-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMagic.cpp
45 lines (40 loc) · 891 Bytes
/
Magic.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
#include "Magic.h"
#include "Character.h"
#include "Terrain.h"
void FireBall::act(Map *map)
{
Vec2i coords = _coords;
Vec2i newCoords = _coords + _direction;
if (map->isValidCell(newCoords))
{
map->getActor(newCoords);
collide(map, map->getActor(newCoords));
}
map->setHasActed(coords);
}
void FireBall::collide(Map *map, Character *target)
{
target->recieveDamage(_power);
if (target->isDead())
{
map->clearCell(target->coordinates());
}
map->clearCell(_coords);
}
char FireBall::getSymbolFromDir(Vec2i direction)
{
if (direction == Vec2i(-1, 0))
return '<';
if (direction == Vec2i(1, 0))
return '>';
if (direction == Vec2i(0, -1))
return '^';
if (direction == Vec2i(0, 1))
return 'v';
throw std::runtime_error(FIREBAL_DIRECTION_ERR);
}
void FireBall::collide(Map *map, Magic *target)
{
map->clearCell(target->coordinates());
map->clearCell(_coords);
}