A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
RoomEngine/RoomEngine.cpp@27:a1b41626f57c, 2019-04-29 (annotated)
- Committer:
- el17sm
- Date:
- Mon Apr 29 10:39:09 2019 +0000
- Revision:
- 27:a1b41626f57c
- Parent:
- 26:abbc19edc5c1
- Child:
- 28:98848e6a77a2
Functional Room; Great Success;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17sm | 26:abbc19edc5c1 | 1 | #include "RoomEngine.h" |
el17sm | 27:a1b41626f57c | 2 | RoomEngine::RoomEngine() |
el17sm | 26:abbc19edc5c1 | 3 | { |
el17sm | 27:a1b41626f57c | 4 | player = new Player(39, 27); |
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 | 27:a1b41626f57c | 12 | void RoomEngine::load_room(Room ¤t_room) |
el17sm | 27:a1b41626f57c | 13 | { |
el17sm | 27:a1b41626f57c | 14 | room = ¤t_room; |
el17sm | 27:a1b41626f57c | 15 | } |
el17sm | 27:a1b41626f57c | 16 | |
el17sm | 27:a1b41626f57c | 17 | void RoomEngine::read_input(Gamepad &gamepad) |
el17sm | 26:abbc19edc5c1 | 18 | { |
el17sm | 26:abbc19edc5c1 | 19 | _L = gamepad.check_event(Gamepad::L_PRESSED); |
el17sm | 26:abbc19edc5c1 | 20 | _R = gamepad.check_event(Gamepad::R_PRESSED); |
el17sm | 26:abbc19edc5c1 | 21 | _START = gamepad.check_event(Gamepad::START_PRESSED); |
el17sm | 26:abbc19edc5c1 | 22 | _BACK = gamepad.check_event(Gamepad::BACK_PRESSED); |
el17sm | 26:abbc19edc5c1 | 23 | _A = gamepad.check_event(Gamepad::A_PRESSED); |
el17sm | 26:abbc19edc5c1 | 24 | _B = gamepad.check_event(Gamepad::B_PRESSED); |
el17sm | 26:abbc19edc5c1 | 25 | _X = gamepad.check_event(Gamepad::X_PRESSED); |
el17sm | 26:abbc19edc5c1 | 26 | _Y = gamepad.check_event(Gamepad::Y_PRESSED); |
el17sm | 26:abbc19edc5c1 | 27 | mapped_coord = gamepad.get_mapped_coord(); |
el17sm | 26:abbc19edc5c1 | 28 | } |
el17sm | 26:abbc19edc5c1 | 29 | |
el17sm | 27:a1b41626f57c | 30 | void RoomEngine::update() |
el17sm | 26:abbc19edc5c1 | 31 | { |
el17sm | 26:abbc19edc5c1 | 32 | check_damage(); |
el17sm | 27:a1b41626f57c | 33 | check_enemies_death(); |
el17sm | 26:abbc19edc5c1 | 34 | move(); |
el17sm | 27:a1b41626f57c | 35 | player->buttons(_A, _B, _Y, _X); |
el17sm | 26:abbc19edc5c1 | 36 | } |
el17sm | 26:abbc19edc5c1 | 37 | |
el17sm | 27:a1b41626f57c | 38 | void RoomEngine::render(N5110 &lcd, Gamepad &gamepad) |
el17sm | 27:a1b41626f57c | 39 | { |
el17sm | 27:a1b41626f57c | 40 | minimap_detection(lcd, gamepad); |
el17sm | 27:a1b41626f57c | 41 | pause_detection(lcd, gamepad); |
el17sm | 27:a1b41626f57c | 42 | lcd.clear(); |
el17sm | 27:a1b41626f57c | 43 | draw(lcd); |
el17sm | 27:a1b41626f57c | 44 | lcd.refresh(); |
el17sm | 27:a1b41626f57c | 45 | wait_ms(1000/40); // setting FPS |
el17sm | 27:a1b41626f57c | 46 | } |
el17sm | 27:a1b41626f57c | 47 | |
el17sm | 27:a1b41626f57c | 48 | bool RoomEngine::check_player_death() |
el17sm | 27:a1b41626f57c | 49 | { |
el17sm | 27:a1b41626f57c | 50 | // Player Death |
el17sm | 27:a1b41626f57c | 51 | if (player->get_hp() <= 0) { |
el17sm | 27:a1b41626f57c | 52 | return true; |
el17sm | 27:a1b41626f57c | 53 | } |
el17sm | 27:a1b41626f57c | 54 | return false; |
el17sm | 26:abbc19edc5c1 | 55 | } |
el17sm | 26:abbc19edc5c1 | 56 | |
el17sm | 26:abbc19edc5c1 | 57 | // Private Functions |
el17sm | 26:abbc19edc5c1 | 58 | |
el17sm | 27:a1b41626f57c | 59 | bool RoomEngine::entity_collision(Entity &a, Entity &b) // returns true if the two entity hitboxes collide |
el17sm | 26:abbc19edc5c1 | 60 | { |
el17sm | 26:abbc19edc5c1 | 61 | 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 | 62 | ((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 | 63 | 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 | 64 | ((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 | 65 | return true; |
el17sm | 26:abbc19edc5c1 | 66 | } |
el17sm | 26:abbc19edc5c1 | 67 | } |
el17sm | 26:abbc19edc5c1 | 68 | return 0; |
el17sm | 26:abbc19edc5c1 | 69 | } |
el17sm | 26:abbc19edc5c1 | 70 | |
el17sm | 26:abbc19edc5c1 | 71 | // 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 | 72 | float RoomEngine::entity_move_check_x(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[]) |
el17sm | 26:abbc19edc5c1 | 73 | { |
el17sm | 26:abbc19edc5c1 | 74 | for (int i = 0; i < no_of_enemies; i++) { |
el17sm | 26:abbc19edc5c1 | 75 | if (valid_enemies[i]) { |
el17sm | 26:abbc19edc5c1 | 76 | if(i != current_entity) { |
el17sm | 26:abbc19edc5c1 | 77 | 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 | 78 | ((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 | 79 | 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 | 80 | ((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 | 81 | return (2*((a->get_pos_x() > array[i]->get_prev_pos_x()) - 0.5)); |
el17sm | 26:abbc19edc5c1 | 82 | } |
el17sm | 26:abbc19edc5c1 | 83 | } |
el17sm | 26:abbc19edc5c1 | 84 | } |
el17sm | 26:abbc19edc5c1 | 85 | } |
el17sm | 26:abbc19edc5c1 | 86 | } |
el17sm | 26:abbc19edc5c1 | 87 | return 0; |
el17sm | 26:abbc19edc5c1 | 88 | } |
el17sm | 26:abbc19edc5c1 | 89 | |
el17sm | 26:abbc19edc5c1 | 90 | // 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 | 91 | float RoomEngine::entity_move_check_y(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[]) |
el17sm | 26:abbc19edc5c1 | 92 | { |
el17sm | 26:abbc19edc5c1 | 93 | for (int i = 0; i < no_of_enemies; i++) { |
el17sm | 26:abbc19edc5c1 | 94 | if (valid_enemies[i]) { |
el17sm | 26:abbc19edc5c1 | 95 | if(i != current_entity) { |
el17sm | 26:abbc19edc5c1 | 96 | 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 | 97 | ((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 | 98 | 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 | 99 | ((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 | 100 | return (2*((a->get_pos_y() > array[i]->get_prev_pos_y()) - 0.5)); |
el17sm | 26:abbc19edc5c1 | 101 | } |
el17sm | 26:abbc19edc5c1 | 102 | } |
el17sm | 26:abbc19edc5c1 | 103 | } |
el17sm | 26:abbc19edc5c1 | 104 | } |
el17sm | 26:abbc19edc5c1 | 105 | } |
el17sm | 26:abbc19edc5c1 | 106 | return 0; |
el17sm | 26:abbc19edc5c1 | 107 | } |
el17sm | 26:abbc19edc5c1 | 108 | |
el17sm | 27:a1b41626f57c | 109 | void RoomEngine::check_damage() |
el17sm | 26:abbc19edc5c1 | 110 | { |
el17sm | 26:abbc19edc5c1 | 111 | check_damage_player(); |
el17sm | 26:abbc19edc5c1 | 112 | check_damage_enemies(); |
el17sm | 26:abbc19edc5c1 | 113 | } |
el17sm | 26:abbc19edc5c1 | 114 | |
el17sm | 27:a1b41626f57c | 115 | void RoomEngine::check_damage_player() |
el17sm | 26:abbc19edc5c1 | 116 | { |
el17sm | 26:abbc19edc5c1 | 117 | for (int i = 0; i < MAX_ENEMIES; i++) { |
el17sm | 27:a1b41626f57c | 118 | if (room->valid_enemies[i]) { |
el17sm | 27:a1b41626f57c | 119 | if(entity_collision(*player, *room->enemies[i])) { |
el17sm | 27:a1b41626f57c | 120 | player->take_damage(room->enemies[i]->get_attack()); |
el17sm | 26:abbc19edc5c1 | 121 | } |
el17sm | 26:abbc19edc5c1 | 122 | } |
el17sm | 27:a1b41626f57c | 123 | } |
el17sm | 26:abbc19edc5c1 | 124 | } |
el17sm | 26:abbc19edc5c1 | 125 | |
el17sm | 27:a1b41626f57c | 126 | void RoomEngine::check_damage_enemies() |
el17sm | 26:abbc19edc5c1 | 127 | { |
el17sm | 26:abbc19edc5c1 | 128 | for (int i = 0; i < bullets_max; i++) { |
el17sm | 27:a1b41626f57c | 129 | if (player->valid_bullets[i]) { |
el17sm | 27:a1b41626f57c | 130 | if (player->bullets_array[i]->out_of_bounds_check(room->get_current_map_2d())) { |
el17sm | 27:a1b41626f57c | 131 | player->valid_bullets[i] = false; |
el17sm | 27:a1b41626f57c | 132 | delete player->bullets_array[i]; |
el17sm | 26:abbc19edc5c1 | 133 | } else { |
el17sm | 26:abbc19edc5c1 | 134 | for (int j = 0; j < MAX_ENEMIES; j++) { |
el17sm | 27:a1b41626f57c | 135 | if (room->valid_enemies[j] && (entity_collision(*player->bullets_array[i], *room->enemies[j]))) { |
el17sm | 27:a1b41626f57c | 136 | room->enemies[j]->take_damage(player->get_attack()); |
el17sm | 27:a1b41626f57c | 137 | player->valid_bullets[i] = false; |
el17sm | 27:a1b41626f57c | 138 | delete player->bullets_array[i]; |
el17sm | 26:abbc19edc5c1 | 139 | break; |
el17sm | 26:abbc19edc5c1 | 140 | } |
el17sm | 26:abbc19edc5c1 | 141 | } |
el17sm | 26:abbc19edc5c1 | 142 | } |
el17sm | 26:abbc19edc5c1 | 143 | } |
el17sm | 26:abbc19edc5c1 | 144 | } |
el17sm | 26:abbc19edc5c1 | 145 | } |
el17sm | 26:abbc19edc5c1 | 146 | |
el17sm | 27:a1b41626f57c | 147 | void RoomEngine::check_enemies_death() |
el17sm | 26:abbc19edc5c1 | 148 | { |
el17sm | 26:abbc19edc5c1 | 149 | // Enemy Death |
el17sm | 26:abbc19edc5c1 | 150 | for (int i = 0; i < MAX_ENEMIES; i++) { |
el17sm | 27:a1b41626f57c | 151 | if (room->valid_enemies[i]) { |
el17sm | 27:a1b41626f57c | 152 | if(room->enemies[i]->get_hp() <= 0) { |
el17sm | 27:a1b41626f57c | 153 | room->valid_enemies[i] = false; |
el17sm | 27:a1b41626f57c | 154 | delete room->enemies[i]; |
el17sm | 26:abbc19edc5c1 | 155 | } |
el17sm | 26:abbc19edc5c1 | 156 | } |
el17sm | 26:abbc19edc5c1 | 157 | } |
el17sm | 26:abbc19edc5c1 | 158 | } |
el17sm | 26:abbc19edc5c1 | 159 | |
el17sm | 27:a1b41626f57c | 160 | void RoomEngine::move() |
el17sm | 26:abbc19edc5c1 | 161 | { |
el17sm | 26:abbc19edc5c1 | 162 | move_player(); |
el17sm | 26:abbc19edc5c1 | 163 | move_enemies(); |
el17sm | 26:abbc19edc5c1 | 164 | move_bullets(); |
el17sm | 26:abbc19edc5c1 | 165 | } |
el17sm | 26:abbc19edc5c1 | 166 | |
el17sm | 27:a1b41626f57c | 167 | void RoomEngine::move_player() |
el17sm | 26:abbc19edc5c1 | 168 | { |
el17sm | 27:a1b41626f57c | 169 | player->move(mapped_coord.x, mapped_coord.y, room->get_current_map_2d()); |
el17sm | 26:abbc19edc5c1 | 170 | } |
el17sm | 26:abbc19edc5c1 | 171 | |
el17sm | 27:a1b41626f57c | 172 | void RoomEngine::move_enemies() |
el17sm | 26:abbc19edc5c1 | 173 | { |
el17sm | 26:abbc19edc5c1 | 174 | // Actual Movement of Enemies |
el17sm | 26:abbc19edc5c1 | 175 | for (int i = 0; i < MAX_ENEMIES; i++) { |
el17sm | 27:a1b41626f57c | 176 | if (room->valid_enemies[i]) { |
el17sm | 27:a1b41626f57c | 177 | room->enemies[i]->update_prev_pos(); |
el17sm | 27:a1b41626f57c | 178 | room->enemies[i]->move(player->get_pos_x(), player->get_pos_y(), room->get_current_map_2d()); |
el17sm | 26:abbc19edc5c1 | 179 | } |
el17sm | 27:a1b41626f57c | 180 | } |
el17sm | 26:abbc19edc5c1 | 181 | // Entity Collision Repulsion |
el17sm | 26:abbc19edc5c1 | 182 | for (int i = 0; i < MAX_ENEMIES; i++) { |
el17sm | 27:a1b41626f57c | 183 | if (room->valid_enemies[i]) { |
el17sm | 27:a1b41626f57c | 184 | room->enemies[i]->position_add_x(entity_move_check_x(room->enemies[i], room->enemies, MAX_ENEMIES, i, room->valid_enemies)); |
el17sm | 27:a1b41626f57c | 185 | room->enemies[i]->position_add_y(entity_move_check_y(room->enemies[i], room->enemies, MAX_ENEMIES, i, room->valid_enemies)); |
el17sm | 26:abbc19edc5c1 | 186 | } |
el17sm | 27:a1b41626f57c | 187 | } |
el17sm | 27:a1b41626f57c | 188 | } |
el17sm | 27:a1b41626f57c | 189 | |
el17sm | 27:a1b41626f57c | 190 | void RoomEngine::move_bullets() |
el17sm | 27:a1b41626f57c | 191 | { |
el17sm | 27:a1b41626f57c | 192 | for (int i = 0; i < bullets_max; i++) { |
el17sm | 27:a1b41626f57c | 193 | if (player->valid_bullets[i]) { |
el17sm | 27:a1b41626f57c | 194 | player->bullets_array[i]->move(player->get_bullet_speed(), 0, 0); |
el17sm | 27:a1b41626f57c | 195 | } |
el17sm | 27:a1b41626f57c | 196 | } |
el17sm | 27:a1b41626f57c | 197 | } |
el17sm | 27:a1b41626f57c | 198 | |
el17sm | 27:a1b41626f57c | 199 | void RoomEngine::minimap_detection(N5110 &lcd, Gamepad &gamepad) |
el17sm | 27:a1b41626f57c | 200 | { |
el17sm | 27:a1b41626f57c | 201 | while(_BACK) { |
el17sm | 27:a1b41626f57c | 202 | _BACK = gamepad.check_event(Gamepad::BACK_PRESSED); |
el17sm | 27:a1b41626f57c | 203 | lcd.clear(); |
el17sm | 27:a1b41626f57c | 204 | lcd.refresh(); |
el17sm | 27:a1b41626f57c | 205 | wait_ms(1000/40); |
el17sm | 26:abbc19edc5c1 | 206 | }; |
el17sm | 26:abbc19edc5c1 | 207 | } |
el17sm | 26:abbc19edc5c1 | 208 | |
el17sm | 27:a1b41626f57c | 209 | void RoomEngine::pause_detection(N5110 &lcd, Gamepad &gamepad) |
el17sm | 26:abbc19edc5c1 | 210 | { |
el17sm | 26:abbc19edc5c1 | 211 | if(_START) { |
el17sm | 27:a1b41626f57c | 212 | draw_health(lcd); |
el17sm | 26:abbc19edc5c1 | 213 | int * paused_screen = lcd.readScreen(); |
el17sm | 26:abbc19edc5c1 | 214 | int pause_timer = 2; |
el17sm | 26:abbc19edc5c1 | 215 | lcd.drawSpriteTransparent(20, 20, 9, 45, (int *)pause_sprite); |
el17sm | 26:abbc19edc5c1 | 216 | wait(0.05); |
el17sm | 26:abbc19edc5c1 | 217 | while(_START) { |
el17sm | 27:a1b41626f57c | 218 | _START = gamepad.check_event(Gamepad::START_PRESSED); |
el17sm | 26:abbc19edc5c1 | 219 | lcd.clear(); |
el17sm | 26:abbc19edc5c1 | 220 | lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen); |
el17sm | 26:abbc19edc5c1 | 221 | if (pause_timer % 10 <= 4) { |
el17sm | 26:abbc19edc5c1 | 222 | lcd.drawSpriteTransparent(20, 20, 9, 45, (int *)pause_sprite); |
el17sm | 26:abbc19edc5c1 | 223 | } |
el17sm | 26:abbc19edc5c1 | 224 | lcd.refresh(); |
el17sm | 26:abbc19edc5c1 | 225 | pause_timer++; |
el17sm | 26:abbc19edc5c1 | 226 | wait_ms(1000/40); |
el17sm | 27:a1b41626f57c | 227 | } |
el17sm | 26:abbc19edc5c1 | 228 | wait(0.05); |
el17sm | 26:abbc19edc5c1 | 229 | pause_timer += 2; |
el17sm | 26:abbc19edc5c1 | 230 | while(!_START) { |
el17sm | 27:a1b41626f57c | 231 | _START = gamepad.check_event(Gamepad::START_PRESSED); |
el17sm | 26:abbc19edc5c1 | 232 | lcd.clear(); |
el17sm | 26:abbc19edc5c1 | 233 | lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen); |
el17sm | 26:abbc19edc5c1 | 234 | if (pause_timer % 10 <= 4) { |
el17sm | 26:abbc19edc5c1 | 235 | lcd.drawSpriteTransparent(20, 20, 9, 45, (int *)pause_sprite); |
el17sm | 26:abbc19edc5c1 | 236 | } |
el17sm | 26:abbc19edc5c1 | 237 | lcd.refresh(); |
el17sm | 26:abbc19edc5c1 | 238 | pause_timer++; |
el17sm | 26:abbc19edc5c1 | 239 | wait_ms(1000/40); |
el17sm | 27:a1b41626f57c | 240 | } |
el17sm | 26:abbc19edc5c1 | 241 | wait(0.05); |
el17sm | 26:abbc19edc5c1 | 242 | pause_timer += 2; |
el17sm | 26:abbc19edc5c1 | 243 | while(_START) { |
el17sm | 27:a1b41626f57c | 244 | _START = gamepad.check_event(Gamepad::START_PRESSED); |
el17sm | 26:abbc19edc5c1 | 245 | lcd.clear(); |
el17sm | 26:abbc19edc5c1 | 246 | lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen); |
el17sm | 26:abbc19edc5c1 | 247 | if (pause_timer % 10 <= 4) { |
el17sm | 26:abbc19edc5c1 | 248 | lcd.drawSpriteTransparent(20, 20, 9, 45, (int *)pause_sprite); |
el17sm | 26:abbc19edc5c1 | 249 | } |
el17sm | 26:abbc19edc5c1 | 250 | lcd.refresh(); |
el17sm | 26:abbc19edc5c1 | 251 | pause_timer++; |
el17sm | 26:abbc19edc5c1 | 252 | wait_ms(1000/40); |
el17sm | 27:a1b41626f57c | 253 | } |
el17sm | 27:a1b41626f57c | 254 | } |
el17sm | 27:a1b41626f57c | 255 | } |
el17sm | 27:a1b41626f57c | 256 | |
el17sm | 27:a1b41626f57c | 257 | void RoomEngine::draw(N5110 &lcd) |
el17sm | 27:a1b41626f57c | 258 | { |
el17sm | 27:a1b41626f57c | 259 | room->draw_room(lcd); |
el17sm | 27:a1b41626f57c | 260 | //lcd.drawSprite(0,0,screen_height,screen_width,(int *)level_map[1]); |
el17sm | 27:a1b41626f57c | 261 | draw_player(lcd); |
el17sm | 27:a1b41626f57c | 262 | draw_enemies(lcd); |
el17sm | 27:a1b41626f57c | 263 | draw_bullets(lcd); |
el17sm | 27:a1b41626f57c | 264 | if (_L) { |
el17sm | 27:a1b41626f57c | 265 | draw_health(lcd); |
el17sm | 26:abbc19edc5c1 | 266 | } |
el17sm | 26:abbc19edc5c1 | 267 | } |
el17sm | 26:abbc19edc5c1 | 268 | |
el17sm | 27:a1b41626f57c | 269 | void RoomEngine::draw_player(N5110 &lcd) |
el17sm | 26:abbc19edc5c1 | 270 | { |
el17sm | 27:a1b41626f57c | 271 | lcd.drawSpriteTransparent(player->get_pos_x()-player->get_offset_x(), |
el17sm | 27:a1b41626f57c | 272 | player->get_pos_y()-player->get_offset_y(), |
el17sm | 27:a1b41626f57c | 273 | player->get_sprite_height(), |
el17sm | 27:a1b41626f57c | 274 | player->get_sprite_width(), |
el17sm | 27:a1b41626f57c | 275 | player->get_frame()); |
el17sm | 26:abbc19edc5c1 | 276 | } |
el17sm | 26:abbc19edc5c1 | 277 | |
el17sm | 27:a1b41626f57c | 278 | void RoomEngine::draw_enemies(N5110 &lcd) |
el17sm | 26:abbc19edc5c1 | 279 | { |
el17sm | 26:abbc19edc5c1 | 280 | for (int i = 0; i < MAX_ENEMIES; i++) { |
el17sm | 27:a1b41626f57c | 281 | if (room->valid_enemies[i]) { |
el17sm | 27:a1b41626f57c | 282 | lcd.drawSpriteTransparent(room->enemies[i]->get_pos_x()-room->enemies[i]->get_offset_x(), |
el17sm | 27:a1b41626f57c | 283 | room->enemies[i]->get_pos_y()-room->enemies[i]->get_offset_y(), |
el17sm | 27:a1b41626f57c | 284 | room->enemies[i]->get_sprite_height(), |
el17sm | 27:a1b41626f57c | 285 | room->enemies[i]->get_sprite_width(), |
el17sm | 27:a1b41626f57c | 286 | room->enemies[i]->get_frame()); |
el17sm | 26:abbc19edc5c1 | 287 | } |
el17sm | 27:a1b41626f57c | 288 | } |
el17sm | 26:abbc19edc5c1 | 289 | } |
el17sm | 26:abbc19edc5c1 | 290 | |
el17sm | 27:a1b41626f57c | 291 | void RoomEngine::draw_bullets(N5110 &lcd) |
el17sm | 26:abbc19edc5c1 | 292 | { |
el17sm | 26:abbc19edc5c1 | 293 | for (int i = 0; i < bullets_max; i++) { |
el17sm | 27:a1b41626f57c | 294 | if (player->valid_bullets[i]) { |
el17sm | 27:a1b41626f57c | 295 | lcd.drawSpriteTransparent(player->bullets_array[i]->get_pos_x()-player->bullets_array[i]->get_offset_x(), |
el17sm | 27:a1b41626f57c | 296 | player->bullets_array[i]->get_pos_y()-player->bullets_array[i]->get_offset_y(), |
el17sm | 27:a1b41626f57c | 297 | player->bullets_array[i]->get_sprite_height(), |
el17sm | 27:a1b41626f57c | 298 | player->bullets_array[i]->get_sprite_width(), |
el17sm | 27:a1b41626f57c | 299 | player->bullets_array[i]->get_frame()); |
el17sm | 26:abbc19edc5c1 | 300 | } |
el17sm | 27:a1b41626f57c | 301 | } |
el17sm | 26:abbc19edc5c1 | 302 | } |
el17sm | 26:abbc19edc5c1 | 303 | |
el17sm | 27:a1b41626f57c | 304 | void RoomEngine::draw_health(N5110 &lcd) |
el17sm | 26:abbc19edc5c1 | 305 | { |
el17sm | 27:a1b41626f57c | 306 | for (int i = 0; i < player->get_hp(); i++){ |
el17sm | 27:a1b41626f57c | 307 | lcd.drawSpriteTransparent(i*10, |
el17sm | 27:a1b41626f57c | 308 | 0, |
el17sm | 27:a1b41626f57c | 309 | player->get_hearts_height(), |
el17sm | 27:a1b41626f57c | 310 | player->get_hearts_width(), |
el17sm | 27:a1b41626f57c | 311 | player->get_hearts_sprite()); |
el17sm | 27:a1b41626f57c | 312 | } |
el17sm | 26:abbc19edc5c1 | 313 | } |