-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
139 lines (121 loc) · 3.79 KB
/
main.cpp
File metadata and controls
139 lines (121 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "kjpsGL.hpp"
#include <algorithm>
using namespace std;
using namespace kjpsgl;
float gravity;
float x,y;
float speedX;
float speedY;
int score;
bool gameOver;
const int boxCount = 100;
float box[boxCount][2];
void reset()
{
gravity = 3000;
score = 0;
gameOver = false;
speedX = 5000;
speedY = 10;
x=-1000; y=500;
for (int i=0; i<boxCount; ++i){
float w = randomInRange(200,400);
box[i][0]= randomInRange(0,max(0.0f,720-w));
box[i][1]= box[i][0] + w;
}
}
int main()
{
init(1024,720,false,0);
setVsync(true);
int kaspars = loadTexture("data/kaspars.png");
int gameOverTex = loadTexture("data/go.png");
int wallTex = loadTexture("data/codewall.png");
int bckg = loadTexture("data/code_bckg.png");
int textTex = loadTexture("data/numbers.png");
reset();
// galvenais cikls
while (!getKey("Escape")) // kamēr nav nospiesta escape poga
{
update();
setTexture(bckg);
setTexturingMode(TexturingMode::Manual);
setColor(255,255,255,200);
setTexturingRect(-x*.621f,0,getTextureWidth(bckg)-x*.621f,getTextureHeight(bckg));
drawRectangle(0,0,1024,720);
setColor(255,255,255,64);
setTexturingRect(-x*.821f,0,getTextureWidth(bckg)-x*.821f,getTextureHeight(bckg));
drawRectangle(0,0,1024,720);
setColor(255,255,255,255);
setTexturingMode(TexturingMode::Stretch);
setTexture(-1);
if (getKey("r")) reset();
const float deltaT = getDeltaTime();
speedX = 250 + score*10;
speedY -= gravity*deltaT;
y += speedY*deltaT;
x += speedX*deltaT;
if (!gameOver){
if (y<0) y=0, speedY=10;
else if (y>700) y=700, speedY=-1;
if (getAnyKey()) speedY=800;
}
int p= int(x/500)+1;
if (p<1) p = 1;
else if (!gameOver) score = p;
setTexture(wallTex);
setTexturingMode(TexturingMode::Manual);
for (int i=p-1; i<p+3; ++i){
int cx = -x + i*500;
if (cx<128+32 && cx>-48){
if (y<box[i][0] || y+64>box[i][1]) gameOver = true;
}
setTexturingRect(cx,0,cx+128,128);
drawRectangle(cx,0,cx+128,box[i][0]);
drawRectangle(cx,box[i][1],cx+128,720);
}
setTexture(-1);
setLineWidth(3);
setColor(155,155,155);
for (int i=p-1; i<p+3; ++i){
int cx = -x + i*500;
drawRectangleOutline(cx,0,cx+128,box[i][0]);
drawRectangleOutline(cx,box[i][1],cx+128,720);
}
setColor(255,255,255);
if (gameOver) setColor(255,0,0);
else {
setColor(255,255,0,64);
drawCircle(64+32,y+32,48);
setColor(255,255,255);
}
setTexture(kaspars);
setTexturingMode(TexturingMode::Stretch);
drawRectangle(64-4,y-4,64+64+8,y+64+8);
setTexture(-1);
setColor(255,255,255);
if (gameOver){
if (speedX>0) speedX-=deltaT;
float w = getTextureWidth(gameOverTex);
float h = getTextureHeight(gameOverTex);
float x = 1024*.5 - w*.5;
float y= 720*.5 - h*.5;
setTexture(gameOverTex);
drawRectangle(x,y,x+w,y+h);
}
setTexture(-1);
{
setTexture(textTex);
setTexturingMode(TexturingMode::Manual);
string s = toString(score);
for (int i=0; i<s.size(); ++i){
float x = i*64+32;
float y=16;
setTexturingRect(x-(90*(s[i]-'0')),y,x+90*10-(90*(s[i]-'0')),y+64);
drawRectangle(x,y,x+90,y+64);
}
}
display();
setWindowTitle("Score: "+toString(score));
}
}