-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (58 loc) · 1.92 KB
/
Copy pathmain.cpp
File metadata and controls
74 lines (58 loc) · 1.92 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
//
// Created by gpelletier on 2022-02.
//
#include <SFML/Graphics.hpp>
#include "GameWorld.h"
using namespace sf;
using namespace std;
int main() {
Texture bgTexture;
Sprite bgSprite;
Clock clock;
Time elapsed;
RenderWindow window(VideoMode(800, 600), "RogueLike");
GameWorld gameWorld = GameWorld(Vector2i(16, 12), 3, 20);
if (!bgTexture.loadFromFile("images/Grass_Sample.png")) {
return EXIT_FAILURE;
}
bgTexture.setRepeated(true);
bgSprite.setTexture(bgTexture);
bgSprite.setTextureRect(IntRect(0, 0, 800, 600));
window.setKeyRepeatEnabled(false); // stops button spamming
while (window.isOpen()) {
Event event{};
while (window.pollEvent(event)) {
if (event.type == Event::Closed) {
window.close();
} else if (event.type == Event::KeyPressed) {
if (Keyboard::isKeyPressed(Keyboard::Up)) {
gameWorld.MovePlayer(Vector2i(0, -1));
}
if (Keyboard::isKeyPressed(Keyboard::Down)) {
gameWorld.MovePlayer(Vector2i(0, 1));
}
if (Keyboard::isKeyPressed(Keyboard::Left)) {
gameWorld.MovePlayer(Vector2i(-1, 0));
}
if (Keyboard::isKeyPressed(Keyboard::Right)) {
gameWorld.MovePlayer(Vector2i(1, 0));
}
}
}
window.clear();
window.draw(bgSprite);
elapsed = clock.getElapsedTime();
if (elapsed.asSeconds() >= 0.5) {
clock.restart();
gameWorld.MoveEnemies();
}
for (auto &mapTiles: gameWorld.m_tiles) {
for (auto &mapTile: mapTiles) {
if (mapTile->m_sprite != nullptr) // don't draw null sprites
window.draw(*mapTile->m_sprite);
}
}
window.display();
}
return 0;
}