Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Entity/Bullets/Bullets.cpp

Committer:
el17sm
Date:
2019-04-29
Revision:
27:a1b41626f57c
Parent:
26:abbc19edc5c1
Child:
28:98848e6a77a2

File content as of revision 27:a1b41626f57c:

#include "Bullets.h"

Bullets::Bullets(float pos_x, float pos_y, int dir)
{
    moving = true;
    face = 0;
    hp = 1;
    hitbox.width = 3;
    hitbox.height = 3;
    position.x = pos_x;
    position.y = pos_y;
    sprite_size.width = 3;
    sprite_size.height = 3;
    sprite_size.offset_x = 0;
    sprite_size.offset_y = 1;
    direction = dir;
}

void Bullets::move(float speed, float unused, int * unused2)
{
    if (direction == 0) {
        position.y -= speed;
    } else if (direction == 1) {
        position.x += speed;
    } else if (direction == 2) {
        position.y += speed;
    } else if (direction == 3) {
        position.x -= speed;
    }
}

void Bullets::take_damage(int damage)
{
    hp -= damage;
}

int * Bullets::get_frame()
{
    return (int *) bullets_sprite;
}

bool Bullets::out_of_bounds_check(int * map)
{
    if (matrix_collision_test(position.x, position.y, map)) {
        return true;
    }
    if ((0 > position.x) || (position.x > 84) || (0 > position.y) || (position.y > 48)) {
        return true;
    }
    return false;
}