Classe WeaponItem (parcial)
[Projeto-PCG.git] / shot.cpp
bloba5d78a1d57b74403be0c88a39e0393228dd8cfcf
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 <math.h>
9 Shot::Shot(double x, double y, double angle, double speed, double gravity, Weapon* w) {
10 game = w->game;
11 setPosition(x,y);
12 if (gravity != 0.0)
13 game->gravityManager->subscribe(this);
14 game->collisionManager->subscribe(this);
15 gravityRate = gravity;
16 bypass = true;
17 setSpeed(-cos(angle)*speed,sin(angle)*speed);
20 Shot::~Shot() {
21 game->shotManager->deleteShot(this);
22 game->collisionManager->remove(this);
23 if (gravityRate != 0.0)
24 game->gravityManager->deleteThing(this);
27 void Shot::desenha() {
28 glPushMatrix();
29 glTranslatef(getX(),getY(),0);
30 sprite.desenha();
31 glPopMatrix();
34 Polygon Shot::getCollision() {
35 Ponto atual(getX(),getY());
36 Polygon collisionSprite = sprite;
37 for (int i = 0; i < collisionSprite.linhas.size();i++) {
38 collisionSprite.linhas[i].vertices[0] = collisionSprite.linhas[i].vertices[0] + atual;
39 collisionSprite.linhas[i].vertices[1] = collisionSprite.linhas[i].vertices[1] + atual;
41 return collisionSprite;
44 #include <iostream>
46 void Shot::collide(Thing* b){
47 Player* p;
48 if (p = dynamic_cast<Player*>(b)) {
49 std::cout<<"Player deaded "<<p<<std::endl;