-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.cpp
More file actions
42 lines (38 loc) · 897 Bytes
/
demo.cpp
File metadata and controls
42 lines (38 loc) · 897 Bytes
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
#include <GEngine.hpp>
#include <math.h>
class Engine: public GEngine
{
public:
bool onStart()
{
speed = 720.0f;
player = Vector2d(400, 300);
size = Vector2d(40, 30);
dir = Vector2d((rand() % 2) ? 1 : -1, (rand() % 2) ? 1 : -1);
return true;
}
bool onUpdate(float dt)
{
player = player + dir * (dt * speed);
Color color = Color(player.x / 800.0f * 255.0f, player.y / 600.0f * 255.0f, 0);
if(player.x < size.x / 2 || player.x > 700 - size.x / 2) dir.x = -dir.x;
if(player.y < size.y / 2 || player.y > 500 - size.y / 2) dir.y = -dir.y;
drawRect(player.x, player.y, size.x, size.y, color);
return true;
}
bool onDestroy()
{
return true;
}
private:
float speed;
Vector2d player, dir, size;
};
int main()
{
srand(time(NULL));
Engine demo;
if(demo.init(700, 500))
demo.run();
return 0;
}