-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLadder.cpp
More file actions
47 lines (37 loc) · 1.03 KB
/
Ladder.cpp
File metadata and controls
47 lines (37 loc) · 1.03 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
// game engine includes
#include "GraphicsManager.h"
// IHOP includes
#include "Ladder.h"
// constructor for Ladder needs length of section of Ladder
Ladder::Ladder(df::Position init_pos, int init_length){
setPosition(init_pos);
length = init_length;
setType("Ladder");
}
// get the length of the section of Ladder
int Ladder::getLength() const {
return length;
}
// set the length of the section of Ladder
void Ladder::setLength(int new_length){
length = new_length;
}
// return true if position falls on Ladder, false otherwise
bool Ladder::onMapObject(df::Position pos) const{
int x = pos.getX();
int y = pos.getY();
if (x == this->getPosition().getX() &&
y >= this->getPosition().getY() &&
y <= this->getPosition().getY() + length -1) {
return true;
}
return false;
}
void Ladder::draw() {
df::GraphicsManager &gm = df::GraphicsManager::getInstance();
int x = getPosition().getX();
int y = getPosition().getY();
for (int i = 0; i < length; i++) {
gm.drawCh(df::Position(x, y + i), LADDER_CHAR, df::Color::WHITE);
}
}