Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- Kern_EL17KJTF
- Date:
- 2019-05-07
- Revision:
- 11:b288d01533cc
- Parent:
- 10:28575a6eaa13
- Child:
- 12:50a7abf21f18
File content as of revision 11:b288d01533cc:
/* ELEC2645 Embedded Systems Project School of Electronic & Electrical Engineering University of Leeds Name: Kern Fowler Username: el17kjtf Student ID Number: 201116686 Date: 19/02/2019 Version: 1.2 */ #include "mbed.h" #include "N5110.h" #include "Gamepad.h" #include "Donkey.h" #include "Options.h" #include "Barrel.h" #include "Banana.h" #include "GameEngine.h" N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; Donkey dky; Barrel barrel; Banana banana; GameEngine eng; Options opt; void init(); void print_menu(); void welcome(); void arrow_location(); void arrow_select(); int fps = 24; int direction; int menu_option_pos = 0; int arrow_pos = 0; int menu_arrow[7][7] = { // Arrow pointer used in main menu {0,0,0,0,0,0,0,}, {0,0,0,0,1,0,0,}, {0,0,0,0,1,1,0,}, {1,1,1,1,1,1,1,}, {0,0,0,0,1,1,0,}, {0,0,0,0,1,0,0,}, {0,0,0,0,0,0,0,}, }; int menu_dk_face[36][34] = { // donkey kong face for menu { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,1,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,1,1,0,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0,0,0,0,0 }, { 0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 }, }; // Controls ------------------------- void controls_run(); // Instructions --------------------- void instructions_run(); // Options -------------------------- // High Scores----------------------- void high_scores_run(); // Main Menu -------------------------------------------------------------- int main() { init(); // initialise peripherals welcome(); // display welcome message while(1) { // infinite loop arrow_location(); print_menu(); // this re-prints the menu at the start of every loop arrow_select(); wait_ms(1.0f/fps); } } void init() { // initialise LCD lcd.init(); // initialise Gamepad pad.init(); wait(2.5); } void arrow_location() { direction = pad.get_direction(); if (direction == N) { menu_option_pos = menu_option_pos - 1; // printf("North Pressed"); wait_ms(250); } if (direction == S) { menu_option_pos = menu_option_pos + 1; // printf("South Pressed"); wait_ms(250); } if (menu_option_pos > 4) { menu_option_pos = 0; } if (menu_option_pos < 0) { menu_option_pos = 4; } arrow_pos = 8 + (menu_option_pos * 8); // printf("Option Num = %d", menu_option_pos) } void arrow_select() { if (pad.check_event(Gamepad::A_PRESSED) == true) { if (menu_option_pos == 0) { // printf("GameEngine"); eng.gameengine_run(pad, lcd, barrel, banana, dky); } if (menu_option_pos == 1) { // printf("Controls"); controls_run(); } if (menu_option_pos == 2) { // printf("Instructions"); instructions_run(); } if (menu_option_pos == 3) { // printf("Options"); opt.options_run(pad, lcd); } if (menu_option_pos == 4) { // printf("High Scores"); high_scores_run(); } } } void print_menu() { lcd.clear(); lcd.printString("Main Menu",19,0); lcd.printString("Start Game",8,1); lcd.printString("Controls",8,2); lcd.printString("Instructions",8,3); lcd.printString("Options",8,4); lcd.printString("High Scores",8,5); lcd.drawSprite(0,arrow_pos,7,7,(int *)menu_arrow); lcd.refresh(); } void welcome() { lcd.clear(); lcd.drawSprite(24,0,36,34,(int *)menu_dk_face); lcd.printString(" Donkey Kong",0,5); lcd.refresh(); wait(1.0); //edit back to longer lcd.clear(); lcd.printString(" Created",0,0); lcd.printString(" By",0,1); lcd.printString(" Kern Fowler",0,3); lcd.printString(" 201116686",0,4); lcd.refresh(); wait(1.0); } // Donkey ----------- // Barrel ----------- // Banana ----------- // Game State-------------------------------------------------------------- // Controls State---------------------------------------------------------- void controls_run() { wait_ms(250); while (pad.check_event(Gamepad::BACK_PRESSED) == false) { //printf("Control State"); lcd.clear(); lcd.printString("Controls",19,0); lcd.refresh(); wait_ms(1.0f/fps); } } // Instructions State------------------------------------------------------ void instructions_run() { wait_ms(250); while (pad.check_event(Gamepad::BACK_PRESSED) == false) { //printf("Instructions State"); lcd.clear(); lcd.printString("Instructions",7,0); lcd.refresh(); wait_ms(1.0f/fps); } } // Options State----------------------------------------------------------- // High Score State-------------------------------------------------------- void high_scores_run() { while (pad.check_event(Gamepad::BACK_PRESSED) == false) { //printf("High Score State"); lcd.clear(); lcd.printString("High Scores",12,0); lcd.refresh(); wait_ms(1.0f/fps); } }