-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
92 lines (72 loc) · 2.16 KB
/
main.cpp
File metadata and controls
92 lines (72 loc) · 2.16 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
#include <iostream>
#include <SFML/Graphics.hpp>
#include <vector>
#include <nlohmann/json.hpp>
#include <map>
#include <fstream>
#include "Tile.hpp"
#include "TileMap.hpp"
#include "GuiType.hpp"
#include "Variables.hpp"
#include "GIF.hpp"
using json = nlohmann::json;
// Kis segítség a json bekéréséhez
json loadJson(std::string fileName) {
std::ifstream ifstr(fileName);
json loadedJson;
ifstr >> loadedJson;
return loadedJson;
}
// Kis segítség a json elmetéséhez
void saveJson(json &input, std::string fileName) {
std::ofstream o(fileName);
o << std::setw(4) << input << std::endl;
}
int main() {
// Az ablak
sf::RenderWindow window(sf::VideoMode(25 * 32 * 2, 15 * 32 * 2), "Danger World", sf::Style::Close);
window.setFramerateLimit(60);
// A config json
json config = loadJson("config.json");
// A mapok listája
std::vector<TileMap> maps;
// A mapok hozzáadása a listához
for (int i = 0; i < config["levels"]; i++) {
json levelJson = loadJson("levels/" + std::to_string(i + 1) + ".json");
TileMap level(levelJson);
maps.push_back(level);
}
// A játék ciklus
while (window.isOpen()) {
// A bezárás event érzékelése
sf::Event event;
if (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
// Ide kellenek majd a külömböző gui típusok
switch (Variables::gui) {
// Főmenü
case GuiType::FŐMENÜ:
window.clear(sf::Color::White);
break;
// Készítők menü
case GuiType::KÉSZÍTŐK:
window.clear(sf::Color::White);
break;
// Források
case GuiType::FORRÁSOK:
window.clear(sf::Color::White);
break;
// Maga a játék
case GuiType::JÁTÉK:
window.clear(sf::Color::Black);
maps[0].update();
window.draw(maps[0]);
break;
}
window.display();
}
return 0;
}