A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
main.cpp
- Committer:
- el17sm
- Date:
- 2019-04-15
- Revision:
- 3:359a49bace1b
- Parent:
- 2:dbfff27a8a94
- Child:
- 4:d1aeb131e533
File content as of revision 3:359a49bace1b:
/* ELEC2645 Embedded Systems Project School of Electronic & Electrical Engineering University of Leeds Name: Steven Mahasin Username: el17sm Student ID Number: 201192939 Date: 11/04/2019 */ #include "main.h" N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad gamepad; bool matrix_collision_test(int pos_x, int pos_y, int map_no, int width, int length){ for (int j = pos_y; j < pos_y+length; j++){ for(int i = pos_x; i < pos_x+width; i++){ if ((j>=48) || (i>=84) || (j<0) || (i<0)) { } else if ((level_map[0][j][i] == 1)) { return false; } } } return true; } int main() { lcd.init(); lcd.setContrast(0.45); gamepad.init(); float player_pos[2] = {39,27}; float future_player_pos[2] = {39,27}; int face = 2; int counter = 0; while(1){ Vector2D mapped_coord = gamepad.get_mapped_coord(); future_player_pos[0] = player_pos[0] + mapped_coord.x/2; future_player_pos[1] = player_pos[1] - mapped_coord.y/2; if(matrix_collision_test(future_player_pos[0], player_pos[1], 0, 6, 5)){ player_pos[0] = future_player_pos[0]; } if(matrix_collision_test(player_pos[0], future_player_pos[1], 0, 6, 5)){ player_pos[1] = future_player_pos[1]; } moving = false; if (abs(mapped_coord.x) + abs(mapped_coord.y) > 0.1f){ moving = true; if (mapped_coord.y < 0 && abs(mapped_coord.y) > abs(mapped_coord.x)){ face = 2; } else if (mapped_coord.y > 0 && abs(mapped_coord.y) > abs(mapped_coord.x)){ face = 0; } else if (mapped_coord.x > 0 && abs(mapped_coord.x) > abs(mapped_coord.y)){ face = 1; } else if (mapped_coord.x < 0 && abs(mapped_coord.x) > abs(mapped_coord.y)){ face = 3; } } lcd.clear(); lcd.drawSprite(0,0,48,84,(int *)level_map[1]); lcd.drawSprite(player_pos[0],player_pos[1]-7,12,6,(int *)player[face][(int)(moving*(counter/10)%4)]); lcd.refresh(); wait_ms(1000/60); counter++; } }