A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
Diff: main.cpp
- Revision:
- 12:a1c1991835ca
- Parent:
- 11:63e54f6e7939
- Child:
- 13:d04a6caba40d
--- a/main.cpp Tue Apr 23 03:10:09 2019 +0000 +++ b/main.cpp Tue Apr 23 22:59:12 2019 +0000 @@ -22,7 +22,7 @@ int counter = 0; -bool entity_collision(Entity &a, Entity &b){ +bool entity_collision(Entity &a, Entity &b){ // returns true if the two entity hitboxes collide if (((b.get_pos_x() <= a.get_pos_x()) && (a.get_pos_x() <= b.get_pos_x() + b.get_hitbox_width() - 1)) || ((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))) { @@ -35,6 +35,7 @@ return false; } +// returns true if the hitbox of "entity a" collides with any hitboxes of enttities within "array" as "entity a" moves on the y direction bool entity_move_check_y(Entity *a, Entity *array[], int no_of_enemies, int current_entity){ for (int i = 0; i < no_of_enemies; i++){ if(i != current_entity){ @@ -45,13 +46,14 @@ ((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))) { return true; - } + } } } } return false; } +// returns true if the hitbox of "entity a" collides with any hitboxes of enttities within "array" as "entity a" moves on the x direction bool entity_move_check_x(Entity *a, Entity *array[], int no_of_enemies, int current_entity){ for (int i = 0; i < no_of_enemies; i++){ if(i != current_entity){ @@ -76,7 +78,7 @@ gamepad.init(); while(1){ Player player(39, 27); - const int no_of_enemies = 3; + int no_of_enemies = 3; Entity *enemies[no_of_enemies]; Headless enemy1(20, 20); Headless enemy2(20, 30); @@ -112,7 +114,6 @@ // Entity Collision Detection - // MiniMap Generation // MiniMap Screen Detection // Pause Detection @@ -139,16 +140,17 @@ pos_y-player.get_offset_y(), player.get_sprite_height(), player.get_sprite_width(), - (int *)sprite_player[player.get_face()][(int)(player.get_moving()*(counter/5)%4)]); + player.get_frame()); for (int i = 0; i < no_of_enemies; i++){ lcd.drawSpriteTransparent(enemies[i]->get_pos_x()-enemies[i]->get_offset_x(), enemies[i]->get_pos_y()-enemies[i]->get_offset_y(), enemies[i]->get_sprite_height(), enemies[i]->get_sprite_width(), - (int *)sprite_headless[enemies[i]->get_face()][(int)(enemies[i]->get_moving()*(counter/5)%4)]); + enemies[i]->get_frame()); }; + lcd.refresh(); - wait_ms(1000/20); + wait_ms(1000/20); // setting FPS counter++; }