Target Library

Dependents:   GameProject_Prototype

Target.cpp

Committer:
ll14c4p
Date:
2017-05-03
Revision:
12:855610bdba49
Parent:
11:5b2be6934e1b
Child:
13:828ede9cf8a5

File content as of revision 12:855610bdba49:

#include "Target.h"

Target::Target()
{

}

Target::~Target()
{

}

int sprite2[8][10] = {
    {1,1,1,1,1,1,1,1,1,1},
    {1,1,0,1,0,1,0,1,0,1},
    {1,0,1,0,1,0,1,0,1,1},
    {1,1,0,1,0,1,0,1,0,1},
    {1,0,1,0,1,0,1,0,1,1},
    {1,1,0,1,0,1,0,1,0,1},
    {1,0,1,0,1,0,1,0,1,1},
    {1,1,1,1,1,1,1,1,1,1},
    };
    
int n = 0;
void Target::init() //Delete Int
{

    
}


void Target::draw(N5110 &lcd)
{   

    //_velocity.x = 1;
    _velocity.y = 1;
    
   /* int random = rand() % 3;
    if(random == 0){
        _velocity.x = 0;
        }
    if(random == 1){
        _velocity.x = 2;
        }
    if(random == 2){
        _velocity.x = -2;
        }
    if(random == 3){
        _velocity.x = -2;
        }
    */
    
    if(_x <= -1){
        _x = 0;
        }
    if(_x >= 75){
        _x = 74;
        }
    if(_y >= 48){
        n = 0;
        }
    
     if(n == 0){
        _x = rand() % 79;
        _y = 0; //rand() % 20;
        n = n+1;  
        }

    lcd.drawSprite(_x,_y,8,10,(int *)sprite2);
}



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




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

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

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

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