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-15
- Revision:
- 11:df8ce6637022
- Parent:
- 10:13e6996223d5
- Child:
- 13:9d6ee753eca6
File content as of revision 11:df8ce6637022:
#include "alien.h"
alien::alien()
{
}
alien::~alien()
{
}
void alien::init(int size,int speed)
{
_size = size;
/*
_x = WIDTH/2 - _size/2;
_y = HEIGHT/2 - _size/2;
*/
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;
}
}