-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
75 lines (63 loc) · 1.66 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
72
73
74
75
#include "SFML/Graphics.hpp"
#include "src/cat.h"
#include "src/beam.h"
#include "src/drawable.h"
#include <array>
#include <memory>
using namespace std;
constexpr unsigned int WINDOW_HEIGHT = 800;
constexpr unsigned int WINDOW_WIGTH = 800;
void onMouseMove(sf::Event::MouseMoveEvent &event, sf::Vector2f &mousePos)
{
mousePos = {static_cast<float>(event.x), static_cast<float>(event.y)};
}
void pollMouseEvent(sf::RenderWindow &window, sf::Vector2f &mousePos)
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::EventType::Closed:
window.close();
break;
case sf::Event::EventType::MouseMoved:
onMouseMove(event.mouseMove, mousePos);
break;
default:
break;
}
}
}
void renderWindow(sf::RenderWindow &window, const auto &objs)
{
window.clear(sf::Color::White);
for (auto &obj : objs)
{
window.draw(obj->getSprite());
}
window.display();
}
int main(int, char **)
{
array<unique_ptr<MyDrawable>, 2> drawObjs;
// Init cat
drawObjs[0] = make_unique<Beam>("assets/red_pointer.png");
// Init red beam
drawObjs[1] = make_unique<Cat>("assets/cat.png");
// Init window
sf::RenderWindow window({WINDOW_HEIGHT, WINDOW_WIGTH},
"Cat following beam");
window.setFramerateLimit(60);
sf::Vector2f mousePos = {0, 0};
while (window.isOpen())
{
pollMouseEvent(window, mousePos);
for (auto &obj : drawObjs)
{
obj->move(mousePos);
}
renderWindow(window, drawObjs);
}
return 0;
}