Rex Raj / Mbed 2 deprecated el17rrrs

Dependencies:   mbed Gamepad N5110 mbed-rtos

Committer:
RexRoshan
Date:
Mon May 06 18:29:49 2019 +0000
Revision:
5:016a7315b75d
Parent:
4:4d673fb2d9dc
Child:
6:1fcfd331c047
Commented almost every class

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 1:45493d1d0689 59
RexRoshan 5:016a7315b75d 60 srand(time(NULL));
RexRoshan 1:45493d1d0689 61 int direction = rand() % 8; // randomise initial direction.
RexRoshan 1:45493d1d0689 62
RexRoshan 4:4d673fb2d9dc 63 // 8 possibilities. Get random modulo and set movement accordingly
RexRoshan 1:45493d1d0689 64 if (direction == 0) {
RexRoshan 5:016a7315b75d 65 _movement.x = 0;
RexRoshan 5:016a7315b75d 66 _movement.y = -speed;
RexRoshan 1:45493d1d0689 67 } else if (direction == 1) {
RexRoshan 1:45493d1d0689 68 _movement.x = speed;
RexRoshan 1:45493d1d0689 69 _movement.y = -speed;
RexRoshan 1:45493d1d0689 70 } else if (direction == 2) {
RexRoshan 1:45493d1d0689 71 _movement.x = speed;
RexRoshan 5:016a7315b75d 72 _movement.y = 0;
RexRoshan 1:45493d1d0689 73 } else if (direction == 3) {
RexRoshan 1:45493d1d0689 74 _movement.x = speed;
RexRoshan 5:016a7315b75d 75 _movement.y = speed;
RexRoshan 1:45493d1d0689 76 } else if (direction == 4) {
RexRoshan 5:016a7315b75d 77 _movement.x = 0;
RexRoshan 5:016a7315b75d 78 _movement.y = speed;
RexRoshan 1:45493d1d0689 79 } else if (direction == 5) {
RexRoshan 5:016a7315b75d 80 _movement.x = -speed;
RexRoshan 1:45493d1d0689 81 _movement.y = speed;
RexRoshan 1:45493d1d0689 82 } else if (direction == 6) {
RexRoshan 1:45493d1d0689 83 _movement.x = -speed;
RexRoshan 5:016a7315b75d 84 _movement.y = 0;
RexRoshan 1:45493d1d0689 85 }else {
RexRoshan 1:45493d1d0689 86 _movement.x = -speed;
RexRoshan 1:45493d1d0689 87 _movement.y = -speed;
RexRoshan 1:45493d1d0689 88 }
RexRoshan 1:45493d1d0689 89 }
RexRoshan 1:45493d1d0689 90
RexRoshan 1:45493d1d0689 91 void EnemyBoss::enemyboss(N5110 &lcd)
RexRoshan 1:45493d1d0689 92 {
RexRoshan 1:45493d1d0689 93
RexRoshan 4:4d673fb2d9dc 94 // draws the boss enemy for stage 3
RexRoshan 1:45493d1d0689 95 lcd.drawSprite(_a,_b,13,13,(int *)boss);
RexRoshan 4:4d673fb2d9dc 96 // draws the first regular enemy for stage 3
RexRoshan 1:45493d1d0689 97 lcd.drawSprite(_c,_d,7,8,(int *)enemy2);
RexRoshan 4:4d673fb2d9dc 98 // draws the first regular enemy for stage 3
RexRoshan 1:45493d1d0689 99 lcd.drawSprite(_e,_f,7,8,(int *)enemy2);
RexRoshan 1:45493d1d0689 100
RexRoshan 1:45493d1d0689 101 }
RexRoshan 1:45493d1d0689 102
RexRoshan 1:45493d1d0689 103 void EnemyBoss::update()
RexRoshan 1:45493d1d0689 104 {
RexRoshan 4:4d673fb2d9dc 105 _a += _movement.x; // updates the x position for the boss enemy
RexRoshan 4:4d673fb2d9dc 106 _b += _movement.y; // updates the y position for the boss enemy
RexRoshan 4:4d673fb2d9dc 107
RexRoshan 4:4d673fb2d9dc 108 // the first and second regular enemy stay stationery
RexRoshan 1:45493d1d0689 109 }
RexRoshan 1:45493d1d0689 110
RexRoshan 1:45493d1d0689 111
RexRoshan 1:45493d1d0689 112 Vector2D EnemyBoss::get_movement()
RexRoshan 1:45493d1d0689 113 {
RexRoshan 4:4d673fb2d9dc 114 // gets the movement of the boss enemy
RexRoshan 1:45493d1d0689 115 Vector2D m = {_movement.x,_movement.y};
RexRoshan 1:45493d1d0689 116 return m;
RexRoshan 1:45493d1d0689 117 }
RexRoshan 1:45493d1d0689 118
RexRoshan 1:45493d1d0689 119 void EnemyBoss::set_movement(Vector2D m)
RexRoshan 1:45493d1d0689 120 {
RexRoshan 4:4d673fb2d9dc 121 // sets the movement of the boss enemy
RexRoshan 1:45493d1d0689 122 _movement.x = m.x;
RexRoshan 1:45493d1d0689 123 _movement.y = m.y;
RexRoshan 1:45493d1d0689 124 }
RexRoshan 1:45493d1d0689 125
RexRoshan 1:45493d1d0689 126 void EnemyBoss::add_health_boss()
RexRoshan 1:45493d1d0689 127 {
RexRoshan 4:4d673fb2d9dc 128 // increments the value of health by 1 for the boss enemy
RexRoshan 1:45493d1d0689 129 _health++;
RexRoshan 1:45493d1d0689 130 }
RexRoshan 1:45493d1d0689 131
RexRoshan 1:45493d1d0689 132 int EnemyBoss::get_health_boss()
RexRoshan 1:45493d1d0689 133 {
RexRoshan 4:4d673fb2d9dc 134 // gets the value of boss health
RexRoshan 1:45493d1d0689 135 return _health;
RexRoshan 1:45493d1d0689 136 }
RexRoshan 1:45493d1d0689 137
RexRoshan 1:45493d1d0689 138 void EnemyBoss::add_health_enemy1()
RexRoshan 1:45493d1d0689 139 {
RexRoshan 4:4d673fb2d9dc 140 // increments the value of health by 1 for the first regular enemy
RexRoshan 1:45493d1d0689 141 _health1++;
RexRoshan 1:45493d1d0689 142 }
RexRoshan 1:45493d1d0689 143
RexRoshan 1:45493d1d0689 144 int EnemyBoss::get_health_enemy1()
RexRoshan 1:45493d1d0689 145 {
RexRoshan 4:4d673fb2d9dc 146 // gets the value of first regular enemy health
RexRoshan 1:45493d1d0689 147 return _health1;
RexRoshan 1:45493d1d0689 148 }
RexRoshan 1:45493d1d0689 149
RexRoshan 1:45493d1d0689 150 void EnemyBoss::add_health_enemy2()
RexRoshan 1:45493d1d0689 151 {
RexRoshan 4:4d673fb2d9dc 152 // increments the value of health by 1 for the second regular enemy
RexRoshan 1:45493d1d0689 153 _health2++;
RexRoshan 1:45493d1d0689 154 }
RexRoshan 1:45493d1d0689 155
RexRoshan 1:45493d1d0689 156 int EnemyBoss::get_health_enemy2()
RexRoshan 1:45493d1d0689 157 {
RexRoshan 4:4d673fb2d9dc 158 // gets the value of second regular enemy health
RexRoshan 1:45493d1d0689 159 return _health2;
RexRoshan 1:45493d1d0689 160 }
RexRoshan 1:45493d1d0689 161
RexRoshan 4:4d673fb2d9dc 162 Vector2D EnemyBoss::get_enemyboss_pos()
RexRoshan 4:4d673fb2d9dc 163 {
RexRoshan 4:4d673fb2d9dc 164 //gets the position of the boss enemy for stage 3
RexRoshan 1:45493d1d0689 165 Vector2D e = {_a,_b};
RexRoshan 1:45493d1d0689 166 return e;
RexRoshan 1:45493d1d0689 167 }
RexRoshan 1:45493d1d0689 168
RexRoshan 4:4d673fb2d9dc 169 Vector2D EnemyBoss::get_enemy1_pos()
RexRoshan 4:4d673fb2d9dc 170 {
RexRoshan 4:4d673fb2d9dc 171 //gets the position of the first regular enemy for stage 3
RexRoshan 1:45493d1d0689 172 Vector2D d = {_c,_d};
RexRoshan 1:45493d1d0689 173 return d;
RexRoshan 1:45493d1d0689 174 }
RexRoshan 1:45493d1d0689 175
RexRoshan 4:4d673fb2d9dc 176 Vector2D EnemyBoss::get_enemy2_pos()
RexRoshan 4:4d673fb2d9dc 177 {
RexRoshan 4:4d673fb2d9dc 178 //gets the position of the second regular enemy for stage 3
RexRoshan 1:45493d1d0689 179 Vector2D c = {_e,_f};
RexRoshan 1:45493d1d0689 180 return c;
RexRoshan 1:45493d1d0689 181 }
RexRoshan 1:45493d1d0689 182
RexRoshan 1:45493d1d0689 183 void EnemyBoss::set_enemyboss_pos(Vector2D e)
RexRoshan 1:45493d1d0689 184 {
RexRoshan 4:4d673fb2d9dc 185 //sets the position of the boss enemy for stage 3
RexRoshan 1:45493d1d0689 186 _a = e.x;
RexRoshan 1:45493d1d0689 187 _b = e.y;
RexRoshan 1:45493d1d0689 188 }
RexRoshan 1:45493d1d0689 189
RexRoshan 1:45493d1d0689 190 void EnemyBoss::set_enemy1_pos(Vector2D d)
RexRoshan 1:45493d1d0689 191 {
RexRoshan 4:4d673fb2d9dc 192 //sets the position of the first regular enemy for stage 3
RexRoshan 1:45493d1d0689 193 _c = d.x;
RexRoshan 1:45493d1d0689 194 _d = d.y;
RexRoshan 1:45493d1d0689 195 }
RexRoshan 1:45493d1d0689 196
RexRoshan 1:45493d1d0689 197 void EnemyBoss::set_enemy2_pos(Vector2D c)
RexRoshan 1:45493d1d0689 198 {
RexRoshan 4:4d673fb2d9dc 199 //gets the position of the second regular enemy for stage 3
RexRoshan 1:45493d1d0689 200 _e = c.x;
RexRoshan 1:45493d1d0689 201 _f = c.y;
RexRoshan 1:45493d1d0689 202 }