Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Entity.cpp
- #include "Entity.h"
- // Defining Entity Class
- Entity::Entity(){
- x = 0;
- y = 0;
- boundX = 0;
- boundY = 0;
- health = 0;
- speed = 0;
- bulletDelay = 0;
- destroyed = false;
- bitmap = 0;
- entities.push_back(this);
- }
- // Defining Collision function
- bool Entity::isColliding(Entity * otherEntity){
- if(destroyed || otherEntity->isDestroyed())
- return false;
- if(x + boundX < otherEntity->x || x > otherEntity->x + otherEntity->boundX || y + boundY < otherEntity->y || y > otherEntity->y + otherEntity->boundY)
- {
- return false;
- }
- else
- {
- al_draw_rectangle(x, y, boundX, boundY, al_map_rgb(255, 0, 0), NULL);
- return true;
- }
- }
- // Entity Class Deconstructor used to remove entites from the list
- Entity::~Entity(){
- entities.remove(this);
- // textprintf(screen,font,10,10,makecol(255,255,255),"deleting object\n",NULL);
- }
- // Entity Class draw function
- void Entity::draw(){
- if(!destroyed){
- al_draw_bitmap(bitmap, x, y, 0);
- }
- }
- // Entity update function
- void Entity::update(){
- }
- // doUpdate function
- void Entity::doUpdate(){
- if(!destroyed)
- update();
- }
- // is it destroyed??
- bool Entity::isDestroyed(){
- return destroyed;
- }
- // destroy this
- void Entity::destroy(){
- destroyed = true;
- }
- // the damage function remove 1.. in this case
- void Entity::takeDamage(int damage){
- health-= damage;
- if(health <= 0)
- this->destroy();
- }
Add Comment
Please, Sign In to add comment