-
Notifications
You must be signed in to change notification settings - Fork 0
/
boulder.cpp
52 lines (41 loc) · 891 Bytes
/
boulder.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
#include "boulder.h"
#include <iostream>
using namespace std;
/** boulder **
*
* See header file for comments
*
**/
boulder::boulder(int startX, int startY)
{
character = 'B';
x = startX;
y = startY;
direction = 1;
}
boulder::~boulder()
{
}
bool boulder::update(game_board& board, int timestep)
{
if(board.get_char(x, y + direction) == '#')
direction *= -1;
if( direction == -1 && (timestep % 4) != 0)
return true;
else if( direction == 1 && (timestep % 2) != 0)
return true;
QChar newChar = board.get_char(x, y + direction);
if(newChar == '.' || newChar == '@')
{
board.set_char(x, y + direction, character);
board.set_char(x, y, '.');
y += direction;
if(newChar == '@')
player_collision(board);
}
return true;
}
void boulder::player_collision(game_board& board)
{
board.reset_player();
}