A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
main.cpp@4:d1aeb131e533, 2019-04-15 (annotated)
- Committer:
- el17sm
- Date:
- Mon Apr 15 02:28:55 2019 +0000
- Revision:
- 4:d1aeb131e533
- Parent:
- 3:359a49bace1b
- Child:
- 5:75b6cb06372a
Added drawSpriteTransparent onto N5110 to allow overlapping of sprite on map; ; Fixed Shifted player; ; Movement of Player and collision of Player to wall complete
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:359a49bace1b | 11 | #include "main.h" |
el17sm | 1:1fa7ecca8dfb | 12 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el17sm | 3:359a49bace1b | 13 | Gamepad gamepad; |
el17sm | 1:1fa7ecca8dfb | 14 | |
el17sm | 3:359a49bace1b | 15 | bool matrix_collision_test(int pos_x, int pos_y, int map_no, int width, int length){ |
el17sm | 1:1fa7ecca8dfb | 16 | for (int j = pos_y; j < pos_y+length; j++){ |
el17sm | 1:1fa7ecca8dfb | 17 | for(int i = pos_x; i < pos_x+width; i++){ |
el17sm | 1:1fa7ecca8dfb | 18 | if ((j>=48) || (i>=84) || (j<0) || (i<0)) { |
el17sm | 1:1fa7ecca8dfb | 19 | } |
el17sm | 3:359a49bace1b | 20 | else if ((level_map[0][j][i] == 1)) { |
el17sm | 3:359a49bace1b | 21 | return false; |
el17sm | 1:1fa7ecca8dfb | 22 | } |
el17sm | 1:1fa7ecca8dfb | 23 | } |
el17sm | 1:1fa7ecca8dfb | 24 | } |
el17sm | 3:359a49bace1b | 25 | return true; |
el17sm | 1:1fa7ecca8dfb | 26 | } |
el17sm | 1:1fa7ecca8dfb | 27 | |
el17sm | 1:1fa7ecca8dfb | 28 | int main() |
el17sm | 1:1fa7ecca8dfb | 29 | { |
el17sm | 1:1fa7ecca8dfb | 30 | lcd.init(); |
el17sm | 2:dbfff27a8a94 | 31 | lcd.setContrast(0.45); |
el17sm | 3:359a49bace1b | 32 | gamepad.init(); |
el17sm | 2:dbfff27a8a94 | 33 | |
el17sm | 3:359a49bace1b | 34 | float player_pos[2] = {39,27}; |
el17sm | 3:359a49bace1b | 35 | float future_player_pos[2] = {39,27}; |
el17sm | 3:359a49bace1b | 36 | int face = 2; |
el17sm | 3:359a49bace1b | 37 | int counter = 0; |
el17sm | 3:359a49bace1b | 38 | |
el17sm | 2:dbfff27a8a94 | 39 | while(1){ |
el17sm | 2:dbfff27a8a94 | 40 | |
el17sm | 3:359a49bace1b | 41 | Vector2D mapped_coord = gamepad.get_mapped_coord(); |
el17sm | 3:359a49bace1b | 42 | future_player_pos[0] = player_pos[0] + mapped_coord.x/2; |
el17sm | 3:359a49bace1b | 43 | future_player_pos[1] = player_pos[1] - mapped_coord.y/2; |
el17sm | 3:359a49bace1b | 44 | if(matrix_collision_test(future_player_pos[0], player_pos[1], 0, 6, 5)){ |
el17sm | 3:359a49bace1b | 45 | player_pos[0] = future_player_pos[0]; |
el17sm | 3:359a49bace1b | 46 | } |
el17sm | 3:359a49bace1b | 47 | if(matrix_collision_test(player_pos[0], future_player_pos[1], 0, 6, 5)){ |
el17sm | 3:359a49bace1b | 48 | player_pos[1] = future_player_pos[1]; |
el17sm | 3:359a49bace1b | 49 | } |
el17sm | 3:359a49bace1b | 50 | moving = false; |
el17sm | 3:359a49bace1b | 51 | if (abs(mapped_coord.x) + abs(mapped_coord.y) > 0.1f){ |
el17sm | 3:359a49bace1b | 52 | moving = true; |
el17sm | 3:359a49bace1b | 53 | if (mapped_coord.y < 0 && abs(mapped_coord.y) > abs(mapped_coord.x)){ |
el17sm | 3:359a49bace1b | 54 | face = 2; |
el17sm | 3:359a49bace1b | 55 | } |
el17sm | 3:359a49bace1b | 56 | else if (mapped_coord.y > 0 && abs(mapped_coord.y) > abs(mapped_coord.x)){ |
el17sm | 3:359a49bace1b | 57 | face = 0; |
el17sm | 3:359a49bace1b | 58 | } |
el17sm | 3:359a49bace1b | 59 | else if (mapped_coord.x > 0 && abs(mapped_coord.x) > abs(mapped_coord.y)){ |
el17sm | 3:359a49bace1b | 60 | face = 1; |
el17sm | 3:359a49bace1b | 61 | } |
el17sm | 3:359a49bace1b | 62 | else if (mapped_coord.x < 0 && abs(mapped_coord.x) > abs(mapped_coord.y)){ |
el17sm | 3:359a49bace1b | 63 | face = 3; |
el17sm | 3:359a49bace1b | 64 | } |
el17sm | 3:359a49bace1b | 65 | } |
el17sm | 3:359a49bace1b | 66 | |
el17sm | 3:359a49bace1b | 67 | lcd.clear(); |
el17sm | 3:359a49bace1b | 68 | lcd.drawSprite(0,0,48,84,(int *)level_map[1]); |
el17sm | 4:d1aeb131e533 | 69 | lcd.drawSpriteTransparent(player_pos[0],player_pos[1]-7,12,6,(int *)player[face][(int)(moving*(counter/10)%4)]); |
el17sm | 3:359a49bace1b | 70 | lcd.refresh(); |
el17sm | 3:359a49bace1b | 71 | wait_ms(1000/60); |
el17sm | 3:359a49bace1b | 72 | counter++; |
el17sm | 2:dbfff27a8a94 | 73 | |
el17sm | 2:dbfff27a8a94 | 74 | } |
el17sm | 2:dbfff27a8a94 | 75 | } |