Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Bullets.cpp Source File

Bullets.cpp

00001 #include "Bullets.h"
00002 
00003 // Constructor
00004 Bullets::Bullets(float pos_x, float pos_y, int dir)
00005 {
00006     _face = dir;
00007     _hp = 1;
00008     
00009     _hitbox.width = 3;
00010     _hitbox.height = 3;
00011     
00012     _position.x = pos_x;
00013     _position.y = pos_y;
00014     
00015     _sprite_size.width = 3;
00016     _sprite_size.height = 3;
00017     _sprite_size.offset_x = -1;
00018     _sprite_size.offset_y = -4;
00019 }
00020 
00021 // Functions
00022 void Bullets::move(float speed, float unused, char * unused2, bool * unused3)   //  Moves regarding face(constant after constructed)
00023 {
00024     if (_face == 0) {
00025         _position.y -= speed;
00026     } else if (_face == 1) {
00027         _position.x += speed;
00028     } else if (_face == 2) {
00029         _position.y += speed;
00030     } else if (_face == 3) {
00031         _position.x -= speed;
00032     }
00033 }
00034 
00035 void Bullets::draw(N5110 &lcd)
00036 {
00037     lcd.drawSpriteTransparent(_position.x+_sprite_size.offset_x,
00038                               _position.y+_sprite_size.offset_y,
00039                               _sprite_size.height,
00040                               _sprite_size.width,
00041                               (char *) bullets_sprite);
00042 }
00043 
00044 void Bullets::take_damage(int damage)   // Taking damage, currently not used(has to be inherited, as well as useful for possible future use)
00045 {
00046     _hp -= damage;
00047 }
00048 
00049 bool Bullets::out_of_bounds_check(char * map, bool * doorways)  // Returns true when bullets exit map or collide with walls
00050 {
00051     if (entity_to_map_collision_test(_position.x, _position.y, map, doorways)) {
00052         return true;
00053     }
00054     if ((0 > _position.x) || (_position.x > 84) || (0 > _position.y) || (_position.y > 48)) {
00055         return true;
00056     }
00057     return false;
00058 }