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