Ikenna Adrian Ozoemena 201157039

Dependencies:   mbed

Weapons/Weapons.cpp

Committer:
ikenna1
Date:
2019-04-18
Revision:
27:f99249e727fd
Parent:
26:a53d41adf40b
Child:
39:7824f9080f59

File content as of revision 27:f99249e727fd:

#include "Weapons.h"
DigitalIn A_button(PTB9);

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,Gamepad &pad,int shipno)
{
    if(shipno == 0) {
        _velocity.x = 0; //Projectile doesn't move sideways.
        _velocity.y = -5; //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) {
        if((A_button) == true) {
            // while((A_button) == true) {
            pad.tone(2000,0.1);
            lcd.drawRect(_ship_xpos - 1, 0,3,_ship_ypos + 6,FILL_BLACK);
            wait(0.1);
            //}
        }
    }
    if(shipno == 2){
        }
}


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



Vector2D Weapons::get_pos(int shipno)
{
    if(shipno == 0) {
        Vector2D pos = {_x,_y};
        return pos;
    }
}

void Weapons::set_pos(int xpos, int ypos)
{
    _x = xpos;
    _y = ypos;
}