Ajuste leve na velocidade permitindo movimentos mais sutis
[Projeto-PCG.git] / enemy.cpp
bloba8464f4358a43b9bcfa1bc0f5b0caab1ceaeddba
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 double Enemy::distanceFromPlayer() {
17 return distance(game->player->getPosition(), this->getPosition());
19 #include <iostream>
20 void Enemy::think() {
21 addSpeed(closerToZero(-getSpeedX(),sign(getSpeedX())*-0.5),0);
22 crawl = false;
23 if (dead) return;
24 Player *player = game->player;
25 Ponto playerpos = player->getPosition();
26 if (playerpos.x < getPosition().x)
27 direction = -1;
28 else
29 direction = 1;
30 if (distanceFromPlayer() >= 500)
31 return;
32 if (player->crawl && onGround)
33 crawl = true;
34 if (playerpos.y > getPosition().y + 30 && distanceFromPlayer() <= 200)
35 bypass = true;
36 else
37 bypass = false;
38 if (playerpos.y < getPosition().y && player->onGround) {
39 addSpeed( 0, -1);
41 if (distanceFromPlayer() <= 300 && distanceFromPlayer() >= 200)
42 addSpeed( direction*3, 0);
43 Ponto leftfeet = player->leftFeet();
44 Ponto rightfeet = player->rightFeet();
45 setAim(playerpos.x + player->pescoco().x,playerpos.y+player->pescoco().y + std::min(-rightfeet.y,-leftfeet.y));
46 fire();
49 void Enemy::collide(Thing* b) {
50 if (dead) return;
51 Shot* shot = dynamic_cast<Shot*>(b);
52 if (shot && shot->firedBy == game->player) {
53 this->die();
55 Shooter* shooter = dynamic_cast<Shooter*>(b);
56 if (shooter) {
57 if (shooter->getPosition().x > getPosition().x)
58 addSpeed(-2,0);
59 else
60 addSpeed(2,0);
64 void Enemy::drawEquipment() {
65 glPushMatrix();
66 Ponto hip = cintura();
67 Ponto leftfeet = leftFeet();
68 Ponto rightfeet = rightFeet();
69 glTranslatef(hip.x,hip.y,0);
70 glRotatef(bodyAngle*180.0/PI,0,0,1);
71 glBegin(GL_LINE_LOOP);
72 glVertex3f(0,0,0);
73 glVertex3f(-10,0,0);
74 glVertex3f(-10,-30,0);
75 glVertex3f(0,-30,0);
76 glEnd();
77 glBegin(GL_LINE_LOOP);
78 glVertex3f(-2.5,0,0);
79 glVertex3f(-7.5,0,0);
80 glVertex3f(-7.5,5,0);
81 glVertex3f(-2.5,5,0);
82 glEnd();
83 glPopMatrix();