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
Diff: alien/alien.cpp
- Revision:
- 11:df8ce6637022
- Parent:
- 10:13e6996223d5
- Child:
- 13:9d6ee753eca6
diff -r 13e6996223d5 -r df8ce6637022 alien/alien.cpp
--- a/alien/alien.cpp Sun Apr 14 16:59:28 2019 +0000
+++ b/alien/alien.cpp Mon Apr 15 12:04:25 2019 +0000
@@ -14,4 +14,34 @@
void alien::init(int size,int speed)
{
- _size = size;
\ No newline at end of file
+ _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;
+ }
+}
+
+
+
+