Target Library
Dependents: GameProject_Prototype
Target.cpp
- Committer:
- ll14c4p
- Date:
- 2017-05-04
- Revision:
- 14:0f590475ba85
- Parent:
- 13:828ede9cf8a5
File content as of revision 14:0f590475ba85:
#include "Target.h" Target::Target() { } Target::~Target() { } //Target Sprite. 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; //Sideways velocity is randomised. //Remember to seed /* 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; } */ //Resets target position if it reaches the bottom of the screen. //Also prevents target from going out of the side of the screen. 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); //Function to draw the sprite. } Vector2D Target::get_pos() //Obtains the X and Y coordinate of the target. { 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_pos(Vector2D p) { _x = p.x; _y = p.y; }