forked from AlexMPC/ALL-Project-2-master-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplayer.cpp
More file actions
30 lines (28 loc) · 758 Bytes
/
player.cpp
File metadata and controls
30 lines (28 loc) · 758 Bytes
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
#include "player.h"
#include "level.h"
Player::Player (int x, int y) {
xPos = x;
yPos = y;
}
bool Level::playerMove(char direction) { //Returns true if valid move, false if not
int x = player->xPos;
int y = player->yPos;
vector< vector<char> > map = getMapWithEntities();
if(direction == 'U' && map[y-1][x] == ' ') { //up
player->yPos = y-1;
return true;
}
else if(direction == 'L' && map[y][x-1] == ' ') { //left
player->xPos = x-1;
return true;
}
else if(direction == 'D' && map[y+1][x] == ' ') { //down
player->yPos = y+1;
return true;
}
else if(direction == 'R' && map[y][x+1] == ' ') { //right
player->xPos = x+1;
return true;
}
return false;
}