-
Notifications
You must be signed in to change notification settings - Fork 0
/
spell.cpp
80 lines (66 loc) · 1.18 KB
/
spell.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
72
73
74
75
76
77
78
79
80
#include "spell.h"
#include <iostream>
using namespace std;
/** spell **
*
* See header file for comments
*
**/
spell::spell(int startX, int startY, int playerX, int playerY)
{
character = '+';
x = startX;
y = startY;
this->playerX = playerX;
this->playerY = playerY;
px = startX;
py = startY;
dx = qAbs(playerX - startX);
dy = qAbs(playerY - startY);
if( startX < playerX )
sx = 1;
else
sx = -1;
if( startY < playerY )
sy = 1;
else
sy = -1;
err = dx - dy;
}
spell::~spell()
{
}
bool spell::update(game_board& board, int timestep)
{
if( (timestep % 1) != 0 )
return true;
// if x0 = x1 and y0 = y1 exit loop
int e2 = 2*err;
if( e2 > -dy )
{
err -= dy;
x += sx;
}
if( e2 < dx )
{
err = err + dx;
y = y + sy;
}
board.set_char(px, py, '.');
px = x;
py = y;
QChar comp = board.get_char(x,y);
if( comp == '@' )
{
player_collision(board);
return false;
}
else if( comp != '.' )
return false;
board.set_char(x, y, character);
return true;
}
void spell::player_collision(game_board& board)
{
board.reset_player();
}