-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameStart.cpp
109 lines (93 loc) · 2.58 KB
/
GameStart.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
/*
* GameStart.cpp
*
* Created on: Sep 4, 2013
* Author: ian
*/
#include <stdlib.h>
#include "GameManager.h"
#include "LogManager.h"
#include "ResourceManager.h"
#include "GraphicsManager.h" // for COLOR_YELLOW
#include "WorldManager.h"
// game includes
#include "GameStart.h"
#include "Hero.h"
#include "Points.h"
#include "EventKeyboard.h"
#include "RapidFire.h"
#include "HealthPickup.h"
#include "MaxHealthPickup.h"
#include "Monster.h"
#include "MazePiece.h"
#include "LevelManager.h"
// different pickup items
#include "HealthPickup.h"
#include "RapidFire.h"
#define MAZE_WALL_COUNT 30
GameStart::GameStart() {
// link to "message" sprite
ResourceManager &resource_manager = ResourceManager::getInstance();
Sprite *p_temp_sprite = resource_manager.getSprite("game_start");
if (!p_temp_sprite) {
LogManager &log_manager = LogManager::getInstance();
log_manager.writeLog(
"GameStart::GameStart(): Warning! Sprite 'gamestart' not found");
} else {
setSprite(p_temp_sprite);
setSpriteSlowdown(15);
}
// put in center of screen
WorldManager &world_manager = WorldManager::getInstance();
Position pos(
world_manager.getBoundary().getCorner().getX()
+ world_manager.getBoundary().getHorizontal() / 2,
world_manager.getBoundary().getCorner().getY()
+ world_manager.getBoundary().getVertical() / 2);
setPosition(pos);
// register for "keyboard" event
registerInterest(KEYBOARD_EVENT);
}
// handle event
// return 0 if ignored, else 1
int GameStart::eventHandler(Event *p_e) {
WorldManager &world_manager = WorldManager::getInstance();
GameManager &game_manager = GameManager::getInstance();
// keyboard
if (p_e->getType() == KEYBOARD_EVENT) {
EventKeyboard *p_keyboard_event = (EventKeyboard *) p_e;
switch (p_keyboard_event->getKey()) {
case 'p': // play
start();
world_manager.markForDelete(this);
break;
case 'q': // quit
game_manager.setGameOver();
break;
default:
break;
}
return 1;
}
// if we get here, we have ignored this event
return 0;
}
void GameStart::start() {
WorldManager &world_manager = WorldManager::getInstance();
LevelManager &level_manager = LevelManager::getInstance();
//Load level and set level
level_manager.nextLevel();
// level_manager.loadLevel("level_1");
// level_manager.loadLevel("level_2");
ViewObject *h_vo = new ViewObject; // used for health count
h_vo->setLocation(TOP_LEFT);
h_vo->setViewString("Health");
h_vo->setType("Health");
h_vo->setValue(1);
h_vo->setColor(COLOR_RED);
new Points;
}
// override default draw so as not to display "value"
void GameStart::draw() {
Object::draw();
}