-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClasses.h
executable file
·330 lines (312 loc) · 6.87 KB
/
Classes.h
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#include <cstdlib>
#include<string>
#include<SDL.h>
#include<SDL_image.h>
#include<cmath>
#include<iostream>
#include<SDL_ttf.h>
#include<sstream>
#include<vector>
#include<thread>
#include<mutex>
#include<deque>
#include<condition_variable>
using namespace std;
class Weapon;
class MySDL;
class Control;
class Worm;
class Timer;
struct coord{
int x;
int y;
};
struct explod{
bool exp;
int rad;
int power;
int counter=0;
int pressure;
int divide;
};
struct bullet{
int x;
int y;
int w;
int h;
float vx;
float vy;
double angle;
SDL_Texture* bulltex=NULL;
SDL_RendererFlip flip;
bool flying;
};
class Texture{
private:
int** map;
int sizex;
int sizey;
public:
Texture(const char* itxt,int isizex,int isizey);
~Texture();
void writeWorm(Worm* w);
void eraseWorm(Worm* w);
int valueat(int x,int y);
void writePoint(int x, int y, int value);
};
class Timer{
private:
int starttime=0;
int pausedtime;
bool timepaused=false;
SDL_Rect dest;
public:
Timer();
SDL_Rect getRect();
int getTime();
void pause();
void unpause();
bool paused();
void reset();
};
class Weapon{
protected:
double lx;
double ly;
int windCounter=0;
int windProof;
public:
SDL_Texture* explode=NULL;
SDL_Texture* weaptex=NULL;
SDL_Texture* weapChargesTex=NULL;
SDL_Rect destexp;
SDL_Rect destweap;
bullet projectile;
explod exploded;
int maxspeed;
int charges;
int lastCharges=0;
coord v0;
SDL_RendererFlip flip=SDL_FLIP_NONE;
double angle=0;
virtual coord getStrikeCoord()=0;
virtual void Shoot(Texture* tex, int wind)=0;
virtual void strike(int x,int y)=0;
virtual ~Weapon(){}
};
class Rocket: public Weapon{
protected:
bool firstShoot=true;
public:
Rocket();
~Rocket();
coord getStrikeCoord();
void Shoot(Texture* tex, int wind);
void strike(int x,int y);
};
class Granade:public Weapon{
protected:
bool firstShoot=true;
Timer timer;
public:
Granade();
~Granade();
coord getStrikeCoord();
void Shoot(Texture* tex, int wind);
void strike(int x,int y);
};
class Dynamite:public Weapon{
protected:
bool firstShoot=true;
Timer timer;
public:
Dynamite();
~Dynamite();
coord getStrikeCoord();
void Shoot(Texture* tex, int wind);
void strike(int x,int y);
};
class BSBat:public Weapon{
public:
BSBat();
~BSBat();
coord getStrikeCoord();
void Shoot(Texture* tex, int wind);
void strike(int x,int y);
};
class Shotgun:public Weapon{
protected:
bool firstShoot=true;
public:
Shotgun();
~Shotgun();
coord getStrikeCoord();
void Shoot(Texture* tex, int wind);
void strike(int x,int y);
};
class Worm{
public:
SDL_Rect dest;
int team;
int dir;//0 left 1 right
int lasthealth;
int health;
bool firing=false;
bool jumping=false;
bool firstjump=true;
int startJumping;
bool playing=false;
bool firstRound=false;
bool flying=false;
int fallspeed=0;
int firstFly=1;
coord flyspeed;
vector<Weapon*> weapons;
static int wormCounter;
int id;
SDL_Texture* tex=NULL;
SDL_Texture* texttex=NULL;
Weapon* weap=NULL;
Worm(int iteam, int teamsize);
~Worm();
void moveWorm(int ix,int iy);
void nextWeapon();
void changeWeapon(int i);
};
class MySDL{
private:
SDL_Texture* backtex=NULL;
SDL_Texture* texarrow=NULL;
SDL_Texture* textime=NULL;
SDL_Window* window=NULL;
TTF_Font* font=NULL;
Control* c;
Texture* tex;
int counter=0;
SDL_Rect srcdest;
void resizeTextDest(SDL_Rect* dest, string text,int letterW,int letterH);
void DrawTime();
void drawAnnoucement(string text, SDL_Color color);
void DrawBack();
void DrawWind();
void DrawWorm(Worm * w);
void DrawProjectile(bullet proj );
void DrawWeapons();
void DrawLine(int x,int y,int wx, int wy);
void DrawPic(SDL_Rect destpic, SDL_Texture* tex,double angle=0,
SDL_RendererFlip flip=SDL_FLIP_NONE,SDL_Rect* srcdest=NULL);
SDL_Texture* RenderText(string text, SDL_Color textcolor);
void createBackTexture();
void setCamera();
void centerCameraAround(int x);
public:
void DrawLoadingScreen();
static int GAME_WINDOW_WIDTH;
static int GAME_WINDOW_HEIGHT;
static int GAME_MAP_WIDTH;
MySDL();
void setControl(Control* ic);
void setTextureRef(Texture* itex);
static SDL_Renderer* rend;//game window renderer
void Init();
void CreateWinRen(const char* name);
void drawGame();
void DestroyWin();
SDL_Rect* getSrcdestRef();
};
class queue{
private:
std::mutex mu;
std::deque<char> q;
std::condition_variable cond;
public:
void eraseAll();
bool empty();
void pushFront(char a);
char takeFromBack();
void notifyAll();
};
class Input{
private:
std::mutex mu;
const Uint8* state;
queue q;
bool goRight=false;
bool goLeft=false;
bool firing=false;
coord mouse;
void eraseEvents();
public:
char takeFromQueue();
bool queueEmpty();
bool moveRight();
bool moveLeft();
bool wormFiring();
coord getMouse();
void getEvents();
};
class Control{
private:
static mutex mu;
static int speed;
static int up;
static int down;
static int checkh;
static int jumpx;
static int jumpy;
static bool shotFlying;
static bool wormFlying;
static bool gamePaused;
bool goToNextRound=false;
bool goLeft=false;
bool goRight=false;
int lastworm1;
int lastworm2;
int lastteamplayed;
int counterChangeWeap=0;
int pauseCounter=0;
SDL_Rect* srcdest;
void wormFall(Worm* w);
void Gravity();
int handleTeamFlying(vector<Worm*> team);
void handleWormsFlying();
void handleExplosion();
void eraseDeadWorms();
void nextRound();
void GoLeft();
void GoRight();
void Jump(Worm* w);
void eraseWormWeap(Worm* w);
void removeWormsEmptyWeapons();
coord FireSpeed(int x, int y);
void WormShoot(coord v0);
bool CanFly(int first, SDL_Rect dest, int dir);
void setWormFlySpeed(Worm* w);
void handleWormsJumping();
int fallDamage(double vx, double vy);
int explosionDamage(double power,double rad,double distance);
Input* input;
public:
coord mouse;
int wind=0;
static bool exitGame;
static bool delay;
static bool explosion;
bool backChanged=true;
vector<Worm*> team1;
vector<Worm*> team2;
Texture* rectex;
Worm* recworm;
Timer timer;
static bool animating();
static bool pausedGame();
double distance(coord a,coord b);
void createTeams(int teamSize);
void clearTeams();
Control(Texture* tex);
coord getMouseCoord();
void handleEvents();
void logic();
void setSrcdestRef(SDL_Rect* dest);
void setInputRef(Input* i);
};