Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
** EPITECH PROJECT, 2024 |
3 |
|
|
** zappy |
4 |
|
|
** File description: |
5 |
|
|
** world |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#ifndef WORLD_HPP_ |
9 |
|
|
#define WORLD_HPP_ |
10 |
|
|
|
11 |
|
|
#include <SFML/Graphics.hpp> |
12 |
|
|
#include <SFML/Audio.hpp> |
13 |
|
|
#include <memory> |
14 |
|
|
#include <functional> |
15 |
|
|
#include <vector> |
16 |
|
|
#include <iostream> |
17 |
|
|
|
18 |
|
|
#include "../../../utils/PerlinNoise.hpp" |
19 |
|
|
#include "Chunck.hpp" |
20 |
|
|
#include "Trantorian.hpp" |
21 |
|
|
#include "../IScene.hpp" |
22 |
|
|
#include "shape/diamond.hpp" |
23 |
|
|
|
24 |
|
|
#include "../../sprites/Sprite.hpp" |
25 |
|
|
#include "../../core/Setting.hpp" |
26 |
|
|
#include "../../ui/Chat.hpp" |
27 |
|
|
#include "ui/WorldUi.hpp" |
28 |
|
|
#include "ui/Ranking.hpp" |
29 |
|
|
#include "ui/Bubble.hpp" |
30 |
|
|
#include "ui/LvlUpAnim.hpp" |
31 |
|
|
#include "../Starlings.hpp" |
32 |
|
|
|
33 |
|
|
static const std::vector<std::string> _elements = { |
34 |
|
|
"tree2", "tree4", "stone1", "grass", "grass2" |
35 |
|
|
}; |
36 |
|
|
|
37 |
|
|
static const std::vector<sf::Color> _teamsColor = { |
38 |
|
|
sf::Color::Red, |
39 |
|
|
sf::Color::Green, |
40 |
|
|
sf::Color::Blue, |
41 |
|
|
sf::Color::Yellow, |
42 |
|
|
sf::Color(255, 165, 0), |
43 |
|
|
sf::Color::Magenta, |
44 |
|
|
}; |
45 |
|
|
|
46 |
|
|
class Core; |
47 |
|
|
class World : public IScene { |
48 |
|
|
public: |
49 |
|
|
World(Core *core); |
50 |
|
✗ |
~World() {} |
51 |
|
|
|
52 |
|
|
void init() override; |
53 |
|
|
bool update(sf::Event event, sf::RenderWindow &window) override; |
54 |
|
|
void update(float fElapsedTime) override; |
55 |
|
|
void draw(sf::RenderWindow &window) override; |
56 |
|
|
|
57 |
|
✗ |
int getNbTrantorian() { return _trantorians.size(); } |
58 |
|
✗ |
Trantorian getTrantorian(int id) { return _trantorians[id]; } |
59 |
|
|
|
60 |
|
✗ |
void iterateWorld(std::function<void(int, int)> func){ |
61 |
|
✗ |
for (int i = 0; i < _worldSize.x; i++) { |
62 |
|
✗ |
for (int j = 0; j < _worldSize.y; j++) { |
63 |
|
✗ |
func(i, j); |
64 |
|
|
} |
65 |
|
|
} |
66 |
|
✗ |
} |
67 |
|
|
std::vector<std::string> _teams; |
68 |
|
|
sf::Vector2f _selectedTile = sf::Vector2f(-1, -1); |
69 |
|
|
std::vector<std::vector<Chunck>> _chuncks; |
70 |
|
|
std::vector<Ranking> _rankings; |
71 |
|
|
void lookTrantorian(int index); |
72 |
|
|
private: |
73 |
|
|
void reset(); |
74 |
|
|
void getServerInit(); |
75 |
|
|
void initMap(); |
76 |
|
|
|
77 |
|
|
void layer1(int i, int j); |
78 |
|
|
void layer2(int i, int j); |
79 |
|
|
|
80 |
|
|
std::shared_ptr<Sprite> _sprite; |
81 |
|
|
std::map<std::string, std::shared_ptr<Sprite>> _sprites; |
82 |
|
|
|
83 |
|
|
sf::Vector2f _worldSize; |
84 |
|
|
std::vector<Trantorian> _trantorians; |
85 |
|
|
|
86 |
|
|
sf::View _view; |
87 |
|
|
sf::Vector2f _pos = sf::Vector2f(0, 0); |
88 |
|
|
sf::Vector2f _offset; |
89 |
|
|
sf::Vector2f _tmpOffset = sf::Vector2f(0, 0); |
90 |
|
|
sf::Text _bubbleText; |
91 |
|
|
std::vector<Bubble> _bubbles; |
92 |
|
|
|
93 |
|
|
bool _isDragging = false; |
94 |
|
|
sf::Vector2f _dragStart = sf::Vector2f(0, 0); |
95 |
|
|
float _zoom = 1; |
96 |
|
|
float _zoomSpeed = 0.1; |
97 |
|
|
float _moveSpeed = 10; |
98 |
|
|
|
99 |
|
|
Core *_core; |
100 |
|
|
sf::Vector2f _hoveredTile; |
101 |
|
|
sf::Vector2f _mousePos; |
102 |
|
|
std::shared_ptr<Chat> _chat; |
103 |
|
|
|
104 |
|
|
Diamond _diamond; |
105 |
|
|
WorldUi _worldUi; |
106 |
|
|
float _rankTime = 0; |
107 |
|
|
int _nbIncantations = 0; |
108 |
|
|
std::vector<LvlUpAnim> _lvlUpAnims; |
109 |
|
|
std::vector<Starlings> _starlings; |
110 |
|
|
|
111 |
|
|
std::vector<std::vector<int>> _buildings; |
112 |
|
|
std::map<std::string, sf::Music> _sounds; |
113 |
|
|
sf::FloatRect _viewRect; |
114 |
|
|
bool moveMap(sf::Event event); |
115 |
|
|
void updateTrantorians(); |
116 |
|
|
void updateChuncks(); |
117 |
|
|
void updateIncantation(); |
118 |
|
|
void initSounds(); |
119 |
|
|
bool drawBuilding(sf::RenderWindow &window, int i, int j); |
120 |
|
|
bool drawTrantorian(sf::RenderWindow &window, int i, int j); |
121 |
|
|
void checkWinner(); |
122 |
|
|
}; |
123 |
|
|
|
124 |
|
|
|
125 |
|
|
#endif /* !WORLD_HPP_ */ |
126 |
|
|
|