-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.cpp
71 lines (67 loc) · 1.45 KB
/
robot.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
#include "robot.h"
#include "robotgame.h"
bool Robot::CanMove(olc::vi2d pos)
{
return this->map->GetPos("walls", pos) == 0;
}
bool Robot::Move(SIDE side)
{
bool moved = false;
switch (side)
{
case SIDE::UP:
if (this->CanMove(this->pos + olc::vi2d{0, -1}))
{
this->pos.y--;
moved = true;
}
break;
case SIDE::DOWN:
if (this->CanMove(this->pos + olc::vi2d{0, 1}))
{
this->pos.y++;
moved = true;
}
break;
case SIDE::LEFT:
if (this->CanMove(this->pos + olc::vi2d{-1, 0}))
{
this->pos.x--;
moved = true;
}
break;
case SIDE::RIGHT:
if (this->CanMove(this->pos + olc::vi2d{1, 0}))
{
this->pos.x++;
moved = true;
}
break;
}
if (this->map->GetPos("items", this->pos))
this->PickUp();
return moved;
}
bool Robot::PickUp()
{
int item = this->map->GetPos("items", this->pos);
switch (item)
{
case 1:
game->inventory[1].first++;
break;
case 3:
game->inventory[0].first++;
break;
case 6:
game->inventory[2].first++;
break;
case 10:
game->inventory[5].first++;
break;
default:
return false;
}
this->map->SetPos("items", this->pos, 0);
return true;
}