Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Asteroids/Asteroid.cpp
- Committer:
- RehamFaqehi
- Date:
- 2018-05-03
- Revision:
- 11:cb48d596aa3e
- Parent:
- 8:13cef7cb872e
- Child:
- 12:4d7f1349d796
File content as of revision 11:cb48d596aa3e:
#include "Asteroid.h"
Asteroid::Asteroid()
{
}
Asteroid::~Asteroid()
{
}
void Asteroid::init(float speed)
{
_size = 5;
_x = WIDTH - _size;
// srand(time(NULL));
_y1 = rand()%(HEIGHT); // random initial position on y-axis.
//_y1 =22;
_velocity.x = speed;
}
void Asteroid::draw(N5110 &lcd)
{
int sprite[6][11] = {
{ 0,0,1,1,0,1,0,0,1,1,0, },
{ 0,1,1,1,1,1,1,0,0,0,0, },
{ 1,1,0,1,1,1,0,1,0,0,0, },
{ 1,1,1,1,1,1,1,1,0,1,1, },
{ 0,1,1,1,0,1,1,0,0,0,0, },
{ 0,0,0,1,1,1,0,0,1,1,0, },
};
lcd.drawSprite(_x,_y1,6,11,(int *)sprite);
}
void Asteroid::update()
{
if(_x>0) {
_x -= _velocity.x;
} else {
_x = WIDTH - _size; //start from the begining again
_y1= rand()%(HEIGHT);
//_y1 =22;
}
}
Vector2D Asteroid::get_pos()
{
Vector2D p = {_x,_y1};
return p;
}