Repository navigation
Expand file tree
/
Copy pathGame.h
More file actions
185 lines (160 loc) · 5.34 KB
/
Copy pathGame.h
File metadata and controls
185 lines (160 loc) · 5.34 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef __Block_Frog__Game__
#define __Block_Frog__Game__
#include <iostream>
#include <SFML/Graphics.hpp>
#include "UDPNetwork.h"
#include <Box2D/Box2D.h>
#include "Player.h"
#include <list>
#include <thread>
class Utility;
class Shape;
class ShapeFactory;
class Controller;
class OSHandler;
class UDPNetwork;
class Textor;
class ContactListener;
class Remover;
class Synchronizer;
class Lobby;
class Director;
//enum {SERVER, CLIENT, SINGLE_PLAYER};
class Game
{
public:
Game(sf::RenderWindow* window, OSHandler* osHandler);
~Game();
void destroyPlayer();
void basicInit();
void init();
void initStartMenu();
void runStartMenu();
void run();
void removeStartMenu();
void exitGame();
void spawnBox(sf::Vector2i position);
// Getter methods
Textor* getTextor() {return textor;};
sf::RenderWindow* getWindow() { return window; }
b2World* getWorld() { return world; }
Player* getPlayer() { return player; }
Utility* getUtility() { return utility; }
OSHandler* getOSHandler() { return osHandler; }
ShapeFactory* getShapeFactory() { return shapeFactory; }
Synchronizer* getSynchronizer() { return synchronizer; }
/*
get any one player, remote or local
returns nullptr if not found
*/
Player* getPlayer(int localID);
sf::Vector2i& getViewOffset() {return viewOffset;};
list<Player*>& getRemotePlayers() {return remotePlayers;};
//returns nullptr if not found
Player* getRemotePlayer(int localID);
vector<Shape*>& getShapes() {return boxes;};
//returns nullptr if not found
Shape* getShape(int id);
Shape* getLastStaticShape() const {return lastStaticShape;};
sf::Shape* getWater() const {return water;};
ContactListener* getContactListener() { return contactListener; }
Lobby* getLobby() { return lobby; }
Director* getDirector() { return director; }
bool getGameHasStarted() { return gameHasStarted; }
int getLocalID() { return localID; }
// Setter methods
void setUtility(Utility* utility);
void setPlayer(Player* player);
void setStaticPlatform(Shape* shape) { lastStaticShape = shape; }
void setElapsedPrepTime(int elapsedPrepTime_) { elapsedPrepTime = elapsedPrepTime_; }
void setGameHasStarted(bool hasStarted) { gameHasStarted = hasStarted; }
void setLobby(Lobby* lobby_) { lobby = lobby_; }
void setDirector(Director* director_) { director = director_; }
// Unique ID for every machine connected to game.
void setLocalID(int localID_) { localID = localID_; }
// Network
void addRemotePlayer(Player* rPlayer);
bool removeRemotePlayer(int localID);
bool playersAllowedToJoined(){return allowJoin;};
UDPNetwork* getLocalHost(){return localHost;};
void setLocalHost(UDPNetwork* localHost_) { localHost = localHost_; }
PacketParser* getPacketParser() const {return packetParser;};
//synchronize shapes against servers game state
void updateShapes(shapeSync* s);
void updatePlayer(player_info* p);
void removeShape(int id);
bool exitCalled;
void startRise();
private:
void removeFallenBoxes(std::list<Shape*>& todelete);
void calcViewOffset();
void boxHandling(); //destroy boxes.
Shape* createBoxes(); //for server only. Returns pointer to last created box, nullptr if no box was created
void createStaticPlatform();
void handleThreads();
void playerHandling();
//if local player interacts with boxes save changes to localChanges
void playerBoxInteraction();
b2World* world;
Player* player; // This is the player that the player controlls
Utility* utility; // Access this object for certain utility functions
list<Player*> remotePlayers;
OSHandler* osHandler;
ShapeFactory* shapeFactory;
ContactListener* contactListener;
Lobby* lobby;
Director* director;
sf::RenderWindow* window;
sf::View* view;
sf::Vector2i viewOffset;
sf::Clock clock;
sf::Time timer;
PacketParser* packetParser;
Textor* textor;
Remover* remover;
// temporary
Shape* staticPlatform;
// This is for the live menu
Shape* hostRectangle;
Shape* joinRectangle;
// Keep track of amount of players. This will affect the userData set for each player
int playerAmount;
// This score is incremented when new boxes are created in createBoxes()
int score;
bool gameHasStarted;
//network
int localID;
UDPNetwork* localHost;
std::thread* network;
std::vector<shapeSync*> localChanges;
std::clock_t start;
Synchronizer* synchronizer;
std::vector<Shape*> boxes;
std::vector<Shape*> staticShapes;
Shape* lastStaticShape;
// Water
sf::Shape* water;
// int values, 1 is start, for each new stage a new static platform is created
int waterStage;
int prevStage;
float platformsPerLevel;
int arrangeX;
int prevArrangeX;
sf::Vector2i oldViewOffset;
// Holds timer.asSeconds() value. Used to create new boxes in intervals
double duration;
// Holds timer.asSeconds() value. Used to count time in preparation before game starts
int prepTime;
int elapsedPrepTime;
int boxCount;
// int gameLevel;
bool rise;
float riseSpeed;
int secPerDrops; //time before a new block is dropped
bool allowJoin;
//float updateTime;
// int staticPlatform; //every staticPlatform:th created box will be a static platform
friend Controller;
friend UDPNetwork;
};
#endif /* defined(__Block_Frog__Game__) */