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 Apr 21 23:23:35 2019 +0000
Revision:
10:1a3499f6b583
Parent:
7:4aaa37a711a1
Child:
11:63e54f6e7939
Added entity_collision, Added start of Bullets,; ; Problems:; Headless can be inside player without detected by entity_collision if on the same y level

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17sm 0:8e92b66a0755 1 /*
el17sm 0:8e92b66a0755 2 ELEC2645 Embedded Systems Project
el17sm 0:8e92b66a0755 3 School of Electronic & Electrical Engineering
el17sm 0:8e92b66a0755 4 University of Leeds
el17sm 0:8e92b66a0755 5 Name: Steven Mahasin
el17sm 0:8e92b66a0755 6 Username: el17sm
el17sm 0:8e92b66a0755 7 Student ID Number: 201192939
el17sm 0:8e92b66a0755 8 Date: 11/04/2019
el17sm 1:1fa7ecca8dfb 9 */
el17sm 1:1fa7ecca8dfb 10
el17sm 7:4aaa37a711a1 11 #include "mbed.h"
el17sm 7:4aaa37a711a1 12 #include "Gamepad.h"
el17sm 7:4aaa37a711a1 13 #include "N5110.h"
el17sm 7:4aaa37a711a1 14 #include "math.h"
el17sm 7:4aaa37a711a1 15 #include "sprites.h"
el17sm 7:4aaa37a711a1 16 #include "Entity.h"
el17sm 7:4aaa37a711a1 17 #include "Player.h"
el17sm 10:1a3499f6b583 18 #include "Headless.h"
el17sm 7:4aaa37a711a1 19
el17sm 7:4aaa37a711a1 20 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
el17sm 7:4aaa37a711a1 21 Gamepad gamepad;
el17sm 7:4aaa37a711a1 22
el17sm 7:4aaa37a711a1 23 int counter = 0;
el17sm 1:1fa7ecca8dfb 24
el17sm 10:1a3499f6b583 25 bool entity_collision(Entity &a, Entity &b){
el17sm 10:1a3499f6b583 26 if (((b.get_pos_x() < a.get_pos_x()) && (a.get_pos_x() < b.get_pos_x() + b.get_hitbox_width())) ||
el17sm 10:1a3499f6b583 27 ((b.get_pos_x() < a.get_pos_x() + a.get_hitbox_width()) && (a.get_pos_x() + a.get_hitbox_width() < b.get_pos_x() + b.get_hitbox_width())))
el17sm 10:1a3499f6b583 28 {
el17sm 10:1a3499f6b583 29 if (((b.get_pos_y() < a.get_pos_y()) && (a.get_pos_y() < b.get_pos_y() + b.get_hitbox_height())) ||
el17sm 10:1a3499f6b583 30 ((b.get_pos_y() < a.get_pos_y() + a.get_hitbox_height()) && (a.get_pos_y() + a.get_hitbox_height() < b.get_pos_y() + b.get_hitbox_height())))
el17sm 10:1a3499f6b583 31 {
el17sm 10:1a3499f6b583 32 return true;
el17sm 10:1a3499f6b583 33 }
el17sm 10:1a3499f6b583 34 }
el17sm 10:1a3499f6b583 35 return false;
el17sm 10:1a3499f6b583 36 }
el17sm 10:1a3499f6b583 37
el17sm 1:1fa7ecca8dfb 38 int main()
el17sm 1:1fa7ecca8dfb 39 {
el17sm 1:1fa7ecca8dfb 40 lcd.init();
el17sm 2:dbfff27a8a94 41 lcd.setContrast(0.45);
el17sm 3:359a49bace1b 42 gamepad.init();
el17sm 2:dbfff27a8a94 43 while(1){
el17sm 10:1a3499f6b583 44 Player player(39, 27);
el17sm 10:1a3499f6b583 45 Headless headless(20, 20);
el17sm 10:1a3499f6b583 46 while(1){
el17sm 10:1a3499f6b583 47 // Player Movement
el17sm 10:1a3499f6b583 48 Vector2D mapped_coord = gamepad.get_mapped_coord();
el17sm 10:1a3499f6b583 49 player.move(mapped_coord.x, mapped_coord.y);
el17sm 10:1a3499f6b583 50 player.buttons(gamepad.check_event(Gamepad::A_PRESSED), gamepad.check_event(Gamepad::B_PRESSED), gamepad.check_event(Gamepad::Y_PRESSED), gamepad.check_event(Gamepad::X_PRESSED));
el17sm 10:1a3499f6b583 51
el17sm 10:1a3499f6b583 52 // Enemy Movement
el17sm 10:1a3499f6b583 53 headless.move(player.get_pos_x(), player.get_pos_y());
el17sm 10:1a3499f6b583 54
el17sm 10:1a3499f6b583 55 // Entity Collision Detection
el17sm 10:1a3499f6b583 56 // Damage action
el17sm 10:1a3499f6b583 57 if(entity_collision(player, headless)){
el17sm 10:1a3499f6b583 58 break;
el17sm 10:1a3499f6b583 59 }
el17sm 10:1a3499f6b583 60
el17sm 10:1a3499f6b583 61 // MiniMap Generation
el17sm 10:1a3499f6b583 62 // MiniMap Screen Detection
el17sm 10:1a3499f6b583 63
el17sm 10:1a3499f6b583 64 // Pause Detection
el17sm 10:1a3499f6b583 65 if(gamepad.check_event(Gamepad::START_PRESSED)){
el17sm 10:1a3499f6b583 66 lcd.clear();
el17sm 10:1a3499f6b583 67 lcd.printString("Paused", 0, 0);
el17sm 10:1a3499f6b583 68 lcd.refresh();
el17sm 10:1a3499f6b583 69 wait(0.05);
el17sm 10:1a3499f6b583 70 while(gamepad.check_event(Gamepad::START_PRESSED)){
el17sm 10:1a3499f6b583 71 };
el17sm 10:1a3499f6b583 72 wait(0.05);
el17sm 10:1a3499f6b583 73 while(!gamepad.check_event(Gamepad::START_PRESSED)){
el17sm 10:1a3499f6b583 74 };
el17sm 10:1a3499f6b583 75 wait(0.05);
el17sm 10:1a3499f6b583 76 while(gamepad.check_event(Gamepad::START_PRESSED)){
el17sm 10:1a3499f6b583 77 };
el17sm 10:1a3499f6b583 78 }
el17sm 10:1a3499f6b583 79
el17sm 10:1a3499f6b583 80
el17sm 10:1a3499f6b583 81 // screen update
el17sm 10:1a3499f6b583 82 lcd.clear();
el17sm 10:1a3499f6b583 83 lcd.drawSprite(0,0,screen_height,screen_width,(int *)level_map[1]);
el17sm 10:1a3499f6b583 84 lcd.drawSpriteTransparent(player.get_pos_x()-player.get_offset_x(),
el17sm 10:1a3499f6b583 85 player.get_pos_y()-player.get_offset_y(),
el17sm 10:1a3499f6b583 86 player.get_sprite_height(),
el17sm 10:1a3499f6b583 87 player.get_sprite_width(),
el17sm 10:1a3499f6b583 88 (int *)sprite_player[player.get_face()][(int)(player.get_moving()*(counter/5)%4)]);
el17sm 10:1a3499f6b583 89 lcd.drawSpriteTransparent(headless.get_pos_x()-headless.get_offset_x(),
el17sm 10:1a3499f6b583 90 headless.get_pos_y()-headless.get_offset_y(),
el17sm 10:1a3499f6b583 91 headless.get_sprite_height(),
el17sm 10:1a3499f6b583 92 headless.get_sprite_width(),
el17sm 10:1a3499f6b583 93 (int *)sprite_headless[headless.get_face()][(int)(headless.get_moving()*(counter/5)%4)]);
el17sm 10:1a3499f6b583 94 lcd.refresh();
el17sm 10:1a3499f6b583 95 wait_ms(1000/20);
el17sm 10:1a3499f6b583 96 counter++;
el17sm 10:1a3499f6b583 97
el17sm 10:1a3499f6b583 98 }
el17sm 3:359a49bace1b 99 lcd.clear();
el17sm 10:1a3499f6b583 100 lcd.printString("Game Over", 0, 0);
el17sm 10:1a3499f6b583 101 lcd.printString("Retry?", 0, 1);
el17sm 3:359a49bace1b 102 lcd.refresh();
el17sm 10:1a3499f6b583 103 player.~Player();
el17sm 10:1a3499f6b583 104 headless.~Headless();
el17sm 10:1a3499f6b583 105 wait(0.05);
el17sm 10:1a3499f6b583 106 while(!gamepad.check_event(Gamepad::A_PRESSED)){
el17sm 10:1a3499f6b583 107 };
el17sm 10:1a3499f6b583 108 wait(0.05);
el17sm 10:1a3499f6b583 109 while(gamepad.check_event(Gamepad::A_PRESSED)){
el17sm 10:1a3499f6b583 110 };
el17sm 10:1a3499f6b583 111 };
el17sm 10:1a3499f6b583 112 }