Projectile Library

Projectile.cpp

Committer:
ll14c4p
Date:
2017-05-04
Revision:
11:aa2ca5b358fe
Parent:
9:64ba68ae2640

File content as of revision 11:aa2ca5b358fe:

#include "Projectile.h"
#include "Player.h"

Projectile::Projectile()
{

}

Projectile::~Projectile()
{

}

//Obtains the player position coordinates in the initialisation stage.
void Projectile::init(int playerx, int playery)
{
    //printf("playerxy proj = %d %d \n", playerx, playery);
    _playerx = playerx;
    _playery = playery;
    //Make intial position of projectile = centre of player

}



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

    //printf("playerxy projdraw = %d %d \n", _playerx, _playery);
    
    
//Resets projectile if it reaches the top of the screen.
    if(_y <= -1){
        m = 0;
        }

//Sets projectile spawn location onto the player sprite.
    if(m == 0){
        _x = _playerx +2;  
        _y = _playery; 
        m = m+1;  
        }
    lcd.drawRect(_x,_y,2,2,FILL_BLACK); //Projectile is a 2x2 square.
    //printf("projdrawn %d %d \n", _x, _y);
    //printf("playerpos in proj = %d %d \n", playerx, playery);
    
}

void Projectile::update() //Updates projectile on screen.
{
    _x += _velocity.x;
    _y += _velocity.y;
}



Vector2D Projectile::get_pos() //Obtains the position of the projectile, used to check if a collision occurs.
{
    Vector2D projpos = {_x,_y};
    //printf("projpos = %f %f \n", projpos.x, projpos.y);
    return projpos;
}

void Projectile::set_pos(Vector2D p) //Used to update the projectile location after colliding with another object.
{
    _x = p.x;
    _y = p.y;
}