A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Thu May 02 21:30:49 2019 +0000
Revision:
28:98848e6a77a2
Parent:
27:a1b41626f57c
Child:
29:6b8411bb040a
Entrance and Exit done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17sm 26:abbc19edc5c1 1 #include "RoomEngine.h"
el17sm 27:a1b41626f57c 2 RoomEngine::RoomEngine()
el17sm 26:abbc19edc5c1 3 {
el17sm 28:98848e6a77a2 4
el17sm 26:abbc19edc5c1 5 }
el17sm 26:abbc19edc5c1 6
el17sm 27:a1b41626f57c 7 RoomEngine::~RoomEngine()
el17sm 27:a1b41626f57c 8 {
el17sm 27:a1b41626f57c 9 delete player;
el17sm 27:a1b41626f57c 10 }
el17sm 27:a1b41626f57c 11
el17sm 28:98848e6a77a2 12 void RoomEngine::init(Player &current_player, Room &current_room)
el17sm 28:98848e6a77a2 13 {
el17sm 28:98848e6a77a2 14 player = &current_player;
el17sm 28:98848e6a77a2 15 room = &current_room;
el17sm 28:98848e6a77a2 16 set_input(0,0,0,0,0,0,0,0);
el17sm 28:98848e6a77a2 17 update_player_position(check_player_room_position());
el17sm 28:98848e6a77a2 18 }
el17sm 28:98848e6a77a2 19
el17sm 28:98848e6a77a2 20 void RoomEngine::save_room(Room &current_room)
el17sm 28:98848e6a77a2 21 {
el17sm 28:98848e6a77a2 22
el17sm 28:98848e6a77a2 23 }
el17sm 28:98848e6a77a2 24
el17sm 28:98848e6a77a2 25 void RoomEngine::entrance_scene(N5110 &lcd, Gamepad &gamepad)
el17sm 27:a1b41626f57c 26 {
el17sm 28:98848e6a77a2 27 int side = check_player_room_position();
el17sm 28:98848e6a77a2 28
el17sm 28:98848e6a77a2 29 for(int i = 0; i<50; i++) {
el17sm 28:98848e6a77a2 30 switch(side) {
el17sm 28:98848e6a77a2 31 case 0 :
el17sm 28:98848e6a77a2 32 set_mapped_coord(0, -((3 +player->get_sprite_height()) / (50 * player->get_velocity())));
el17sm 28:98848e6a77a2 33 break;
el17sm 28:98848e6a77a2 34 case 1 :
el17sm 28:98848e6a77a2 35 set_mapped_coord(-((3 +player->get_hitbox_width()) / (50 * player->get_velocity())), 0);
el17sm 28:98848e6a77a2 36 break;
el17sm 28:98848e6a77a2 37 case 2 :
el17sm 28:98848e6a77a2 38 set_mapped_coord(0, ((3 +player->get_hitbox_height()) / (50 * player->get_velocity())));
el17sm 28:98848e6a77a2 39 break;
el17sm 28:98848e6a77a2 40 case 3 :
el17sm 28:98848e6a77a2 41 set_mapped_coord(((3 +player->get_hitbox_width()) / (50 * player->get_velocity())), 0);
el17sm 28:98848e6a77a2 42 break;
el17sm 28:98848e6a77a2 43 }
el17sm 28:98848e6a77a2 44 move_player();
el17sm 28:98848e6a77a2 45 render(lcd, gamepad);
el17sm 28:98848e6a77a2 46 lcd.setContrast(0.75 - (i * 0.005));
el17sm 28:98848e6a77a2 47 }
el17sm 28:98848e6a77a2 48 }
el17sm 28:98848e6a77a2 49
el17sm 28:98848e6a77a2 50 void RoomEngine::exit_scene(N5110 &lcd, Gamepad &gamepad)
el17sm 28:98848e6a77a2 51 {
el17sm 28:98848e6a77a2 52 int side = check_player_room_position();
el17sm 28:98848e6a77a2 53
el17sm 28:98848e6a77a2 54 for(int i = 0; i<50; i++) {
el17sm 28:98848e6a77a2 55 switch(side) {
el17sm 28:98848e6a77a2 56 case 0 :
el17sm 28:98848e6a77a2 57 set_mapped_coord(0, (player->get_velocity() / 2));
el17sm 28:98848e6a77a2 58 break;
el17sm 28:98848e6a77a2 59 case 1 :
el17sm 28:98848e6a77a2 60 set_mapped_coord((player->get_velocity() / 2), 0);
el17sm 28:98848e6a77a2 61 break;
el17sm 28:98848e6a77a2 62 case 2 :
el17sm 28:98848e6a77a2 63 set_mapped_coord(0, -(player->get_velocity() / 2));
el17sm 28:98848e6a77a2 64 break;
el17sm 28:98848e6a77a2 65 case 3 :
el17sm 28:98848e6a77a2 66 set_mapped_coord(-(player->get_velocity() / 2), 0);
el17sm 28:98848e6a77a2 67 break;
el17sm 28:98848e6a77a2 68 }
el17sm 28:98848e6a77a2 69 move_player();
el17sm 28:98848e6a77a2 70 render(lcd, gamepad);
el17sm 28:98848e6a77a2 71 lcd.setContrast(0.5 + (i * 0.005));
el17sm 28:98848e6a77a2 72 }
el17sm 27:a1b41626f57c 73 }
el17sm 27:a1b41626f57c 74
el17sm 27:a1b41626f57c 75 void RoomEngine::read_input(Gamepad &gamepad)
el17sm 26:abbc19edc5c1 76 {
el17sm 26:abbc19edc5c1 77 _L = gamepad.check_event(Gamepad::L_PRESSED);
el17sm 26:abbc19edc5c1 78 _R = gamepad.check_event(Gamepad::R_PRESSED);
el17sm 26:abbc19edc5c1 79 _A = gamepad.check_event(Gamepad::A_PRESSED);
el17sm 26:abbc19edc5c1 80 _B = gamepad.check_event(Gamepad::B_PRESSED);
el17sm 26:abbc19edc5c1 81 _X = gamepad.check_event(Gamepad::X_PRESSED);
el17sm 26:abbc19edc5c1 82 _Y = gamepad.check_event(Gamepad::Y_PRESSED);
el17sm 26:abbc19edc5c1 83 mapped_coord = gamepad.get_mapped_coord();
el17sm 26:abbc19edc5c1 84 }
el17sm 26:abbc19edc5c1 85
el17sm 27:a1b41626f57c 86 void RoomEngine::update()
el17sm 26:abbc19edc5c1 87 {
el17sm 26:abbc19edc5c1 88 check_damage();
el17sm 27:a1b41626f57c 89 check_enemies_death();
el17sm 26:abbc19edc5c1 90 move();
el17sm 27:a1b41626f57c 91 player->buttons(_A, _B, _Y, _X);
el17sm 26:abbc19edc5c1 92 }
el17sm 26:abbc19edc5c1 93
el17sm 27:a1b41626f57c 94 void RoomEngine::render(N5110 &lcd, Gamepad &gamepad)
el17sm 27:a1b41626f57c 95 {
el17sm 27:a1b41626f57c 96 minimap_detection(lcd, gamepad);
el17sm 27:a1b41626f57c 97 pause_detection(lcd, gamepad);
el17sm 27:a1b41626f57c 98 lcd.clear();
el17sm 27:a1b41626f57c 99 draw(lcd);
el17sm 27:a1b41626f57c 100 lcd.refresh();
el17sm 27:a1b41626f57c 101 wait_ms(1000/40); // setting FPS
el17sm 27:a1b41626f57c 102 }
el17sm 27:a1b41626f57c 103
el17sm 27:a1b41626f57c 104 bool RoomEngine::check_player_death()
el17sm 27:a1b41626f57c 105 {
el17sm 27:a1b41626f57c 106 // Player Death
el17sm 27:a1b41626f57c 107 if (player->get_hp() <= 0) {
el17sm 27:a1b41626f57c 108 return true;
el17sm 27:a1b41626f57c 109 }
el17sm 27:a1b41626f57c 110 return false;
el17sm 26:abbc19edc5c1 111 }
el17sm 26:abbc19edc5c1 112
el17sm 28:98848e6a77a2 113 int RoomEngine::check_player_room_position() // returns 0,1,2,3 if the player exits the respective directions, returns 4 if the player is in the room
el17sm 28:98848e6a77a2 114 {
el17sm 28:98848e6a77a2 115 if (player->get_pos_y() < 0) {
el17sm 28:98848e6a77a2 116 return 0;
el17sm 28:98848e6a77a2 117 }
el17sm 28:98848e6a77a2 118 else if (player->get_pos_x() > WIDTH - (player->get_hitbox_width())) {
el17sm 28:98848e6a77a2 119 return 1;
el17sm 28:98848e6a77a2 120 }
el17sm 28:98848e6a77a2 121 else if (player->get_pos_y() > HEIGHT - (player->get_hitbox_height())) {
el17sm 28:98848e6a77a2 122 return 2;
el17sm 28:98848e6a77a2 123 }
el17sm 28:98848e6a77a2 124 else if (player->get_pos_x() < 0) {
el17sm 28:98848e6a77a2 125 return 3;
el17sm 28:98848e6a77a2 126 }
el17sm 28:98848e6a77a2 127 else {
el17sm 28:98848e6a77a2 128 return 4;
el17sm 28:98848e6a77a2 129 }
el17sm 28:98848e6a77a2 130 }
el17sm 28:98848e6a77a2 131
el17sm 28:98848e6a77a2 132 // Private Mutators
el17sm 28:98848e6a77a2 133
el17sm 28:98848e6a77a2 134 void RoomEngine::set_input(bool L, bool R, bool A, bool B, bool X, bool Y, float mapped_x, float mapped_y)
el17sm 28:98848e6a77a2 135 {
el17sm 28:98848e6a77a2 136 _L = L;
el17sm 28:98848e6a77a2 137 _R = R;
el17sm 28:98848e6a77a2 138 _A = A;
el17sm 28:98848e6a77a2 139 _B = B;
el17sm 28:98848e6a77a2 140 _X = X;
el17sm 28:98848e6a77a2 141 _Y = Y;
el17sm 28:98848e6a77a2 142 set_mapped_coord(mapped_x, mapped_y);
el17sm 28:98848e6a77a2 143 }
el17sm 28:98848e6a77a2 144
el17sm 28:98848e6a77a2 145 void RoomEngine::set_mapped_coord(float x, float y)
el17sm 28:98848e6a77a2 146 {
el17sm 28:98848e6a77a2 147 mapped_coord.x = x;
el17sm 28:98848e6a77a2 148 mapped_coord.y = y;
el17sm 28:98848e6a77a2 149 }
el17sm 28:98848e6a77a2 150
el17sm 26:abbc19edc5c1 151 // Private Functions
el17sm 26:abbc19edc5c1 152
el17sm 27:a1b41626f57c 153 bool RoomEngine::entity_collision(Entity &a, Entity &b) // returns true if the two entity hitboxes collide
el17sm 26:abbc19edc5c1 154 {
el17sm 26:abbc19edc5c1 155 if (((b.get_pos_x() <= a.get_pos_x()) && (a.get_pos_x() <= b.get_pos_x() + b.get_hitbox_width() - 1)) ||
el17sm 26:abbc19edc5c1 156 ((b.get_pos_x() <= a.get_pos_x() + a.get_hitbox_width() - 1) && (a.get_pos_x() + a.get_hitbox_width() - 1 <= b.get_pos_x() + b.get_hitbox_width() - 1))) {
el17sm 26:abbc19edc5c1 157 if (((b.get_pos_y() <= a.get_pos_y()) && (a.get_pos_y() <= b.get_pos_y() + b.get_hitbox_height() - 1)) ||
el17sm 26:abbc19edc5c1 158 ((b.get_pos_y() <= a.get_pos_y() + a.get_hitbox_height() - 1) && (a.get_pos_y() + a.get_hitbox_height() - 1 <= b.get_pos_y() + b.get_hitbox_height() - 1))) {
el17sm 26:abbc19edc5c1 159 return true;
el17sm 26:abbc19edc5c1 160 }
el17sm 26:abbc19edc5c1 161 }
el17sm 26:abbc19edc5c1 162 return 0;
el17sm 26:abbc19edc5c1 163 }
el17sm 26:abbc19edc5c1 164
el17sm 26:abbc19edc5c1 165 // returns true if the hitbox of "entity a" collides with any hitboxes of enttities within "array" as "entity a" moves on the x direction
el17sm 27:a1b41626f57c 166 float RoomEngine::entity_move_check_x(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[])
el17sm 26:abbc19edc5c1 167 {
el17sm 26:abbc19edc5c1 168 for (int i = 0; i < no_of_enemies; i++) {
el17sm 26:abbc19edc5c1 169 if (valid_enemies[i]) {
el17sm 26:abbc19edc5c1 170 if(i != current_entity) {
el17sm 26:abbc19edc5c1 171 if (((array[i]->get_prev_pos_x() <= a->get_pos_x()) && (a->get_pos_x() <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1)) ||
el17sm 26:abbc19edc5c1 172 ((array[i]->get_prev_pos_x() <= a->get_pos_x() + a->get_hitbox_width() - 1) && (a->get_pos_x() + a->get_hitbox_width() - 1 <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1))) {
el17sm 26:abbc19edc5c1 173 if (((array[i]->get_prev_pos_y() <= a->get_prev_pos_y()) && (a->get_prev_pos_y() <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1)) ||
el17sm 26:abbc19edc5c1 174 ((array[i]->get_prev_pos_y() <= a->get_prev_pos_y() + a->get_hitbox_height() - 1) && (a->get_prev_pos_y() + a->get_hitbox_height() - 1 <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1))) {
el17sm 26:abbc19edc5c1 175 return (2*((a->get_pos_x() > array[i]->get_prev_pos_x()) - 0.5));
el17sm 26:abbc19edc5c1 176 }
el17sm 26:abbc19edc5c1 177 }
el17sm 26:abbc19edc5c1 178 }
el17sm 26:abbc19edc5c1 179 }
el17sm 26:abbc19edc5c1 180 }
el17sm 26:abbc19edc5c1 181 return 0;
el17sm 26:abbc19edc5c1 182 }
el17sm 26:abbc19edc5c1 183
el17sm 26:abbc19edc5c1 184 // returns true if the hitbox of "entity a" collides with any hitboxes of enttities within "array" as "entity a" moves on the y direction
el17sm 27:a1b41626f57c 185 float RoomEngine::entity_move_check_y(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[])
el17sm 26:abbc19edc5c1 186 {
el17sm 26:abbc19edc5c1 187 for (int i = 0; i < no_of_enemies; i++) {
el17sm 26:abbc19edc5c1 188 if (valid_enemies[i]) {
el17sm 26:abbc19edc5c1 189 if(i != current_entity) {
el17sm 26:abbc19edc5c1 190 if (((array[i]->get_prev_pos_x() <= a->get_prev_pos_x()) && (a->get_prev_pos_x() <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1)) ||
el17sm 26:abbc19edc5c1 191 ((array[i]->get_prev_pos_x() <= a->get_prev_pos_x() + a->get_hitbox_width() - 1) && (a->get_prev_pos_x() + a->get_hitbox_width() - 1 <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1))) {
el17sm 26:abbc19edc5c1 192 if (((array[i]->get_prev_pos_y() <= a->get_pos_y()) && (a->get_pos_y() <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1)) ||
el17sm 26:abbc19edc5c1 193 ((array[i]->get_prev_pos_y() <= a->get_pos_y() + a->get_hitbox_height() - 1) && (a->get_pos_y() + a->get_hitbox_height() - 1 <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1))) {
el17sm 26:abbc19edc5c1 194 return (2*((a->get_pos_y() > array[i]->get_prev_pos_y()) - 0.5));
el17sm 26:abbc19edc5c1 195 }
el17sm 26:abbc19edc5c1 196 }
el17sm 26:abbc19edc5c1 197 }
el17sm 26:abbc19edc5c1 198 }
el17sm 26:abbc19edc5c1 199 }
el17sm 26:abbc19edc5c1 200 return 0;
el17sm 26:abbc19edc5c1 201 }
el17sm 26:abbc19edc5c1 202
el17sm 27:a1b41626f57c 203 void RoomEngine::check_damage()
el17sm 26:abbc19edc5c1 204 {
el17sm 26:abbc19edc5c1 205 check_damage_player();
el17sm 26:abbc19edc5c1 206 check_damage_enemies();
el17sm 26:abbc19edc5c1 207 }
el17sm 26:abbc19edc5c1 208
el17sm 27:a1b41626f57c 209 void RoomEngine::check_damage_player()
el17sm 26:abbc19edc5c1 210 {
el17sm 26:abbc19edc5c1 211 for (int i = 0; i < MAX_ENEMIES; i++) {
el17sm 27:a1b41626f57c 212 if (room->valid_enemies[i]) {
el17sm 27:a1b41626f57c 213 if(entity_collision(*player, *room->enemies[i])) {
el17sm 27:a1b41626f57c 214 player->take_damage(room->enemies[i]->get_attack());
el17sm 28:98848e6a77a2 215 break; // only let 1 enemy damage player at a time
el17sm 26:abbc19edc5c1 216 }
el17sm 26:abbc19edc5c1 217 }
el17sm 27:a1b41626f57c 218 }
el17sm 26:abbc19edc5c1 219 }
el17sm 26:abbc19edc5c1 220
el17sm 27:a1b41626f57c 221 void RoomEngine::check_damage_enemies()
el17sm 26:abbc19edc5c1 222 {
el17sm 28:98848e6a77a2 223 check_damage_enemies_by_bullets();
el17sm 28:98848e6a77a2 224 check_damage_enemies_by_collisions();
el17sm 28:98848e6a77a2 225 }
el17sm 28:98848e6a77a2 226
el17sm 28:98848e6a77a2 227 void RoomEngine::check_damage_enemies_by_bullets()
el17sm 28:98848e6a77a2 228 {
el17sm 26:abbc19edc5c1 229 for (int i = 0; i < bullets_max; i++) {
el17sm 27:a1b41626f57c 230 if (player->valid_bullets[i]) {
el17sm 27:a1b41626f57c 231 if (player->bullets_array[i]->out_of_bounds_check(room->get_current_map_2d())) {
el17sm 27:a1b41626f57c 232 player->valid_bullets[i] = false;
el17sm 27:a1b41626f57c 233 delete player->bullets_array[i];
el17sm 26:abbc19edc5c1 234 } else {
el17sm 26:abbc19edc5c1 235 for (int j = 0; j < MAX_ENEMIES; j++) {
el17sm 27:a1b41626f57c 236 if (room->valid_enemies[j] && (entity_collision(*player->bullets_array[i], *room->enemies[j]))) {
el17sm 27:a1b41626f57c 237 room->enemies[j]->take_damage(player->get_attack());
el17sm 27:a1b41626f57c 238 player->valid_bullets[i] = false;
el17sm 27:a1b41626f57c 239 delete player->bullets_array[i];
el17sm 26:abbc19edc5c1 240 break;
el17sm 26:abbc19edc5c1 241 }
el17sm 26:abbc19edc5c1 242 }
el17sm 26:abbc19edc5c1 243 }
el17sm 26:abbc19edc5c1 244 }
el17sm 26:abbc19edc5c1 245 }
el17sm 26:abbc19edc5c1 246 }
el17sm 26:abbc19edc5c1 247
el17sm 28:98848e6a77a2 248 void RoomEngine::check_damage_enemies_by_collisions()
el17sm 28:98848e6a77a2 249 {
el17sm 28:98848e6a77a2 250 for (int i = 0; i < MAX_ENEMIES; i++) {
el17sm 28:98848e6a77a2 251 if (room->valid_enemies[i]) {
el17sm 28:98848e6a77a2 252 if((room->enemies[i]->is_damaged_by_collision()) && (entity_collision(*player, *room->enemies[i]))) {
el17sm 28:98848e6a77a2 253 room->enemies[i]->take_damage(player->get_attack());
el17sm 28:98848e6a77a2 254 }
el17sm 28:98848e6a77a2 255 }
el17sm 28:98848e6a77a2 256 }
el17sm 28:98848e6a77a2 257 }
el17sm 28:98848e6a77a2 258
el17sm 27:a1b41626f57c 259 void RoomEngine::check_enemies_death()
el17sm 26:abbc19edc5c1 260 {
el17sm 26:abbc19edc5c1 261 // Enemy Death
el17sm 26:abbc19edc5c1 262 for (int i = 0; i < MAX_ENEMIES; i++) {
el17sm 27:a1b41626f57c 263 if (room->valid_enemies[i]) {
el17sm 27:a1b41626f57c 264 if(room->enemies[i]->get_hp() <= 0) {
el17sm 28:98848e6a77a2 265 float temp_pos_x = room->enemies[i]->get_pos_x();
el17sm 28:98848e6a77a2 266 float temp_pos_y = room->enemies[i]->get_pos_y();
el17sm 27:a1b41626f57c 267 delete room->enemies[i];
el17sm 28:98848e6a77a2 268 if ((rand() % 100) < room->enemies[i]->get_hp_drop_chance()){
el17sm 28:98848e6a77a2 269 room->enemies[i] = new Health(temp_pos_x, temp_pos_y);
el17sm 28:98848e6a77a2 270 } else {
el17sm 28:98848e6a77a2 271 room->valid_enemies[i] = false;
el17sm 28:98848e6a77a2 272 }
el17sm 26:abbc19edc5c1 273 }
el17sm 28:98848e6a77a2 274
el17sm 26:abbc19edc5c1 275 }
el17sm 26:abbc19edc5c1 276 }
el17sm 26:abbc19edc5c1 277 }
el17sm 26:abbc19edc5c1 278
el17sm 27:a1b41626f57c 279 void RoomEngine::move()
el17sm 26:abbc19edc5c1 280 {
el17sm 26:abbc19edc5c1 281 move_player();
el17sm 26:abbc19edc5c1 282 move_enemies();
el17sm 26:abbc19edc5c1 283 move_bullets();
el17sm 26:abbc19edc5c1 284 }
el17sm 26:abbc19edc5c1 285
el17sm 27:a1b41626f57c 286 void RoomEngine::move_player()
el17sm 26:abbc19edc5c1 287 {
el17sm 27:a1b41626f57c 288 player->move(mapped_coord.x, mapped_coord.y, room->get_current_map_2d());
el17sm 26:abbc19edc5c1 289 }
el17sm 26:abbc19edc5c1 290
el17sm 27:a1b41626f57c 291 void RoomEngine::move_enemies()
el17sm 26:abbc19edc5c1 292 {
el17sm 26:abbc19edc5c1 293 // Actual Movement of Enemies
el17sm 26:abbc19edc5c1 294 for (int i = 0; i < MAX_ENEMIES; i++) {
el17sm 27:a1b41626f57c 295 if (room->valid_enemies[i]) {
el17sm 27:a1b41626f57c 296 room->enemies[i]->update_prev_pos();
el17sm 27:a1b41626f57c 297 room->enemies[i]->move(player->get_pos_x(), player->get_pos_y(), room->get_current_map_2d());
el17sm 26:abbc19edc5c1 298 }
el17sm 27:a1b41626f57c 299 }
el17sm 26:abbc19edc5c1 300 // Entity Collision Repulsion
el17sm 26:abbc19edc5c1 301 for (int i = 0; i < MAX_ENEMIES; i++) {
el17sm 27:a1b41626f57c 302 if (room->valid_enemies[i]) {
el17sm 27:a1b41626f57c 303 room->enemies[i]->position_add_x(entity_move_check_x(room->enemies[i], room->enemies, MAX_ENEMIES, i, room->valid_enemies));
el17sm 27:a1b41626f57c 304 room->enemies[i]->position_add_y(entity_move_check_y(room->enemies[i], room->enemies, MAX_ENEMIES, i, room->valid_enemies));
el17sm 26:abbc19edc5c1 305 }
el17sm 27:a1b41626f57c 306 }
el17sm 27:a1b41626f57c 307 }
el17sm 27:a1b41626f57c 308
el17sm 27:a1b41626f57c 309 void RoomEngine::move_bullets()
el17sm 27:a1b41626f57c 310 {
el17sm 27:a1b41626f57c 311 for (int i = 0; i < bullets_max; i++) {
el17sm 27:a1b41626f57c 312 if (player->valid_bullets[i]) {
el17sm 27:a1b41626f57c 313 player->bullets_array[i]->move(player->get_bullet_speed(), 0, 0);
el17sm 27:a1b41626f57c 314 }
el17sm 27:a1b41626f57c 315 }
el17sm 27:a1b41626f57c 316 }
el17sm 27:a1b41626f57c 317
el17sm 28:98848e6a77a2 318 void RoomEngine::update_player_position(int side)
el17sm 28:98848e6a77a2 319 {
el17sm 28:98848e6a77a2 320 switch(side) {
el17sm 28:98848e6a77a2 321 case 0 :
el17sm 28:98848e6a77a2 322 player->set_position(39, 49);
el17sm 28:98848e6a77a2 323 break;
el17sm 28:98848e6a77a2 324 case 1 :
el17sm 28:98848e6a77a2 325 player->set_position(0 - player->get_hitbox_width(), 25);
el17sm 28:98848e6a77a2 326 break;
el17sm 28:98848e6a77a2 327 case 2 :
el17sm 28:98848e6a77a2 328 player->set_position(39, 0 - player->get_hitbox_height());
el17sm 28:98848e6a77a2 329 break;
el17sm 28:98848e6a77a2 330 case 3 :
el17sm 28:98848e6a77a2 331 player->set_position(85, 25);
el17sm 28:98848e6a77a2 332 break;
el17sm 28:98848e6a77a2 333 case 4 :
el17sm 28:98848e6a77a2 334 player->set_position(39, 27);
el17sm 28:98848e6a77a2 335 break;
el17sm 28:98848e6a77a2 336 }
el17sm 28:98848e6a77a2 337 }
el17sm 28:98848e6a77a2 338
el17sm 27:a1b41626f57c 339 void RoomEngine::minimap_detection(N5110 &lcd, Gamepad &gamepad)
el17sm 27:a1b41626f57c 340 {
el17sm 28:98848e6a77a2 341 while(gamepad.check_event(Gamepad::BACK_PRESSED)) {
el17sm 27:a1b41626f57c 342 lcd.clear();
el17sm 27:a1b41626f57c 343 lcd.refresh();
el17sm 27:a1b41626f57c 344 wait_ms(1000/40);
el17sm 26:abbc19edc5c1 345 };
el17sm 26:abbc19edc5c1 346 }
el17sm 26:abbc19edc5c1 347
el17sm 27:a1b41626f57c 348 void RoomEngine::pause_detection(N5110 &lcd, Gamepad &gamepad)
el17sm 26:abbc19edc5c1 349 {
el17sm 28:98848e6a77a2 350 if(gamepad.check_event(Gamepad::START_PRESSED)) {
el17sm 27:a1b41626f57c 351 draw_health(lcd);
el17sm 26:abbc19edc5c1 352 int * paused_screen = lcd.readScreen();
el17sm 26:abbc19edc5c1 353 int pause_timer = 2;
el17sm 26:abbc19edc5c1 354 lcd.drawSpriteTransparent(20, 20, 9, 45, (int *)pause_sprite);
el17sm 26:abbc19edc5c1 355 wait(0.05);
el17sm 28:98848e6a77a2 356 while(gamepad.check_event(Gamepad::START_PRESSED)) {
el17sm 26:abbc19edc5c1 357 lcd.clear();
el17sm 26:abbc19edc5c1 358 lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen);
el17sm 26:abbc19edc5c1 359 if (pause_timer % 10 <= 4) {
el17sm 26:abbc19edc5c1 360 lcd.drawSpriteTransparent(20, 20, 9, 45, (int *)pause_sprite);
el17sm 26:abbc19edc5c1 361 }
el17sm 26:abbc19edc5c1 362 lcd.refresh();
el17sm 26:abbc19edc5c1 363 pause_timer++;
el17sm 26:abbc19edc5c1 364 wait_ms(1000/40);
el17sm 27:a1b41626f57c 365 }
el17sm 26:abbc19edc5c1 366 wait(0.05);
el17sm 26:abbc19edc5c1 367 pause_timer += 2;
el17sm 28:98848e6a77a2 368 while(!gamepad.check_event(Gamepad::START_PRESSED)) {
el17sm 26:abbc19edc5c1 369 lcd.clear();
el17sm 26:abbc19edc5c1 370 lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen);
el17sm 26:abbc19edc5c1 371 if (pause_timer % 10 <= 4) {
el17sm 26:abbc19edc5c1 372 lcd.drawSpriteTransparent(20, 20, 9, 45, (int *)pause_sprite);
el17sm 26:abbc19edc5c1 373 }
el17sm 26:abbc19edc5c1 374 lcd.refresh();
el17sm 26:abbc19edc5c1 375 pause_timer++;
el17sm 26:abbc19edc5c1 376 wait_ms(1000/40);
el17sm 27:a1b41626f57c 377 }
el17sm 26:abbc19edc5c1 378 wait(0.05);
el17sm 26:abbc19edc5c1 379 pause_timer += 2;
el17sm 28:98848e6a77a2 380 while(gamepad.check_event(Gamepad::START_PRESSED)) {
el17sm 26:abbc19edc5c1 381 lcd.clear();
el17sm 26:abbc19edc5c1 382 lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen);
el17sm 26:abbc19edc5c1 383 if (pause_timer % 10 <= 4) {
el17sm 26:abbc19edc5c1 384 lcd.drawSpriteTransparent(20, 20, 9, 45, (int *)pause_sprite);
el17sm 26:abbc19edc5c1 385 }
el17sm 26:abbc19edc5c1 386 lcd.refresh();
el17sm 26:abbc19edc5c1 387 pause_timer++;
el17sm 26:abbc19edc5c1 388 wait_ms(1000/40);
el17sm 27:a1b41626f57c 389 }
el17sm 27:a1b41626f57c 390 }
el17sm 27:a1b41626f57c 391 }
el17sm 27:a1b41626f57c 392
el17sm 27:a1b41626f57c 393 void RoomEngine::draw(N5110 &lcd)
el17sm 27:a1b41626f57c 394 {
el17sm 27:a1b41626f57c 395 room->draw_room(lcd);
el17sm 27:a1b41626f57c 396 //lcd.drawSprite(0,0,screen_height,screen_width,(int *)level_map[1]);
el17sm 27:a1b41626f57c 397 draw_player(lcd);
el17sm 27:a1b41626f57c 398 draw_enemies(lcd);
el17sm 27:a1b41626f57c 399 draw_bullets(lcd);
el17sm 27:a1b41626f57c 400 if (_L) {
el17sm 27:a1b41626f57c 401 draw_health(lcd);
el17sm 26:abbc19edc5c1 402 }
el17sm 28:98848e6a77a2 403 room->draw_room_overlay(lcd);
el17sm 26:abbc19edc5c1 404 }
el17sm 26:abbc19edc5c1 405
el17sm 27:a1b41626f57c 406 void RoomEngine::draw_player(N5110 &lcd)
el17sm 26:abbc19edc5c1 407 {
el17sm 27:a1b41626f57c 408 lcd.drawSpriteTransparent(player->get_pos_x()-player->get_offset_x(),
el17sm 27:a1b41626f57c 409 player->get_pos_y()-player->get_offset_y(),
el17sm 27:a1b41626f57c 410 player->get_sprite_height(),
el17sm 27:a1b41626f57c 411 player->get_sprite_width(),
el17sm 27:a1b41626f57c 412 player->get_frame());
el17sm 26:abbc19edc5c1 413 }
el17sm 26:abbc19edc5c1 414
el17sm 27:a1b41626f57c 415 void RoomEngine::draw_enemies(N5110 &lcd)
el17sm 26:abbc19edc5c1 416 {
el17sm 26:abbc19edc5c1 417 for (int i = 0; i < MAX_ENEMIES; i++) {
el17sm 27:a1b41626f57c 418 if (room->valid_enemies[i]) {
el17sm 27:a1b41626f57c 419 lcd.drawSpriteTransparent(room->enemies[i]->get_pos_x()-room->enemies[i]->get_offset_x(),
el17sm 27:a1b41626f57c 420 room->enemies[i]->get_pos_y()-room->enemies[i]->get_offset_y(),
el17sm 27:a1b41626f57c 421 room->enemies[i]->get_sprite_height(),
el17sm 27:a1b41626f57c 422 room->enemies[i]->get_sprite_width(),
el17sm 27:a1b41626f57c 423 room->enemies[i]->get_frame());
el17sm 26:abbc19edc5c1 424 }
el17sm 27:a1b41626f57c 425 }
el17sm 26:abbc19edc5c1 426 }
el17sm 26:abbc19edc5c1 427
el17sm 27:a1b41626f57c 428 void RoomEngine::draw_bullets(N5110 &lcd)
el17sm 26:abbc19edc5c1 429 {
el17sm 26:abbc19edc5c1 430 for (int i = 0; i < bullets_max; i++) {
el17sm 27:a1b41626f57c 431 if (player->valid_bullets[i]) {
el17sm 27:a1b41626f57c 432 lcd.drawSpriteTransparent(player->bullets_array[i]->get_pos_x()-player->bullets_array[i]->get_offset_x(),
el17sm 27:a1b41626f57c 433 player->bullets_array[i]->get_pos_y()-player->bullets_array[i]->get_offset_y(),
el17sm 27:a1b41626f57c 434 player->bullets_array[i]->get_sprite_height(),
el17sm 27:a1b41626f57c 435 player->bullets_array[i]->get_sprite_width(),
el17sm 27:a1b41626f57c 436 player->bullets_array[i]->get_frame());
el17sm 26:abbc19edc5c1 437 }
el17sm 27:a1b41626f57c 438 }
el17sm 26:abbc19edc5c1 439 }
el17sm 26:abbc19edc5c1 440
el17sm 27:a1b41626f57c 441 void RoomEngine::draw_health(N5110 &lcd)
el17sm 26:abbc19edc5c1 442 {
el17sm 27:a1b41626f57c 443 for (int i = 0; i < player->get_hp(); i++){
el17sm 27:a1b41626f57c 444 lcd.drawSpriteTransparent(i*10,
el17sm 27:a1b41626f57c 445 0,
el17sm 27:a1b41626f57c 446 player->get_hearts_height(),
el17sm 27:a1b41626f57c 447 player->get_hearts_width(),
el17sm 27:a1b41626f57c 448 player->get_hearts_sprite());
el17sm 27:a1b41626f57c 449 }
el17sm 26:abbc19edc5c1 450 }