ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Bullet/Bullet.cpp

Committer:
el17m2h
Date:
2019-04-24
Revision:
16:e0542761fc8c
Child:
17:74de8c17ddac

File content as of revision 16:e0542761fc8c:

#include "Bullet.h"
Bullet::Bullet(){
}
Bullet::~Bullet(){
}

void Bullet::init(float dood_position_x, float dood_position_y){  
    _radius = 1;
    _position_x = dood_position_x; // initially in same position as doodler
    _position_y = dood_position_y;
}

void Bullet::draw(N5110 &lcd){
    lcd.drawCircle(_position_x, _position_y, _radius, FILL_BLACK);
}

void Bullet::update(float dood_position_x, float dood_position_y, bool button_Y){
    _position_x = get_position_x();
    _position_y = get_position_y();
    if (button_Y == true){
        _position_y -= 2; // moves upwards    
    } 
    if (_position_y < 0){ // checking it leaves screen
        _position_x =dood_position_x;
        _position_y =dood_position_y;
    }
}

float Bullet::get_position_x(){
    float p_x = _position_x; 
    return p_x;
}

float Bullet::get_position_y(){
    float p_y = _position_y;
    return p_y;
}

float Bullet::get_velocity_x(){
    float v_x = _velocity_x;
    return v_x;
}

double Bullet::get_velocity_y(){
    double v_y = (double)_velocity_y;
    return (double)v_y;
}

void Bullet::set_velocity(float vel_x, double vel_y){
    _velocity_x = vel_x;
    _velocity_y = (double)vel_y;
}

void Bullet::set_position(float pos_x, float pos_y){
    _position_x = pos_x; 
    _position_y = pos_y;
}