ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Weapons/Weapons.cpp

Committer:
ikenna1
Date:
2019-04-14
Revision:
22:8cad70085883
Parent:
14:88ca5b1a111a
Child:
23:0301effce801

File content as of revision 22:8cad70085883:

#include "Weapons.h"


Weapons::Weapons()
{

}

Weapons::~Weapons()
{

}

//Obtains the player position coordinates in the initialisation stage.
void Weapons::init(int ship_xpos, int ship_ypos, int ship_width)
{
    //printf("ship x, ship y = %d , %d \n", playerx, playery);
    _ship_xpos = ship_xpos + (ship_width/2);
    _ship_ypos = ship_ypos;

}



void Weapons::draw(N5110 &lcd,int shipno)
{
    if(shipno == 0) {
        _velocity.x = 0; //Projectile doesn't move sideways.
        _velocity.y = -1; //Projectile moves upwards on screen.

        //resets once projectile reaches top of screen
        if(_y <= -1) {
            reset= 0;
        }

        if(reset == 0) {
            _x = _ship_xpos;
            _y = _ship_ypos;
            reset = reset+1;
        }
        lcd.drawRect(_x,_y,1,4,FILL_BLACK);
        // printf("Ship x and y pos, reset = %d , %d ,%d \n", _ship_xpos, _ship_ypos, reset);
    }
    if(shipno == 1) {
        lcd.drawRect(_ship_xpos - 2, 0,3,_ship_ypos + 6,FILL_BLACK);
    }
}


void Weapons::update()
{
    _x = _x + _velocity.x;
    _y = _y + _velocity.y;
}



Vector2D Weapons::get_pos()
{
    Vector2D pos = {_x,_y};
    return pos;
}

void Weapons::set_pos(Vector2D p)
{
    _x = p.x;
    _y = p.y;
}