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 09 01:57:49 2019 +0000
Revision:
47:6e31b195ce3c
Parent:
46:f09711580d4a
Child:
49:3f83ed62d123
Full Game Complete;; Added scoring system;; ; To do: ; Commenting and Doxygen;; Shortening of a few functions;

Who changed what in which revision?

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