-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlevel_manager.cpp
More file actions
87 lines (66 loc) · 1.86 KB
/
level_manager.cpp
File metadata and controls
87 lines (66 loc) · 1.86 KB
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
#include "level_manager.h"
LevelManager::LevelManager() {
}
LevelManager::~LevelManager() {
if (_level != NULL) {
delete _level;
}
}
void LevelManager::initialize(int screenWidth, int screenHeight, Ship *ship) {
_screenWidth = screenWidth;
_screenHeight = screenHeight;
_ship = ship;
_level = new Level(_screenWidth, _screenHeight, 1, _ship, 0, 0);
}
bool LevelManager::update(unsigned int ticks) {
switch (_currentState) {
case GALAGA_LEVEL_MANAGER_STATE_MAIN:
_level->update(ticks);
if (_level->isComplete()) {
++_currentLevel;
int oldDifficulty = _level->getDifficulty();
int score = _level->getScore();
int shotHits = _level->getShotsHit();
delete _level;
_level = new Level(_screenWidth, _screenHeight, oldDifficulty + 1,
_ship, score, shotHits);
_currentState = GALAGA_LEVEL_MANAGER_STATE_TRANSITION;
_stateTicks = 0;
}
break;
case GALAGA_LEVEL_MANAGER_STATE_TRANSITION:
if (_stateTicks > 100) {
_currentState = GALAGA_LEVEL_MANAGER_STATE_MAIN;
_stateTicks = 0;
}
break;
}
++_stateTicks;
return true;
}
void LevelManager::render() {
switch (_currentState) {
case GALAGA_LEVEL_MANAGER_STATE_MAIN:
_level->render();
break;
case GALAGA_LEVEL_MANAGER_STATE_TRANSITION:
if (_stateTicks < 90) {
ALLEGRO_FONT *font = AssetManager::getFont("big");
int lineHeight = al_get_font_line_height(font);
al_draw_textf(font, al_map_rgb(255, 0, 0), _screenWidth / 2,
_screenHeight / 2 - lineHeight / 2, ALLEGRO_ALIGN_CENTRE, "LEVEL %d",
_currentLevel);
}
break;
}
}
int LevelManager::getScore() {
return _level == NULL ? 0 : _level->getScore();
}
int LevelManager::getShotsHit() {
return _level == NULL ? 0 : _level->getShotsHit();
}
bool LevelManager::isTransitioning() {
return _currentState == GALAGA_LEVEL_MANAGER_STATE_TRANSITION
&& _stateTicks < 90;
}