-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBus.cpp
More file actions
61 lines (50 loc) · 1.96 KB
/
Bus.cpp
File metadata and controls
61 lines (50 loc) · 1.96 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
// system includes
#include <string>
// game engine includes
#include "LogManager.h"
#include "GraphicsManager.h"
#include "GameManager.h"
#include "EventStep.h"
#include "EventOut.h"
#include "EventKeyboard.h"
#include "Utility.h"
// tester includes
#include "Bus.h"
// constructor to set velocity
Bus::Bus(){
setType("Bus");
setSolidness(df::SOFT);
}
// overloaded constructor to set initial position and altitude.
Bus::Bus(df::Position pos, int alt){
setType("Bus");
setSolidness(df::SOFT);
setPosition(pos);
setAltitude(alt);
}
// defines how to draw the bus
void Bus::draw(){
int x = getPosition().getX();
int y = getPosition().getY();
// multiline drawing of a bus
df::GraphicsManager::getInstance().drawString(df::Position(x, y - 1), " --------+", df::Justification::LEFT_JUSTIFIED, df::Color::YELLOW);
df::GraphicsManager::getInstance().drawString(df::Position(x, y), " / |", df::Justification::LEFT_JUSTIFIED, df::Color::YELLOW);
df::GraphicsManager::getInstance().drawString(df::Position(x, y + 1), "/ |", df::Justification::LEFT_JUSTIFIED, df::Color::YELLOW);
df::GraphicsManager::getInstance().drawString(df::Position(x, y + 2), "| |", df::Justification::LEFT_JUSTIFIED, df::Color::YELLOW);
df::GraphicsManager::getInstance().drawString(df::Position(x, y + 3), "o---------o", df::Justification::LEFT_JUSTIFIED, df::Color::YELLOW);
}
// Handle event (default is to ignore everything).
// Return 0 if ignored, else 1 if handled.
int Bus::eventHandler(df::Event *p_e){
// if out of bounds then end game
if (p_e->getType() == DF_OUT_EVENT){
df::GameManager::getInstance().setGameOver();
return 1;
}
// if the space key is pressed then set the velocity of the bus to start moving
else if (p_e->getType() == df::DF_KEYBOARD_EVENT && ((df::EventKeyboard *) p_e)->getKeyboardAction() == df::EventKeyboardAction::KEY_PRESSED && ((df::EventKeyboard *) p_e)->getKey() == df::Input::SPACE){
setXVelocity(-0.1);
return 1;
}
return 0;
}