Final Submission. I have read and agreed with Statement of Academic Integrity.
Dependencies: mbed
main.cpp
- Committer:
- louisberard
- Date:
- 2020-05-29
- Revision:
- 1:86f96ceaf593
- Parent:
- 0:7423345f87c5
- Child:
- 2:586409836de7
File content as of revision 1:86f96ceaf593:
///////// pre-processor directives //////// #include "mbed.h" #include "Gamepad.h" #include "N5110.h" //Objects Gamepad pad; N5110 lcd; char player_char = 'x'; int player_xpos = 1; int player_ypos = 45; char array[84][48]; int move = 0; //Prototypes void pad_init(); void update_display(); void draw_array(); void player_object(); void Copy_array(); void player_movements(); void update_array(); void apply_move(); void array_init(); void add_surface_array(); void add_player_array(); void get_move(int); void print_screen(); //Main function int main() { pad_init(); array_init(); add_surface_array(); add_player_array(); print_screen(); update_display(); //Loop runs forever while(1){ get_move(move); apply_move(); add_player_array(); print_screen(); update_display(); } } void array_init(){ for(int j = 0; j < 47; j++){ for(int i = 0; i < 83; i++){ array[i][j] = '0'; }}} void apply_move(){ int old_player_xpos = player_xpos; player_xpos += move; array[old_player_xpos][player_ypos] = '0'; } void print_screen(){ for(int j = 0; j < 47; j++){ for(int i = 0; i < 83; i++){ if (array[i][j] == '0'){ lcd.setPixel(i,j,false); } else if(array[i][j] == '1'){ lcd.setPixel(i,j, true); } else if(array[i][j] == 'x'){ lcd.setPixel(i,j, true); } } }} //Prototype functions void pad_init(){ lcd.init(); lcd.setContrast(0.5); lcd.clear(); pad.init(); } void add_surface_array() { for(int i = 0; i < 84; i++){ array[i][46] = '1'; } } void add_player_array() { array[player_xpos][player_ypos] = player_char; } void get_move(int) { while(pad.A_pressed() == 0 && pad.B_pressed() == 0){ if(pad.A_pressed() == 1){ move = 1; } else if(pad.B_pressed() == 1){ move = -1; } } } void update_display() { lcd.refresh(); //Refreshes the lcd so the pixels appear wait_ms(200); //Frame rate of game }