Guest User

Untitled

a guest
Jan 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. // Entity.cpp
  2. #include "Entity.h"
  3.  
  4. // Defining Entity Class
  5. Entity::Entity(){
  6.      x = 0;
  7.      y = 0;
  8.      boundX = 0;
  9.      boundY = 0;
  10.      health = 0;
  11.      speed = 0;
  12.      bulletDelay = 0;
  13.      destroyed = false;
  14.      bitmap = 0;
  15.      entities.push_back(this);    
  16. }
  17.  
  18. // Defining Collision function
  19. bool Entity::isColliding(Entity * otherEntity){
  20.     if(destroyed || otherEntity->isDestroyed())
  21.         return false;
  22.    
  23.     if(x + boundX < otherEntity->x || x > otherEntity->x + otherEntity->boundX || y + boundY < otherEntity->y || y > otherEntity->y + otherEntity->boundY)
  24.     {
  25.         return false;
  26.     }
  27.     else
  28.     {
  29.         al_draw_rectangle(x, y, boundX, boundY, al_map_rgb(255, 0, 0), NULL);
  30.         return true;
  31.     }
  32. }
  33.  
  34. // Entity Class Deconstructor used to remove entites from the list
  35. Entity::~Entity(){      
  36.      entities.remove(this);
  37.    //  textprintf(screen,font,10,10,makecol(255,255,255),"deleting object\n",NULL);
  38.  
  39. }
  40.  
  41. // Entity Class draw function
  42. void Entity::draw(){
  43.      if(!destroyed){   
  44.         al_draw_bitmap(bitmap, x, y, 0);
  45.      }
  46. }
  47.  
  48. // Entity update function
  49. void Entity::update(){
  50. }
  51.  
  52. // doUpdate function
  53. void Entity::doUpdate(){
  54.      if(!destroyed)
  55.      update();
  56. }
  57.  
  58. // is it destroyed??
  59. bool Entity::isDestroyed(){
  60.      return destroyed;
  61. }
  62.  
  63. // destroy this
  64. void Entity::destroy(){
  65.      destroyed = true;
  66. }
  67.  
  68. // the damage function remove 1.. in this case
  69. void Entity::takeDamage(int damage){
  70.      health-= damage;
  71.      if(health <= 0)
  72.      this->destroy();
  73. }
Add Comment
Please, Sign In to add comment