-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.h
149 lines (132 loc) · 3.67 KB
/
Game.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
#ifndef GAME_H
#define GAME_H
#include "Screen.h"
#include <vector>
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
#include "Tile.h"
#include "Player.h"
#include "MyTexture.h"
#include "TileAtlas.h"
#include "Renderable.h"
#include "Entity.h"
#include "Timer.h"
#include "Text.h"
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <vector>
#include "NPC.h"
typedef std::pair<int, std::string> task;
class LGame : public LScreen
{
private:
const std::vector<std::pair<int, std::string>> allTasks = {
task(13, "Play Volleyball"),
task(14, "PLay Tennis"),
task(15, "Swim"),
task(22, "Buy stationery from the shop"),
task(25, "Attend dance practice in SAC"),
task(26, "PLay Football"),
task(27, "Play Basketball"),
task(28, "Do Athletics"),
task(29, "Play Cricket"),
task(30, "Attend class in LHC"),
task(31, "Take ID Card from security office"),
task(32, "Get documents verified from main building"),
task(33, "Meet professor in biotech building"),
task(34, "Go to the library to study"),
task(38, "Buy vegetables"),
task(39, "Buy bread"),
task(40, "Buy tools"),
task(41, "Get a haircut")};
std::vector<std::pair<int, std::string>> currTasks;
int tasksNum = 5;
// std::string serverIp;
std::string playerName, opponentName;
int &sockfd;
struct sockaddr_in &theirAddr;
char buf[512];
char recBuf[512];
void initSocket();
std::vector<Tile> tiles;
std::vector<Player> players;
std::vector<Entity> entities;
std::vector<NPC> NPCs;
SDL_Rect camera;
// for instructions on object collision
std::string displayText;
std::vector<Renderable *> renderables;
LTexture tilesTexture;
LTexture ashTexture;
LTexture dogTexture;
LTexture profTexture;
LTexture ash2Texture;
LTexture robberTexture ;
LTexture yuluTexture ;
TileAtlas tileAtlas;
int mTilesX;
int mTilesY;
int mTileWidth;
int mTileHeight;
int mMaxPlayerHealth;
bool initObjs();
void initTasks();
bool setTiles();
void initEntities();
void gameEnd();
LTimer globalTime;
Text *nameText;
Text *oppText;
Text *timeText;
Text *healthText;
Text *moneyText;
Text *pointsText;
Text *moneyTextOpp;
Text *pointsTextOpp;
// for instructions on object collision
Text *prompText;
Text *tasksText;
Text *winText;
Text *loseText;
Text *pressAnyKey;
std::vector<Text *> taskTexts;
bool gameEnded = false;
bool waitingEnd = false;
bool result = false;
public:
LGame(LWindow &window, std::string playerName, std::string opponentName, int &sockfd, sockaddr_in &theiraddr);
void handleEvent(SDL_Event &e);
void update();
void render(SDL_Renderer *renderer);
void cleanUp();
SDL_Rect getTileClip(int tileType);
int getLevelWidth();
int getLevelHeight();
int getWindowWidth();
int getWindowHeight();
Animation *sleepingAnimation;
Animation *burgerAnimation;
Animation *icecreamAnimation;
Animation *hotDogAnimation;
Animation *tennisAnimation;
Animation *basketballAnimation;
Animation *footballAnimation;
LTimer getTimer();
Mix_Music *backGroundMusic;
Mix_Chunk *introMusic;
bool hasTask(std::pair<int, std::string> task);
bool hasTask(int task);
void replaceTask(std::pair<int, std::string> task);
void replaceTask(int task);
int getTileType(int x, int y);
};
#endif