Agora ele olha pra frente deitado
[Projeto-PCG.git] / shot.cpp
blob5be3c93315e01cc148aa7672006679939c7a200b
1 #include "shot.h"
2 #include "weapon.h"
3 #include "game.h"
4 #include "shotmanager.h"
5 #include "collision.h"
6 #include "player.h"
7 #include "shooter.h"
8 #include "enemy.h"
9 #include <math.h>
11 Shot::Shot(double x, double y, double angle, double speed, double gravity, Weapon* w, int damage) {
12 game = w->game;
13 firedBy = w->firedBy;
14 this->damage = damage;
15 setPosition(x,y);
16 if (gravity != 0.0)
17 game->gravityManager->subscribe(this);
18 game->collisionManager->subscribe(this);
19 gravityRate = gravity;
20 bypass = true;
21 setSpeed(-cos(angle)*speed,sin(angle)*speed);
24 Shot::~Shot() {
25 game->shotManager->deleteShot(this);
26 game->collisionManager->remove(this);
27 if (gravityRate != 0.0)
28 game->gravityManager->deleteThing(this);
31 void Shot::desenha() {
32 glPushMatrix();
33 glTranslatef(getX(),getY(),0);
34 sprite.desenha();
35 glPopMatrix();
38 Polygon Shot::getCollision() {
39 Polygon collisionSprite = sprite;
40 return collisionSprite;
43 void Shot::collide(Thing* b){
44 if (dead) return;
45 /*Player* p = dynamic_cast<Player*>(b);
47 Enemy* e = dynamic_cast<Enemy*>(b);
48 std::cout<<b<<std::endl;
49 if (p ) {
51 else if (e ) {
52 e->die();
54 }*/
57 bool Shot::canCollide(Thing* b) {
58 Shooter* shooter = dynamic_cast<Shooter*>(b);
59 return shooter;