Rex Raj / Mbed 2 deprecated el17rrrs

Dependencies:   mbed Gamepad N5110 mbed-rtos

Committer:
RexRoshan
Date:
Wed May 08 10:03:24 2019 +0000
Revision:
6:1fcfd331c047
Parent:
5:016a7315b75d
Child:
7:574c66ebd8b0
Documentation has been completed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RexRoshan 1:45493d1d0689 1 #include "EnemyBoss.h"
RexRoshan 1:45493d1d0689 2
RexRoshan 1:45493d1d0689 3 // nothing doing in the constructor and destructor
RexRoshan 1:45493d1d0689 4 EnemyBoss::EnemyBoss()
RexRoshan 1:45493d1d0689 5 {
RexRoshan 1:45493d1d0689 6
RexRoshan 1:45493d1d0689 7 }
RexRoshan 1:45493d1d0689 8
RexRoshan 1:45493d1d0689 9 EnemyBoss::~EnemyBoss()
RexRoshan 1:45493d1d0689 10 {
RexRoshan 1:45493d1d0689 11
RexRoshan 1:45493d1d0689 12 }
RexRoshan 1:45493d1d0689 13
RexRoshan 4:4d673fb2d9dc 14 // sprite of the third-(one&two) enemy
RexRoshan 1:45493d1d0689 15 int enemy2 [7][8] = {
RexRoshan 1:45493d1d0689 16
RexRoshan 1:45493d1d0689 17 {0,1,1,0,0,0,0,1},
RexRoshan 1:45493d1d0689 18 {0,0,0,1,1,1,1,1},
RexRoshan 1:45493d1d0689 19 {0,0,1,0,0,1,1,0},
RexRoshan 1:45493d1d0689 20 {0,1,0,0,1,1,1,0},
RexRoshan 1:45493d1d0689 21 {0,0,1,0,0,1,1,0},
RexRoshan 1:45493d1d0689 22 {0,0,0,1,1,1,1,1},
RexRoshan 1:45493d1d0689 23 {0,1,1,0,0,0,0,1},
RexRoshan 1:45493d1d0689 24
RexRoshan 1:45493d1d0689 25 };
RexRoshan 1:45493d1d0689 26
RexRoshan 4:4d673fb2d9dc 27 // sprite of the third-boss enemy
RexRoshan 1:45493d1d0689 28 int boss [13][13] = {
RexRoshan 1:45493d1d0689 29
RexRoshan 1:45493d1d0689 30 {0,0,0,0,0,1,1,1,1,1,0,0,0},
RexRoshan 1:45493d1d0689 31 {0,0,0,0,0,0,1,1,1,0,0,0,0},
RexRoshan 1:45493d1d0689 32 {0,0,1,1,1,1,1,1,1,1,1,1,1},
RexRoshan 1:45493d1d0689 33 {0,0,0,0,0,1,0,1,0,0,1,0,0},
RexRoshan 1:45493d1d0689 34 {0,0,0,0,1,0,1,0,1,0,1,0,0},
RexRoshan 1:45493d1d0689 35 {0,0,0,1,0,0,0,1,0,1,1,0,0},
RexRoshan 1:45493d1d0689 36 {1,1,1,1,0,1,0,1,0,1,1,0,0},
RexRoshan 1:45493d1d0689 37 {0,0,0,1,0,0,0,1,0,1,1,0,0},
RexRoshan 1:45493d1d0689 38 {0,0,0,0,1,0,1,0,1,0,1,0,0},
RexRoshan 1:45493d1d0689 39 {0,0,0,0,0,1,0,1,0,0,1,0,0},
RexRoshan 1:45493d1d0689 40 {0,0,1,1,1,1,1,1,1,1,1,1,1},
RexRoshan 1:45493d1d0689 41 {0,0,0,0,0,0,1,1,1,0,0,0,0},
RexRoshan 1:45493d1d0689 42 {0,0,0,0,0,1,1,1,1,1,0,0,0},
RexRoshan 1:45493d1d0689 43
RexRoshan 1:45493d1d0689 44 };
RexRoshan 1:45493d1d0689 45
RexRoshan 4:4d673fb2d9dc 46 void EnemyBoss::init(int a,int b,int c,int d,int e,int f,int speed) // initialising the x and y position of the third enemy and movement speed of the third enemy
RexRoshan 1:45493d1d0689 47 {
RexRoshan 1:45493d1d0689 48
RexRoshan 4:4d673fb2d9dc 49 _a = a; // x position of the boss enemy for stage 3
RexRoshan 4:4d673fb2d9dc 50 _b = b; // y position of the boss enemy for stage 3
RexRoshan 4:4d673fb2d9dc 51 _c = c; // x position of the first regular enemy for stage 3
RexRoshan 4:4d673fb2d9dc 52 _d = d; // y position of the first regular enemy for stage 3
RexRoshan 4:4d673fb2d9dc 53 _e = e; // x position of the second regular enemy for stage 3
RexRoshan 4:4d673fb2d9dc 54 _f = f; // y position of the second regular enemy for stage 3
RexRoshan 1:45493d1d0689 55
RexRoshan 4:4d673fb2d9dc 56 _health = 0; // start health from zero for boss
RexRoshan 4:4d673fb2d9dc 57 _health1 = 0; // start health from zero for first enemy
RexRoshan 4:4d673fb2d9dc 58 _health2 = 0; // start health from zero for second enemy
RexRoshan 6:1fcfd331c047 59
RexRoshan 6:1fcfd331c047 60 _speed = speed;
RexRoshan 1:45493d1d0689 61
RexRoshan 6:1fcfd331c047 62 }
RexRoshan 6:1fcfd331c047 63
RexRoshan 6:1fcfd331c047 64 Vector2D EnemyBoss::motion()
RexRoshan 6:1fcfd331c047 65 {
RexRoshan 1:45493d1d0689 66 int direction = rand() % 8; // randomise initial direction.
RexRoshan 1:45493d1d0689 67
RexRoshan 4:4d673fb2d9dc 68 // 8 possibilities. Get random modulo and set movement accordingly
RexRoshan 1:45493d1d0689 69 if (direction == 0) {
RexRoshan 5:016a7315b75d 70 _movement.x = 0;
RexRoshan 6:1fcfd331c047 71 _movement.y = -_speed;
RexRoshan 1:45493d1d0689 72 } else if (direction == 1) {
RexRoshan 6:1fcfd331c047 73 _movement.x = _speed;
RexRoshan 6:1fcfd331c047 74 _movement.y = -_speed;
RexRoshan 1:45493d1d0689 75 } else if (direction == 2) {
RexRoshan 6:1fcfd331c047 76 _movement.x = _speed;
RexRoshan 5:016a7315b75d 77 _movement.y = 0;
RexRoshan 1:45493d1d0689 78 } else if (direction == 3) {
RexRoshan 6:1fcfd331c047 79 _movement.x = _speed;
RexRoshan 6:1fcfd331c047 80 _movement.y = _speed;
RexRoshan 1:45493d1d0689 81 } else if (direction == 4) {
RexRoshan 5:016a7315b75d 82 _movement.x = 0;
RexRoshan 6:1fcfd331c047 83 _movement.y = _speed;
RexRoshan 1:45493d1d0689 84 } else if (direction == 5) {
RexRoshan 6:1fcfd331c047 85 _movement.x = -_speed;
RexRoshan 6:1fcfd331c047 86 _movement.y = _speed;
RexRoshan 1:45493d1d0689 87 } else if (direction == 6) {
RexRoshan 6:1fcfd331c047 88 _movement.x = -_speed;
RexRoshan 5:016a7315b75d 89 _movement.y = 0;
RexRoshan 1:45493d1d0689 90 }else {
RexRoshan 6:1fcfd331c047 91 _movement.x = -_speed;
RexRoshan 6:1fcfd331c047 92 _movement.y = -_speed;
RexRoshan 6:1fcfd331c047 93 }
RexRoshan 6:1fcfd331c047 94 Vector2D velocity = {_movement.x, _movement.y};
RexRoshan 6:1fcfd331c047 95 return velocity;
RexRoshan 1:45493d1d0689 96 }
RexRoshan 6:1fcfd331c047 97
RexRoshan 1:45493d1d0689 98 void EnemyBoss::enemyboss(N5110 &lcd)
RexRoshan 1:45493d1d0689 99 {
RexRoshan 1:45493d1d0689 100
RexRoshan 4:4d673fb2d9dc 101 // draws the boss enemy for stage 3
RexRoshan 1:45493d1d0689 102 lcd.drawSprite(_a,_b,13,13,(int *)boss);
RexRoshan 4:4d673fb2d9dc 103 // draws the first regular enemy for stage 3
RexRoshan 1:45493d1d0689 104 lcd.drawSprite(_c,_d,7,8,(int *)enemy2);
RexRoshan 4:4d673fb2d9dc 105 // draws the first regular enemy for stage 3
RexRoshan 1:45493d1d0689 106 lcd.drawSprite(_e,_f,7,8,(int *)enemy2);
RexRoshan 1:45493d1d0689 107
RexRoshan 1:45493d1d0689 108 }
RexRoshan 1:45493d1d0689 109
RexRoshan 1:45493d1d0689 110 void EnemyBoss::update()
RexRoshan 1:45493d1d0689 111 {
RexRoshan 4:4d673fb2d9dc 112 _a += _movement.x; // updates the x position for the boss enemy
RexRoshan 4:4d673fb2d9dc 113 _b += _movement.y; // updates the y position for the boss enemy
RexRoshan 4:4d673fb2d9dc 114
RexRoshan 4:4d673fb2d9dc 115 // the first and second regular enemy stay stationery
RexRoshan 1:45493d1d0689 116 }
RexRoshan 1:45493d1d0689 117
RexRoshan 1:45493d1d0689 118
RexRoshan 1:45493d1d0689 119 Vector2D EnemyBoss::get_movement()
RexRoshan 1:45493d1d0689 120 {
RexRoshan 4:4d673fb2d9dc 121 // gets the movement of the boss enemy
RexRoshan 1:45493d1d0689 122 Vector2D m = {_movement.x,_movement.y};
RexRoshan 1:45493d1d0689 123 return m;
RexRoshan 1:45493d1d0689 124 }
RexRoshan 1:45493d1d0689 125
RexRoshan 1:45493d1d0689 126 void EnemyBoss::set_movement(Vector2D m)
RexRoshan 1:45493d1d0689 127 {
RexRoshan 4:4d673fb2d9dc 128 // sets the movement of the boss enemy
RexRoshan 1:45493d1d0689 129 _movement.x = m.x;
RexRoshan 1:45493d1d0689 130 _movement.y = m.y;
RexRoshan 1:45493d1d0689 131 }
RexRoshan 1:45493d1d0689 132
RexRoshan 1:45493d1d0689 133 void EnemyBoss::add_health_boss()
RexRoshan 1:45493d1d0689 134 {
RexRoshan 4:4d673fb2d9dc 135 // increments the value of health by 1 for the boss enemy
RexRoshan 1:45493d1d0689 136 _health++;
RexRoshan 1:45493d1d0689 137 }
RexRoshan 1:45493d1d0689 138
RexRoshan 1:45493d1d0689 139 int EnemyBoss::get_health_boss()
RexRoshan 1:45493d1d0689 140 {
RexRoshan 4:4d673fb2d9dc 141 // gets the value of boss health
RexRoshan 1:45493d1d0689 142 return _health;
RexRoshan 1:45493d1d0689 143 }
RexRoshan 1:45493d1d0689 144
RexRoshan 1:45493d1d0689 145 void EnemyBoss::add_health_enemy1()
RexRoshan 1:45493d1d0689 146 {
RexRoshan 4:4d673fb2d9dc 147 // increments the value of health by 1 for the first regular enemy
RexRoshan 1:45493d1d0689 148 _health1++;
RexRoshan 1:45493d1d0689 149 }
RexRoshan 1:45493d1d0689 150
RexRoshan 1:45493d1d0689 151 int EnemyBoss::get_health_enemy1()
RexRoshan 1:45493d1d0689 152 {
RexRoshan 4:4d673fb2d9dc 153 // gets the value of first regular enemy health
RexRoshan 1:45493d1d0689 154 return _health1;
RexRoshan 1:45493d1d0689 155 }
RexRoshan 1:45493d1d0689 156
RexRoshan 1:45493d1d0689 157 void EnemyBoss::add_health_enemy2()
RexRoshan 1:45493d1d0689 158 {
RexRoshan 4:4d673fb2d9dc 159 // increments the value of health by 1 for the second regular enemy
RexRoshan 1:45493d1d0689 160 _health2++;
RexRoshan 1:45493d1d0689 161 }
RexRoshan 1:45493d1d0689 162
RexRoshan 1:45493d1d0689 163 int EnemyBoss::get_health_enemy2()
RexRoshan 1:45493d1d0689 164 {
RexRoshan 4:4d673fb2d9dc 165 // gets the value of second regular enemy health
RexRoshan 1:45493d1d0689 166 return _health2;
RexRoshan 1:45493d1d0689 167 }
RexRoshan 1:45493d1d0689 168
RexRoshan 4:4d673fb2d9dc 169 Vector2D EnemyBoss::get_enemyboss_pos()
RexRoshan 4:4d673fb2d9dc 170 {
RexRoshan 4:4d673fb2d9dc 171 //gets the position of the boss enemy for stage 3
RexRoshan 1:45493d1d0689 172 Vector2D e = {_a,_b};
RexRoshan 1:45493d1d0689 173 return e;
RexRoshan 1:45493d1d0689 174 }
RexRoshan 1:45493d1d0689 175
RexRoshan 4:4d673fb2d9dc 176 Vector2D EnemyBoss::get_enemy1_pos()
RexRoshan 4:4d673fb2d9dc 177 {
RexRoshan 4:4d673fb2d9dc 178 //gets the position of the first regular enemy for stage 3
RexRoshan 1:45493d1d0689 179 Vector2D d = {_c,_d};
RexRoshan 1:45493d1d0689 180 return d;
RexRoshan 1:45493d1d0689 181 }
RexRoshan 1:45493d1d0689 182
RexRoshan 4:4d673fb2d9dc 183 Vector2D EnemyBoss::get_enemy2_pos()
RexRoshan 4:4d673fb2d9dc 184 {
RexRoshan 4:4d673fb2d9dc 185 //gets the position of the second regular enemy for stage 3
RexRoshan 1:45493d1d0689 186 Vector2D c = {_e,_f};
RexRoshan 1:45493d1d0689 187 return c;
RexRoshan 1:45493d1d0689 188 }
RexRoshan 1:45493d1d0689 189
RexRoshan 1:45493d1d0689 190 void EnemyBoss::set_enemyboss_pos(Vector2D e)
RexRoshan 1:45493d1d0689 191 {
RexRoshan 4:4d673fb2d9dc 192 //sets the position of the boss enemy for stage 3
RexRoshan 1:45493d1d0689 193 _a = e.x;
RexRoshan 1:45493d1d0689 194 _b = e.y;
RexRoshan 1:45493d1d0689 195 }
RexRoshan 1:45493d1d0689 196
RexRoshan 1:45493d1d0689 197 void EnemyBoss::set_enemy1_pos(Vector2D d)
RexRoshan 1:45493d1d0689 198 {
RexRoshan 4:4d673fb2d9dc 199 //sets the position of the first regular enemy for stage 3
RexRoshan 1:45493d1d0689 200 _c = d.x;
RexRoshan 1:45493d1d0689 201 _d = d.y;
RexRoshan 1:45493d1d0689 202 }
RexRoshan 1:45493d1d0689 203
RexRoshan 1:45493d1d0689 204 void EnemyBoss::set_enemy2_pos(Vector2D c)
RexRoshan 1:45493d1d0689 205 {
RexRoshan 4:4d673fb2d9dc 206 //gets the position of the second regular enemy for stage 3
RexRoshan 1:45493d1d0689 207 _e = c.x;
RexRoshan 1:45493d1d0689 208 _f = c.y;
RexRoshan 1:45493d1d0689 209 }