-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cpp
711 lines (687 loc) · 19.2 KB
/
Game.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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
#include "pch.h"
#include "Game.h"
#include "ConsoleCtrl.h"
Game::Game()
{
RetrieveScore("topScore.txt");
ObjModel[0] = new CAR;
ObjModel[1] = new STICK;
ObjModel[2] = new TRAIN;
ObjModel[3] = new LAMP;
ObjModel[4] = new EAGLE;
ObjModel[5] = new COIN;
ObjModel[6] = new ANIMAL;
}
Game::~Game()
{
for (int i = objects.size() - 1; i >= 0; i--)
{
delete objects[i];
}
for (int i = 0; i < rows; i++)
delete[] map[i];
delete[] map;
for (int i = 0; i < 7; ++i) delete ObjModel[i];
for (int i = 0; i < 7; ++i) FreeTileTexture(TileModel[i]);
}
template<class T>
void Game::FreeTileTexture(T obj)
{
size_t s = obj.texture.size();
for (size_t i = 0; i < s; ++i) G_DestroyTexture(obj.texture[i]);
vector<G_Texture*>().swap(obj.texture);
}
void Game::deleteObjects()
{
while (!objects.empty() && objects.front()->tile.y == rows - 1)
{
delete objects[0];
objects.pop_front();
}
}
void Game::destroyTiles() {
for (int i = 0; i < rows; i++)
delete[] map[i];
delete[] map;
}
void Game::drawObjects()
{
for (size_t i = 0; i < objects.size(); i++)
{
objects[i]->self_draw();
}
}
void Game::drawTiles()
{
if (rowcnt == 52)
{
TileModel[0].change_skin(1);
TileModel[1].change_skin(1);
TileModel[2].change_skin(1);
TileModel[5].change_skin(1);
}
for (int i = 0; i < columns; i++)
{
for (int j = 0; j < rows; j++)
{
map[i][j].self_draw();
}
}
}
void Game::initTiles()
{
columns = (int)ceil(windowPos.w / TILE_LENGTH);
rows = (int)ceil(windowPos.h / TILE_LENGTH) + 1;
rowcnt += rows;
map = new TileTexture*[columns];
for (int i = 0; i < columns; i++)
map[i] = new TileTexture[rows];
for (int y = rows - 1; y >= 0; y--)
{
if (y >= rows - 2)
{
for (int x = 0; x < columns; x++)
{
map[x][y] = (x == 0 || x == columns - 1) ? TileModel[1] : TileModel[0];
map[x][y].position.x = x * 100;
map[x][y].position.y = (y - 1) * 100;
}
}
else
{
generateTiles(y);
addObjects(y);
}
}
}
void Game::generateTiles(int row)
{
int rowChance = rand() % 100 + 1;
int Trees = 0;
TileModel[4].change_skin(rand() % 2);
for (int x = 0; x < columns; x++)
{
if (rowcnt % 52 == 0 && score > 0 && map[columns / 2][row - 1].type != GATE)
{
if (x == columns / 2) map[x][row] = TileModel[6];
else map[x][row] = TileModel[1];
Gate++;
}
else
{
if (rowChance <= 50 /*rowType == GRASS*/)
{
int chance = rand() % 100 + 1;
if (x == 0 || x == columns - 1)
map[x][row] = TileModel[1];
else {
if (chance >= 80 && Trees < maxTreesInARow)
{
if (rand() % 3 == 1)
{
map[x][row] = TileModel[2];
}
else map[x][row] = TileModel[1];
Trees++;
}
else
{
map[x][row] = TileModel[0];
}
}
}
else if (rowChance <= 70 /*rowType == ROAD*/)
{
map[x][row] = TileModel[4];
}
else if (rowChance <= 75 /*rowType == RAIL*/)
{
map[x][row] = TileModel[5];
}
else if (rowChance <= 100 /*rowType == WATER*/)
{
map[x][row] = TileModel[3];
}
}
map[x][row].position.x = x * 100;
map[x][row].position.y = map[x][row + 1].position.y - TILE_LENGTH;
}
}
void Game::addObjects(int row)
{
if (map[0][row].type != WATER) addCoins(row);
switch (map[0][row].type)
{
case ROAD:
if (map[0][row].skin == 0) addEnemy<CAR>(ObjModel[0], row);
else addEnemy<ANIMAL>(ObjModel[6], row);
break;
case WATER:
addStick(row);
break;
case RAIL:
addTrain(row);
break;
}
}
template<class O, class T>
void Game::addEnemy(T*obj, int row)
{
Direction dir = (Direction)((rand() % 2) + 2);
obj->dir = dir;
obj->position.y = map[0][row].position.y;
obj->tile.y = row;
obj->moveSpeed = (rand() % 5 + 2) * (dir == RIGHT ? 1 : -1);
int num = (rand() % 3) + 1;
int space = (windowPos.w - ((num - 1) * obj->position.w)) / num;
int randPos = rand() % windowPos.w;
for (int i = 0; i < num; i++)
{
Object* Prefab = new O(obj);
objects.push_back(Prefab);////////////////////////////////////////////////////////
if (dir == LEFT)
objects.back()->position.x = windowPos.w + (i*(space + obj->position.w)) - randPos;
else
objects.back()->position.x = -obj->position.w - (i*(space + obj->position.w)) + randPos;
objects.back()->random_skin();
}
}
void Game::addStick(int row)
{
ObjModel[1]->position.y = map[0][row].position.y;
ObjModel[1]->tile.y = row;
if (map[0][row + 1].type == WATER) { // Direction of two rivers should be diffrent.
for (int i = objects.size() - 1; i >= 0; i--) {
if (objects[i]->tile.y == row + 1 && dynamic_cast<STICK*>(objects[i]) != NULL)
{
ObjModel[1]->dir = (objects[i]->dir == LEFT ? RIGHT : LEFT);
ObjModel[1]->isMoving = (objects[i]->isMoving ? rand() % 2 : true); //We Cant Have Two Stopped Rivers
break;
}
}
}
else
{
ObjModel[1]->isMoving = rand() % 2;
ObjModel[1]->dir = (Direction)((rand() % 2) + 2);
}
if (ObjModel[1]->isMoving)
{
ObjModel[1]->moveSpeed = (rand() % 3 + 1) * (ObjModel[1]->dir == RIGHT ? 1 : -1);
int num = (rand() % 4) + 3;
int space = (windowPos.w - ((num - 1) * ObjModel[1]->position.w)) / num;
int randPos = rand() % 200;
for (int i = 0; i < num; i++)
{
Object *StickDup = new STICK(ObjModel[1]);
objects.push_back(StickDup);///////////////////////////////////////////////////////////
if (ObjModel[1]->dir == LEFT)
objects.back()->position.x = randPos + (i*(space + ObjModel[1]->position.w));
else
objects.back()->position.x = windowPos.w - randPos - (i*(space + ObjModel[1]->position.w));
}
}
else
{
int num = 0;
do {
for (int i = 0; i < columns; i++)
{
if (map[i][row + 1].type != TREE) {
int chance = rand() % 100 + 1;
if (chance >= 50 && num < maxSticksInARow) {
num++;
ObjModel[1]->position.x = map[i][row].position.x;
Object *StickDup = new STICK(ObjModel[1]);
objects.push_back(StickDup);/////////////////////////////////////////
}
}
}
} while (num < minSticksInARow);
}
}
void Game::addTrain(int row)
{
Direction dir = (Direction)((rand() % 2) + 2);
ObjModel[2]->dir = dir;
ObjModel[2]->position.y = map[0][row].position.y;
ObjModel[2]->tile.y = row;
ObjModel[2]->timer = ((rand() % 5) + 2) * FPS;
ObjModel[2]->random_skin();
Object* TrainDup = new TRAIN(ObjModel[2]);
objects.push_back(TrainDup);////////////////////////////////////////
if (dir == LEFT)
objects.back()->position.x = windowPos.w + ObjModel[2]->position.w;
else
objects.back()->position.x = -ObjModel[2]->position.w;
ObjModel[3]->tile.y = row;
ObjModel[3]->position.y = map[0][row].position.y + TILE_LENGTH - ObjModel[3]->position.h;
ObjModel[3]->position.x = map[0][row].position.x + 20;
Object *LampDup = new LAMP(ObjModel[3]);
objects.push_back(LampDup);////////////////////////////////////////////////
}
void Game::addCoins(int row)
{
int num = 0;
ObjModel[5]->position.y = map[0][row].position.y;
ObjModel[5]->position.w = ObjModel[5]->position.h = 100;
ObjModel[5]->tile.y = row;
for (int i = 0; i < columns; i++)
{
if (map[i][row].type != TREE) {
int chance = rand() % 101;
if (chance >= 90 && num < maxCoinsInARow) {
num++;
ObjModel[5]->position.x = map[i][row].position.x;
Object *CoinDup = new COIN(ObjModel[5]);
objects.push_back(CoinDup);//////////////////////////////////////////
}
}
}
}
void Game::checkPlayerStatus()
{
if (state != PLAY) return;
if (Player.position.y + 5 >= windowPos.h)
{
state = OUT;
ObjModel[4]->position.x = Player.position.x - (ObjModel[4]->position.w / 2);
ObjModel[4]->position.y = -ObjModel[4]->position.h;
eagleIntersection = false;
return;
}
if (Player.position.x <= -TILE_LENGTH || Player.position.x >= windowPos.w)
state = GAME_OVER;
bool onStick = false;
G_Rect temp = { Player.position.x + realPlayerClip.x + 5 , Player.position.y + realPlayerClip.y + 5 , realPlayerClip.w - 5,realPlayerClip.h - 5 };
for (size_t i = 0; i < objects.size(); i++) {
if (SDL_HasIntersection(&temp, &objects[i]->position) == SDL_TRUE)
{
if (dynamic_cast<CAR*>(objects[i]) != NULL || dynamic_cast<TRAIN*>(objects[i]) != NULL || dynamic_cast<ANIMAL*>(objects[i]) != NULL)
{
state = GAME_OVER;
Playsound(Player);
}
else if (dynamic_cast<STICK*>(objects[i]) != NULL)
{
onStick = true;
if (!Player.isMoving) {
if (objects[i]->isMoving) Player.position.x += objects[i]->moveSpeed;
if (Player.position.x >= map[Player.tile.x][0].position.x + TILE_LENGTH) Player.tile.x++;
else if (Player.position.x <= map[Player.tile.x][0].position.x - TILE_LENGTH) Player.tile.x--;
if (Player.tile.x >= columns || Player.tile.x < 0) state = GAME_OVER;
}
}
else if (dynamic_cast<COIN*>(objects[i]) != NULL)
{
coins++;
Playsound(ObjModel[5]);
updateScore();
delete objects[i];
objects.erase(objects.begin() + i);
i--;
continue;
}
}
}
if (!Player.isMoving && !onStick && map[Player.tile.x][Player.tile.y].type == WATER)
state = GAME_OVER;
}
void Game::updateScore()// repair
{
if (score > 0 && score % 50 == 0) Player.LevelUp();
if (score > maxScore) maxScore = score;
}
//Suspicious
void Game::eagle()
{
ObjModel[4]->position.y += ObjModel[4]->moveSpeed;
G_Draw(ObjModel[4]->texture[ObjModel[4]->skin], &ObjModel[4]->position);
if (!eagleIntersection && SDL_HasIntersection(&Player.position, &ObjModel[4]->position)) {
Player.position.x = windowPos.w; //Move it to a hidden Area
Playsound(ObjModel[4]);
eagleIntersection = true;
}
if (ObjModel[4]->position.y > windowPos.h)
state = GAME_OVER;
}
void Game::loadTiles()
{
TileModel[0].self_load("assets/image/floor.png", GRASS);
TileModel[0].add_texture("assets/image/floor1.png");
TileModel[2].self_load("assets/image/streetlamp.png", TREE);
TileModel[2].add_texture("assets/image/crystal.png");
TileModel[1].self_load("assets/image/tree.png", TREE);
TileModel[1].add_texture("assets/image/lava.png");
TileModel[3].self_load("assets/image/sea.png", WATER);
TileModel[4].self_load("assets/image/street.png", ROAD);
TileModel[4].add_texture("assets/image/grass.png");
TileModel[5].self_load("assets/image/rail.png", RAIL);
TileModel[5].add_texture("assets/image/rail1.png");
TileModel[6].self_load("assets/image/gate.png", GATE);
cout << "Load tile complete" << endl;
}
void Game::loadObjects()
{
ObjModel[0]->self_load("assets/image/car.png", 0, 0, 169, 100, "assets/sound/car-horn.wav", true);
ObjModel[0]->add_texture("assets/image/car2.png");
ObjModel[0]->add_texture("assets/image/car3.png");
ObjModel[6]->self_load("assets/image/turtle.png", 0, 0, 169, 100, "assets/sound/animal_horn.wav", true);
ObjModel[6]->add_texture("assets/image/sheep.png");
ObjModel[1]->self_load("assets/image/stick1.png", 0, 0, 100, 100, "assets/sound/water.wav", false);
ObjModel[2]->self_load("assets/image/train.png", 0, 0, 544, 100, "assets/sound/train_pass_no_horn.wav", false);
ObjModel[2]->add_texture("assets/image/train2.png");
ObjModel[3]->self_load("assets/image/green-lamp.png", 0, 0, 39, 93, "assets/sound/train_alarm.wav", false);
ObjModel[3]->add_texture("assets/image/red-lamp.png");
ObjModel[4]->self_load("assets/image/eagle.png", 0, 0, 350, 250, "assets/sound/eagle_hit.wav", false);
ObjModel[5]->self_load("assets/image/coin.png", windowPos.w - 100, 20, 100, 100, "assets/sound/coin_tap.wav", false);
cout << "Load object complete" << endl;
}
void Game::loadPlayer()
{
Player.tile = { columns / 2, rows - 2 };
Player.load_player("assets/image/player.png", map[Player.tile.x][Player.tile.y].position, "assets/sound/car_squish.wav");
Player.add_texture("assets/image/player2.png");
Player.add_texture("assets/image/player3.png");
Player.add_texture("assets/image/player_die.png");
cout << "load player complete" << endl;
}
void Game::load()
{
loadTiles();
loadObjects();
initTiles();
loadPlayer();
}
void Game::adjustCameraSpeed()
{
if (state == OUT) {
cameraSpeed = -2;
return;
}
if (state != PLAY) {
cameraSpeed = 0;
return;
}
cameraSpeed = cameraBaseSpeed;
switch (Player.tile.y) {
case 4:
cameraSpeed += 1;
break;
case 3:
cameraSpeed += 3;
break;
case 2:
cameraSpeed += 6;
break;
case 1:
cameraSpeed = playerMoveSpeed;
break;
}
}
void Game::update()
{
adjustCameraSpeed();
for (int y = 0; y < rows; y++)
for (int x = 0; x < columns; x++)
map[x][y].position.y += cameraSpeed;
for (size_t i = 0; i < objects.size(); i++)
{
objects[i]->position.y += cameraSpeed;
if (dynamic_cast<CAR*>(objects[i]) != NULL)
{
objects[i]->self_update(ObjModel[0]->position.w, windowPos.w);
}
if (dynamic_cast<ANIMAL*>(objects[i]) != NULL)
{
objects[i]->self_update(ObjModel[6]->position.w, windowPos.w);
}
if (dynamic_cast<STICK*>(objects[i]) != NULL)
{
objects[i]->self_update(ObjModel[1]->position.w, windowPos.w);
}
if (dynamic_cast<TRAIN*>(objects[i]) != NULL)
{
if (objects[i]->isMoving)
{
if (objects[i]->dir == LEFT && objects[i]->position.x < -ObjModel[2]->position.w)
{
objects[i]->position.x = windowPos.w;
objects[i]->isMoving = false;
objects[i + 1]->change_skin(0); // We Are Sure there is a lamp just after a train!!
objects[i]->timer = ((rand() % 5) + 2) * FPS;
}
else if (objects[i]->dir == RIGHT && objects[i]->position.x > windowPos.w)
{
objects[i]->position.x = -ObjModel[2]->position.w;
objects[i]->isMoving = false;
objects[i + 1]->change_skin(0);
objects[i]->timer = ((rand() % 5) + 2) * FPS;
}
}
else {
if (objects[i]->timer == FPS)
{ //1 Second Before it move we should change the lamp!!
objects[i + 1]->change_skin(1);
Playsound(ObjModel[3]);
}
if (objects[i]->timer == 0)
{
objects[i]->isMoving = true;
Playsound(ObjModel[3]);
}
else
objects[i]->timer--;
}
if (objects[i]->isMoving)
{
objects[i]->position.x += (objects[i]->dir == LEFT ? -trainMoveSpeed : trainMoveSpeed);
}
}
}
if (map[0][rows - 1].position.y > windowPos.h)
{
for (int y = rows - 1; y > 0; y--)
for (int x = 0; x < columns; x++)
map[x][y] = map[x][y - 1];
rowcnt++;
generateTiles(0);
deleteObjects();
for (size_t i = 0; i < objects.size(); i++)
objects[i]->tile.y += 1;
addObjects(0);
Player.tile.y += 1;
}
Player.position.y += cameraSpeed;
checkPlayerStatus();
}
int Game::NewTopScore()
{
if (maxScore > topScore) topScore = maxScore;
return topScore;
}
void Game::Reload()
{
destroyTiles();
size_t s = objects.size();
for (size_t i = 0; i < s; ++i)
{
delete objects[i];
}
objects.clear();
maxScore = score = coins = rowcnt = 0;
updateScore();
for (int i = 0; i < 7; i++) TileModel[i].change_skin(0);
initTiles(); //ReGenerate The Envirement!
Player.tile = { columns / 2 , rows - 2 };
Player.position = map[Player.tile.x][Player.tile.y].position;
Player.ResetLv();
state = START;
}
void Game::draw() /////Console draw
{
drawTiles();
if (state == GAME_OVER)
{
G_Draw(Player.texture[Player.texture.size() - 1], &Player.position); // If player lose,Draw it Under Objects!!
}
drawObjects();
if (state != GAME_OVER)
G_Draw(Player.texture[Player.skin], &Player.position); // But If It is alive , Draw It top of Objects!
ObjModel[5]->position = { windowPos.w - 50,0,50,50 };
ObjModel[5]->self_draw();
}
G_Texture* Game::GetPlayerTexture(int i)
{
return Player.texture[i];
}
void Game::SetPlayerTexture(G_Texture* txture)
{
for (size_t i = 0; i < Player.texture.size(); i++)
{
if (Player.texture[i] == txture)
{
Player.change_skin(i);
break;
}
}
}
void Game::PlayerMove()
{
if (Player.isMoving)
{
switch (Player.dir)
{
case UP:
Player.position.y -= playerMoveSpeed;
if (Player.position.y <= map[Player.tile.x][Player.tile.y - 1].position.y)
{
Player.isMoving = false;
score++;
Player.tile.y--;
Player.position.y = map[Player.tile.x][Player.tile.y].position.y;
//Player.position.x = map[Player.tile.x][Player.tile.y].position.x;
if (map[Player.tile.x][Player.tile.y].type == ROAD)
{
if (map[Player.tile.x][Player.tile.y].skin == 0) Playsound(ObjModel[0]);
else Playsound(ObjModel[6]);
}
else if (map[Player.tile.x][Player.tile.y].type == WATER) Playsound(ObjModel[1]);
}
break;
case RIGHT:
Player.position.x += playerMoveSpeed;
if (Player.position.x >= map[Player.tile.x + 1][Player.tile.y].position.x)
{
Player.isMoving = false;
Player.tile.x++;
Player.position.x = map[Player.tile.x][Player.tile.y].position.x;
}
break;
case LEFT:
Player.position.x -= playerMoveSpeed;
if (Player.position.x <= map[Player.tile.x - 1][Player.tile.y].position.x)
{
Player.isMoving = false;
Player.tile.x--;
Player.position.x = map[Player.tile.x][Player.tile.y].position.x;
}
break;
case DOWN:
Player.position.y += playerMoveSpeed;
if (Player.position.y >= map[Player.tile.x][Player.tile.y + 1].position.y)
{
Player.isMoving = false;
score--;
Player.tile.y++;
Player.position.y = map[Player.tile.x][Player.tile.y].position.y;
}
break;
}
}
}
void Game::CheckObstacle(int i)
{
switch (i)
{
case 0:
if (map[Player.tile.x][Player.tile.y - 1].type != TREE && map[Player.tile.x][Player.tile.y - 1].type != GATE)//normal tile
{
Player.isMoving = true;
Player.dir = UP;
//Player.position.y -= playerMoveSpeed;
}
if (map[Player.tile.x][Player.tile.y - 1].type == GATE)//gate tile
{
if (coins > score / 3)
{
Player.isMoving = true;
Player.dir = UP;
//Player.LevelUp();
}
}
//tree tile
break;
case 1:
if (Player.tile.x + 1 < columns && map[Player.tile.x + 1][Player.tile.y].type != TREE)
{
Player.isMoving = true;
Player.dir = RIGHT;
//Player.position.x += playerMoveSpeed;
}
break;
case 2:
if (Player.tile.x - 1 >= 0 && map[Player.tile.x - 1][Player.tile.y].type != TREE)
{
Player.isMoving = true;
Player.dir = LEFT;
//Player.position.x -= playerMoveSpeed;
}
break;
case 3:
if (Player.tile.y + 1 < rows && map[Player.tile.x][Player.tile.y + 1].type != TREE)
{
Player.isMoving = true;
Player.dir = DOWN;
//Player.position.y += playerMoveSpeed;
}
break;
}
}
bool Game::Player_isMove()
{
return Player.isMoving;
}
bool Game::IsState(enum GameState stat)
{
if (state == stat) return true;
return false;
}
void Game::SaveScoreToFile(string path)
{
ofstream out_file(path);
if (!out_file) cout << "Can not save." << endl;
out_file << topScore;
out_file.close();
}
void Game::RetrieveScore(string path)
{
ifstream in_file(path);
if (!in_file)
{
topScore = 0;
cout << "High score was not initialized.";
}
in_file >> topScore;
in_file.close();
}
template<class T>
void Game::Playsound(T& obj)
{
if (ConsoleCtrl::onSound == true) obj.Playsound();
}
template<class T>
void Game::Playsound(T* obj)
{
if (ConsoleCtrl::onSound == true) obj->Playsound();
}