-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrate.cpp
56 lines (46 loc) · 985 Bytes
/
Crate.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
#include "Crate.h"
#include "Map.h"
Crate::Crate(int x, int y, Map* map) : Item(x, y), selfMap_(map) {
type = 'B';
}
char* Crate::getPath() {
return IMAGE_PATH;
}
bool Crate::Collide(Directions dir) {
//return true if crate can be moved to next position
int tmpX = yPosition;
int tmpY = xPosition;
//direction to where crate is pushed
switch (dir) {
case UP:
tmpY--;
break;
case DOWN:
tmpY++;
break;
case LEFT:
tmpX--;
break;
case RIGHT:
tmpX++;
break;
}
int mapWidth = selfMap_->getMapWidth();
int mapHeight = selfMap_->getMapHeight();
if (tmpX<0 || tmpX>mapWidth || tmpY<0 || tmpY>mapHeight) {
return false;
}
Item* itemOnPosition;
itemOnPosition = selfMap_->getItem(tmpX, tmpY);
char type = itemOnPosition->getType();
//item is ground
if (type == 'E') {
return true;
}
//item is endpoint
if (type == 'F') {
return true;
}
//cant move into boxes for now
return false;
}