-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (55 loc) · 1.34 KB
/
main.cpp
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
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include <iostream>
class Game : public olc::PixelGameEngine
{
public:
Game()
{
sAppName = "Test with olcPixelGameEngine";
}
olc::vd2d position;
olc::vd2d velocity = { 0, 0};
olc::vd2d size = { 30, 30 };
float speed = 30;
public:
bool OnUserCreate() override
{
std::cout << "Start!";
olc::vd2d screenSize = {ScreenWidth(), ScreenHeight()};
position = (screenSize / 2) - size / 2;
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
olc::vf2d mousePos = { float(GetMouseX()), float(GetMouseY())};
velocity.x = 0;
velocity.y = 0;
if(GetKey(olc::Key::S).bHeld) {
velocity.y += 1;
}
if(GetKey(olc::Key::W).bHeld) {
velocity.y -= 1;
}
if(GetKey(olc::Key::D).bHeld) {
velocity.x += 1;
}
if(GetKey(olc::Key::A).bHeld) {
velocity.x -= 1;
}
Clear(olc::BLACK);
DrawCircle(mousePos, 3, olc::YELLOW);
// Update position
position += velocity * fElapsedTime * speed;
// Draw character
DrawRect(position, size, olc::GREEN);
return true;
}
};
int main()
{
Game demo;
if (demo.Construct(320, 180, 4, 4))
demo.Start();
return 0;
}