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:
Sun May 05 18:37:23 2019 +0000
Revision:
31:ab24d028ddfd
Parent:
30:ec915d24d3e9
Child:
32:fe6359ef9916
Rearranged main.cpp to be converted into a game_engine class

Who changed what in which revision?

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