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
alien/alien.cpp
- Committer:
- fy14lkaa
- Date:
- 2019-04-19
- Revision:
- 16:cba54d0696dc
- Parent:
- 15:ebbd903455f0
- Child:
- 17:9da9d0d41fca
File content as of revision 16:cba54d0696dc:
#include "alien.h"
alien::alien()
{
}
alien::~alien()
{
}
void alien::init(int size,int speed)
{
_size = size;
srand(time(NULL));
int direction = rand() % 8; // randomise initial direction.
// 4 possibilities. Get random modulo and set velocities accordingly
if (direction == 0) {
_velocity.x = speed;
_velocity.y = speed;
} else if (direction == 1) {
_velocity.x = speed;
_velocity.y = -speed;
} else if (direction == 2) {
_velocity.x = speed;
_velocity.y = speed;
} else {
_velocity.x = -speed;
_velocity.y = -speed;
}
}
void alien::draw(N5110 &lcd)
{
lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
}
void alien::update()
{
_x += _velocity.x;
_y += _velocity.y;
void alien::set_velocity(Vector2D v)
{
_velocity.x = v.x;
_velocity.y = v.y;
}
Vector2D alien::get_velocity()
{
Vector2D v = {_velocity.x,_velocity.y};
return v;
}