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 Gamepad N5110 mbed-rtos
Diff: Enemy/Enemy.cpp
- Revision:
- 6:1fcfd331c047
- Parent:
- 4:4d673fb2d9dc
- Child:
- 7:574c66ebd8b0
--- a/Enemy/Enemy.cpp Mon May 06 18:29:49 2019 +0000
+++ b/Enemy/Enemy.cpp Wed May 08 10:03:24 2019 +0000
@@ -34,6 +34,28 @@
}
+void Enemy::location()
+{
+ int _speed = 5;
+ srand(time(NULL));
+ int direction = rand() % 4; // randomise initial direction.
+
+ // 4 possibilities. Get random modulo and set location accordingly
+ if (direction == 0) {
+ _a = _a;
+ _b += _speed;
+ } else if (direction == 1) {
+ _a = _a;
+ _b -= _speed;
+ } else if (direction == 2) {
+ _a -= _speed;
+ _b = _b;
+ } else {
+ _a += _speed;
+ _b = _b;
+ }
+}
+
void Enemy::enemy(N5110 &lcd)
{
@@ -44,7 +66,7 @@
void Enemy::update() // moves the position of the enemy when the enemy dies
{
- _speed = 2.0; // set at 2 so that it is not too fast
+ _fast = 2.0; // set at 2 so that it is not too fast
_b+=_speed; // moves the y-position downwards
@@ -66,4 +88,11 @@
//gets the position of the first enemy
Vector2D e = {_a,_b};
return e;
+}
+
+void Enemy::set_enemy_pos(Vector2D e)
+{
+ //sets the position of the first enemy of stage 2
+ _a = e.x;
+ _b = e.y;
}
\ No newline at end of file