-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
392 lines (330 loc) · 25.2 KB
/
Main.cpp
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
//Using SDL, SDL_image, standard IO, and strings
#include "SDL2/SDL.h"
#include "SDL2/SDL_image.h"
#include "SDL2/SDL_mixer.h"
#include <stdio.h>
#include <string>
#include "Player.h"
#include "Constants.h"
#include "Prof.h"
#include <iostream>
//#include "Locations.cpp"
//Starts up SDL and creates window
bool init();
//Loads media
bool loadMedia();
//Frees media and shuts down SDL
void close();
//The window we'll be rendering to
SDL_Window* gWindow = NULL;
//The window renderer
SDL_Renderer* gRenderer = NULL;
//Scene textures
WTexture gPlayer1Texture;
WTexture gPlayer2Texture;
WTexture gBackgroundTexture;
WTexture gRoadTexture;
WTexture gProfTexture;
WTexture gBuildingTexture;
WTexture gGrassTexture;
WTexture gFoodTexture;
WTexture gWinTexture;
WTexture gLoseTexture;
Mix_Music *gMusic = NULL;
bool visit1 = false;
bool visit2 = false;
bool visit3 = false;
bool visit4 = false;
bool visit5 = false;
bool visit6 = false;
bool visit7 = false;
int map[70][100] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}
;
bool init(){
//Initialization flag
bool success = true;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 ){
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ){
printf( "Warning: Linear texture filtering not enabled!" );
}
//Create window
gWindow = SDL_CreateWindow( "GAME", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL ){
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else{
//Create vsynced renderer for window
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
if( gRenderer == NULL ){
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else{
//Initialize renderer color
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ) )
{
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
success = false;
}
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
}
}
}
return success;
}
bool loadMedia(){
//Loading success flag
bool success = true;
gMusic = Mix_LoadMUS("Resources/song.mp3");
if( !gPlayer1Texture.loadFromFile(gRenderer, "Resources/minion.png" ) ){
printf( "Failed to load dot texture!\n" );
success = false;
}
if( !gPlayer2Texture.loadFromFile(gRenderer, "Resources/minion2.png" ) ){
printf( "Failed to load dot texture!\n" );
success = false;
}
if( !gBackgroundTexture.loadFromFile(gRenderer, "Resources/backg.png" ) ){
printf( "Failed to load background texture image!\n" );
success = false;
}
if( !gRoadTexture.loadFromFile(gRenderer, "Resources/smallroad.png" ) ){
printf( "Failed to load tile texture image!\n" );
success = false;
}
if( !gBuildingTexture.loadFromFile(gRenderer, "Resources/build.png" ) ){
printf( "Failed to load tile texture image!\n" );
success = false;
}
if( !gGrassTexture.loadFromFile(gRenderer, "Resources/smallgrass.png" ) ){
printf( "Failed to load tile texture image!\n" );
success = false;
}
if(!gProfTexture.loadFromFile(gRenderer, "Resources/professor.png")){
printf("Failed to load Prof texture image!\n");
success = false;
}if(!gFoodTexture.loadFromFile(gRenderer, "Resources/salad.png")){
printf("Failed to load Prof texture image!\n");
success = false;
}if(!gWinTexture.loadFromFile(gRenderer, "Resources/win.png")){
printf("Failed to load Prof texture image!\n");
success = false;
}if(!gLoseTexture.loadFromFile(gRenderer, "Resources/lose.png")){
printf("Failed to load Prof texture image!\n");
success = false;
}
if(gMusic == NULL){
printf("Failed to load music!\n");
success = false;
}
return success;
}
void close(){
//Free loaded images
gPlayer1Texture.free();
gPlayer2Texture.free();
gBackgroundTexture.free();
gRoadTexture.free();
gBuildingTexture.free();
gGrassTexture.free();
gProfTexture.free();
Mix_FreeMusic(gMusic);
//Destroy window
SDL_DestroyRenderer( gRenderer );
SDL_DestroyWindow( gWindow );
gWindow = NULL;
gRenderer = NULL;
//Quit SDL subsystems
Mix_Quit();
IMG_Quit();
SDL_Quit();
}
int main( int argc, char* args[] ){
//Start up SDL and create window
if( !init() ){
printf( "Failed to initialize!\n" );
}
else{
//Load media
if( !loadMedia() ){
printf( "Failed to load media!\n" );
}
else{
//Main loop flag
bool quit = false;
Uint32 startTime = SDL_GetTicks();
//Event handler
SDL_Event e;
//The dot that will be moving around on the screen
Player player1(72, 300);
Player player2(1032, 360);
Prof Prof1(12,600);
Prof Prof2(1152, 432);
Prof Prof3(660, 648);
Prof Prof4(712, 180);
Prof Prof5(348, 250);
//While application is running
while( !quit ){
//Handle events on queue
while( SDL_PollEvent( &e ) != 0 ){
//User requests quit
if( e.type == SDL_QUIT ){
quit = true;
}
//Handle input for the dot
player1.handleEvent( e );
player2.handleEvent( e );
}
//Mix_PlayMusic(gMusic, -1);
player1.mMentalHealth -= SDL_GetTicks();
player2.mMentalHealth -= SDL_GetTicks();
//Move the dot
player1.movePlayer(map);
player2.movePlayer(map);
Prof1.moveProf(player1 , player2, map);
Prof2.moveProf(player1 , player2, map);
Prof3.moveProf(player1 , player2, map);
Prof4.moveProf(player1 , player2, map);
Prof5.moveProf(player1 , player2, map);
Prof1.collided(player1);
Prof1.collided(player2);
Prof2.collided(player1);
Prof2.collided(player2);
Prof3.collided(player1);
Prof3.collided(player2);
Prof4.collided(player1);
Prof4.collided(player2);
Prof5.collided(player1);
Prof5.collided(player2);
startTime = SDL_GetTicks();
if(Prof1.collided(player1) || Prof2.collided(player1) || Prof3.collided(player1) || Prof4.collided(player1) || Prof5.collided(player1)){
player1.transport();
}
if(Prof1.collided(player2) || Prof2.collided(player2) || Prof3.collided(player2) || Prof4.collided(player2) || Prof5.collided(player2)){
player2.transport();
}
if(player1.reachedDestination(720,420) && visit1 == false){
visit1 = true;
player1.mScore += 10;
}if(player2.reachedDestination(720,420) && visit1 == false){
visit1 = true;
player2.mScore += 10;
}
if(player1.reachedDestination(408,516) && visit2 == false){
visit2 = true;
player1.mScore += 10;
}if(player2.reachedDestination(408,516) && visit2 == false){
visit2 = true;
player2.mScore += 10;
}
if(player1.reachedDestination(252,420) && visit3 == false){
visit3 = true;
player1.mScore += 10;
}if(player2.reachedDestination(252,420) && visit3 == false){
visit3 = true;
player2.mScore += 10;
}if(player1.reachedDestination(84,660) && visit4 == false){
visit4 = true;
player1.mScore += 10;
}if(player2.reachedDestination(84,660) && visit4 == false){
visit4 = true;
player2.mScore += 10;
}if(player1.reachedDestination(540,552) && visit5 == false){
visit5 = true;
player1.mScore += 10;
}if(player2.reachedDestination(540,552) && visit5 == false){
visit5 = true;
player2.mScore += 10;
}if(player1.reachedDestination(396,648) && visit6 == false){
visit6 = true;
player1.mScore += 10;
}if(player2.reachedDestination(396,648) && visit6 == false){
visit6 = true;
player2.mScore += 10;
}if(player1.reachedDestination(348,312) && visit7 == false){
visit7 = true;
player1.mScore += 10;
}if(player2.reachedDestination(348,312) && visit7 == false){
visit7 = true;
player2.mScore += 10;
}
//Clear screen
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
SDL_RenderClear( gRenderer );
//Render objects
for (int i = 0 ; i < 70 ; i++){
for (int j = 0 ; j < 100 ; j ++){
if (map[i][j] == 0){
gBackgroundTexture.render(gRenderer, TILE_SIZE*j,TILE_SIZE*i, TILE_SIZE,TILE_SIZE);
}else if(map[i][j] == 1){
gRoadTexture.render(gRenderer, TILE_SIZE*j,TILE_SIZE*i, TILE_SIZE, TILE_SIZE);
}else if(map[i][j] == 2){
gGrassTexture.render(gRenderer, TILE_SIZE*j,TILE_SIZE*i, TILE_SIZE, TILE_SIZE);
}else if(map[i][j] == 3){
gBuildingTexture.render(gRenderer, TILE_SIZE*j,TILE_SIZE*i, TILE_SIZE, TILE_SIZE);
}
}
}
if(visit1 == false){
gFoodTexture.render(gRenderer, 720,420, TILE_SIZE, TILE_SIZE);
}
if(visit2 == false){
gFoodTexture.render(gRenderer, 408,516, TILE_SIZE, TILE_SIZE);
}
if(visit3 == false){
gFoodTexture.render(gRenderer, 252,420, TILE_SIZE, TILE_SIZE);
}
if(visit4 == false){
gFoodTexture.render(gRenderer, 84,660, TILE_SIZE, TILE_SIZE);
}
if(visit5 == false){
gFoodTexture.render(gRenderer, 540,552, TILE_SIZE, TILE_SIZE);
}
if(visit6 == false){
gFoodTexture.render(gRenderer, 396,648, TILE_SIZE, TILE_SIZE);
}
if(visit7 == false){
gFoodTexture.render(gRenderer, 348,312, TILE_SIZE, TILE_SIZE);
}
player1.renderPlayer(gRenderer, gPlayer1Texture);
player2.renderPlayer(gRenderer, gPlayer2Texture);
Prof1.renderProf(gRenderer, gProfTexture);
Prof2.renderProf(gRenderer, gProfTexture);
Prof3.renderProf(gRenderer, gProfTexture);
Prof4.renderProf(gRenderer, gProfTexture);
Prof5.renderProf(gRenderer, gProfTexture);
if(player1.mMentalHealth > 1800000){
SDL_RenderClear( gRenderer );
gLoseTexture.render(gRenderer, 0,0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
if(player1.mScore + player2.mScore == 70){
SDL_RenderClear( gRenderer );
gWinTexture.render(gRenderer, 0,0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
//Update screen
SDL_RenderPresent( gRenderer );
//std::cout<<SDL_GetTicks()<<std::endl;
std::cout<<player1.mMentalHealth<<std::endl;
}
}
}
//Free resources and close SDL
close();
return 0;
}