Inimigos e players afetados pelos tiros
[Projeto-PCG.git] / enemy.cpp
blob09c43918086eae4ad5649faa14e25ffc9ecbfd9e
1 #include "enemy.h"
2 #include "shot.h"
3 #include "player.h"
5 Enemy::Enemy(Game* agame): Shooter(agame, Ponto(0,0), Ponto(0,0)) {
8 void Enemy::die() {
9 if (dead) return;
10 dead = true;
11 //game->enemyManager->remove(this);
12 //game->gravityManager->deleteThing(this);
13 //game->collisionManager->remove(this);
16 void Enemy::think() {
17 if (dead) return;
18 if (game->player->getPosition().x < this->getPosition().x)
19 direction = -1;
20 else
21 direction = 1;
22 if (distance(game->player->getPosition(), this->getPosition()) >= 500)
23 return;
24 setAim(game->player->getPosition().x,game->player->getPosition().y-50);
25 fire();
28 void Enemy::collide(Thing* b) {
29 if (dead) return;
30 Shot* shot = dynamic_cast<Shot*>(b);
31 if (shot && shot->firedBy == game->player) {
32 this->die();