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/Enemy22.cpp
- Revision:
- 0:d9cf94b41df3
diff -r 000000000000 -r d9cf94b41df3 Enemy/Enemy22.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Enemy/Enemy22.cpp Thu May 09 09:49:35 2019 +0000
@@ -0,0 +1,101 @@
+#include "Enemy22.h"
+
+// nothing doing in the constructor and destructor
+Enemy22::Enemy22()
+{
+
+}
+
+Enemy22::~Enemy22()
+{
+
+}
+
+// sprite of the second enemy for stage 2
+int enemy22 [7][7] ={
+
+{1,1,0,0,0,0,0},
+{1,1,0,0,0,0,0},
+{0,0,1,0,0,0,0},
+{0,0,0,1,0,0,0},
+{0,0,0,0,1,0,0},
+{0,0,0,0,0,1,1},
+{0,0,0,0,0,1,1},
+
+};
+
+void Enemy22::init(int a,int b,int speed)// initialising the x and y position of the enemy and movement speed of the enemy
+{
+
+ _a = a; // x position of the second enemy for stage 2
+ _b = b; // y position of the second enemy for stage 2
+
+ _health = 0; // start health from zero
+
+ int direction = rand() % 2; // randomise initial direction.
+
+ // 4 possibilities. Get random modulo and set movement accordingly
+ if (direction == 0) {
+ _movement.x = 0;
+ _movement.y = speed; // moves up
+ } else {
+ _movement.x = 0;
+ _movement.y = -speed; // moves down
+ }
+}
+
+void Enemy22::enemy2(N5110 &lcd)
+{
+
+ // draws the second-two enemy
+ lcd.drawSprite(_a,_b,7,7,(int *)enemy22);
+
+}
+
+void Enemy22::update()
+{
+ _a += _movement.x; // updates the x position
+ _b += _movement.y; // updates the y position
+
+}
+
+
+Vector2D Enemy22::get_movement()
+{
+ // gets the movement of the enemy
+ Vector2D m = {_movement.x,_movement.y};
+ return m;
+}
+
+void Enemy22::set_movement(Vector2D m)
+{
+ // sets the movement of the enemy
+ _movement.x = m.x;
+ _movement.y = m.y;
+}
+
+void Enemy22::add_health()
+{
+ // increments the value of health by 1
+ _health++;
+}
+
+int Enemy22::get_health()
+{
+ // gets the value of health
+ return _health;
+}
+
+Vector2D Enemy22::get_enemy22_pos()
+{
+ //gets the position of the second enemy for stage 2
+ Vector2D e = {_a,_b};
+ return e;
+}
+
+void Enemy22::set_enemy22_pos(Vector2D e)
+{
+ //sets the position of the second enemy for stage 2
+ _a = e.x;
+ _b = e.y;
+}