-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.cpp
99 lines (86 loc) · 2.74 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
#include "game.h"
void Game::init()
{
this->should_exit = false;
this->setCurGameState(GAME_STATE_MENU);
this->setPreviousGameState(0);
this->setBananaType(BANANA_TYPE_1);
this->setIfPlaying(false);
this->setPlayerWon(false);
this->setScoresShouldUpdate(false);
this->setScoresMenuShouldUpdate(false);
this->setBananaShouldChange(false);
for (int i = 0; i < GAME_LEVELS_COUNT; i++)
{
this->setLevelShouldReset(false, i);
this->setCurScore (0, i);
}
SDL_Init(SDL_INIT_EVERYTHING);
TTF_Init();
this->window = SDL_CreateWindow ("Ape Escape", 0, 0, SCREEN_W, SCREEN_H, SDL_WINDOW_FULLSCREEN_DESKTOP);
this->renderer = SDL_CreateRenderer (this->window, -1, 0);
this->audio.init("./sources/jungle.mp3");
this->menu.init(this);
this->levels_menu.init(this);
this->scores.init(this);
this->options.init(this);
this->pause_menu.init(this);
this->win_menu.init(this);
this->level_1.init(this);
this->level_2.init(this);
this->level_3.init(this);
this->level_4.init(this);
this->level_5.init(this);
this->audio.play();
this->setMusicState(ON);
this->setCurTime(SDL_GetTicks());
}
void Game::process()
{
SDL_RenderClear(this->getRenderer());
if (this->getCurGameState() == GAME_STATE_MENU)
this->menu.process();
if (this->getCurGameState() == GAME_STATE_LEVELS_MENU)
this->levels_menu.process();
if (this->getCurGameState() == GAME_STATE_SCORES)
this->scores.process();
if (this->getCurGameState() == GAME_STATE_OPTIONS)
this->options.process();
if (this->getCurGameState() == GAME_STATE_PAUSE_MENU)
this->pause_menu.process();
if (this->getCurGameState() == GAME_STATE_WIN_MENU)
this->win_menu.process();
if (this->getCurGameState() == GAME_STATE_LEVEL_1)
this->level_1.process();
if (this->getCurGameState() == GAME_STATE_LEVEL_2)
this->level_2.process();
if (this->getCurGameState() == GAME_STATE_LEVEL_3)
this->level_3.process();
if (this->getCurGameState() == GAME_STATE_LEVEL_4)
this->level_4.process();
if (this->getCurGameState() == GAME_STATE_LEVEL_5)
this->level_5.process();
SDL_RenderPresent(this->getRenderer());
SDL_Delay(10);
}
void Game::quit()
{
this->audio.quit();
this->menu.quit();
this->levels_menu.quit();
this->scores.quit();
this->options.quit();
this->pause_menu.quit();
this->win_menu.quit();
this->level_1.quit();
this->level_2.quit();
this->level_3.quit();
this->level_4.quit();
this->level_5.quit();
SDL_DestroyRenderer(this->renderer);
SDL_DestroyWindow(this->window);
Mix_Quit();
TTF_Quit();
IMG_Quit();
SDL_Quit();
}