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.
Dependencies: mbed
main.cpp
00001 /* 00002 Name: Spencer Tingle 00003 Username: el17set 00004 Student ID: 201147893 00005 Date: 09/05/19 00006 */ 00007 00008 #include "mbed.h" 00009 #include "Gamepad.h" 00010 #include "N5110.h" 00011 #include "Game.h" 00012 #include "Menu.h" 00013 #include "Coin.h" 00014 00015 // objects // 00016 Game game; 00017 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); 00018 Gamepad pad; 00019 00020 // prototypes // 00021 void init(); 00022 void render(); 00023 void startScreen(); 00024 bool gameWin(); 00025 00026 // functions // 00027 int main() 00028 { 00029 int fps = 30; // set frames per second 00030 lcd.setContrast(0.4); // set contrast 00031 lcd.setBrightness(1); // set brightness 00032 00033 init(); // initialises all initial variables 00034 startScreen(); // displays start screen until start pressed 00035 wait(1.0f/fps); // sets wait between next frame 00036 00037 // game loop // 00038 while (1) { 00039 game.UI(lcd, pad); // displays the menus 00040 game.init(); 00041 int health = game.get_health(); 00042 00043 // condition to allow for returning to // 00044 // main menu on win or loss // 00045 while (health > 0) { 00046 render(); 00047 wait(1.0f/fps); 00048 health = game.get_health(); 00049 } 00050 } 00051 } 00052 00053 // initialises gamepad and lcd // 00054 void init() 00055 { 00056 lcd.init(); 00057 pad.init(); 00058 } 00059 00060 // updates all sprites and updates all movements // 00061 // and conditional values every frame // 00062 void render() 00063 { 00064 lcd.clear(); 00065 game.direc(pad); 00066 game.drawSprite(lcd); 00067 game.movement(lcd, pad); 00068 game.collect(lcd, pad); 00069 game.win(lcd); 00070 game.damage(lcd, pad); 00071 game.death(lcd); 00072 game.display_health(lcd); 00073 lcd.refresh(); 00074 } 00075 00076 // start screen with 3 frames // 00077 void startScreen() 00078 { 00079 // until start pressed 3 frames will loop // 00080 while (pad.check_event(Gamepad::START_PRESSED) == false) { 00081 lcd.clear(); 00082 lcd.drawSprite(0,0,48,84,(int *)start_01); 00083 lcd.refresh(); 00084 wait(0.5); 00085 lcd.drawSprite(0,0,48,84,(int *)start_02); 00086 lcd.refresh(); 00087 wait(0.5); 00088 lcd.drawSprite(0,0,48,84,(int *)start_03); 00089 lcd.refresh(); 00090 wait(0.5); 00091 } 00092 }
Generated on Wed Jul 13 2022 21:10:10 by
