Projectile Library

Projectile.cpp

Committer:
ll14c4p
Date:
2017-05-02
Revision:
5:023fe92d6384
Parent:
4:977109f7b9f6
Child:
6:70b35ebfa8c8

File content as of revision 5:023fe92d6384:

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

Projectile::Projectile()
{

}

Projectile::~Projectile()
{

}


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;
    _velocity.y = -3;
    

    printf("playerxy projdraw = %d %d \n", _playerx, _playery);
    
    
    if(_x <= -1){
        m = 0;
        }
    if(_x >= 85){
        m = 0;
        }
    if(_y <= -1){
        m = 0;
        }
    if(_y >= 49){
        m = 0;
        }
        
        
        
    if(m == 0){
        _x = _playerx +1;  // Middle of screen // Change these values to change starting position
        _y = _playery +1; // Near bottom of screen
        m = m+1;  
        }
    lcd.drawRect(_x,_y,1,1,FILL_BLACK);
    printf("projdrawn %d %d \n", _x, _y);
    //printf("playerpos in proj = %d %d \n", playerx, playery);
    
}

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

void Projectile::set_velocity(Vector2D v)
{
    _velocity.x = v.x;
    _velocity.y = v.y;
}

Vector2D Projectile::get_velocity()
{
    Vector2D v = {_velocity.x,_velocity.y};
    return v;
}

Vector2D Projectile::get_pos()
{
    Vector2D projpos = {_x,_y};
    //printf("projpos = %f %f \n", projpos.x, projpos.y);
    return projpos;
}