-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectile.cpp
38 lines (32 loc) · 1005 Bytes
/
Projectile.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
#pragma once
#include "Entity.hpp"
#include "Object.hpp"
#include "Utility.hpp"
#include "Projectile.hpp"
class Enemy;
Projectile::Projectile(int id, util::Point pos, util::Point direction, char sym, int dmg, bool isPlayer) : Entity(sym, 1, dmg, id, pos), speed(direction), isPlayer(isPlayer) {}
void Projectile::update(util::GameInfo& game) {
if (game[this->pos] != '.' && game[this->pos] != symbol) {
enabled = false;
if (game[this->pos] == '#') {
return;
}
auto& tmp = findCollision(this->pos, game);
tmp.interact(*this, game);
return;
}
game[this->pos] = '.';
auto newPos = pos + speed;
if (!util::checkPoint(game.map, newPos) || game[newPos] == '#') {
enabled = false;
return;
}
if (game[newPos] != '.') {
auto& tmp = findCollision(newPos, game);
tmp.interact(*this, game);
return;
}
this->pos = newPos;
game[this->pos] = this->symbol;
return;
}