-
Notifications
You must be signed in to change notification settings - Fork 0
/
zombie.cpp
59 lines (48 loc) · 1.05 KB
/
zombie.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
#include "zombie.h"
#include <iostream>
using namespace std;
zombie::zombie(int startX, int startY, player* _player)
{
this->_player = _player;
character = 'Z';
x = startX;
y = startY;
direction = 1;
}
zombie::~zombie()
{
}
bool zombie::update(game_board& board, int timestep)
{
if( (timestep % 10) != 0 )
return true;;
int xDirection;
int yDirection;
if (x > _player->getX())
xDirection = -1;
else if (x < _player->getX())
xDirection = 1;
else
xDirection = 0;
if (y > _player->getY())
yDirection = -1;
else if (y < _player->getY())
yDirection = 1;
else
yDirection = 0;
QChar newChar = board.get_char(x + xDirection, y + yDirection);
if(newChar == '.' || newChar == '@')
{
board.set_char(x + xDirection, y + yDirection, character);
board.set_char(x, y, '.');
y += yDirection;
x += xDirection;
if(newChar == '@')
player_collision(board);
}
return true;
}
void zombie::player_collision(game_board& board)
{
board.reset_player();
}