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
Diff: main.cpp
- Revision:
- 45:bad704c546d4
- Parent:
- 44:e29458976114
- Child:
- 48:bd1f31fbfee3
--- a/main.cpp Wed Apr 17 19:57:33 2019 +0000 +++ b/main.cpp Wed Apr 24 13:17:58 2019 +0000 @@ -8,46 +8,86 @@ Date: 18/03/19 */ +///////// pre-processor directives //////// #include "mbed.h" #include "N5110.h" #include "Gamepad.h" #include "Gameengine.h" +/////////////// objects /////////////// + Gameengine game; Gamepad pad; N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); AnalogIn pot0(PTB2); - BusOut oxygen(PTA1, PTA2, PTC2); BusOut lives(PTC3, PTC4, PTD3); +///////////// prototypes /////////////// + +/** + * @brief sets the contrast of lcd screen + * @details contrast is adjust with analog input PTB2 + */ void contrast(); +/** + * @brief initialises all classes and libraries and default game settings + * @details initialises LCD and gamepad library and sets screen brightness + */ void init(); +/** + * @brief Displays opening screen + * @details Screen displays title of game and instructs player to press start to begin + */ void start_screen(); +/** + * @brief Controls LEDs on front panel + * @details Every time a player dies a RHS LED is turned off, as time reduces + * LEDs turn off on LHS + */ void leds(); +/** + * @brief initialises and renders all level objects + * @details Contains functions for all levels and will display next level objects + * once player has completed each level + */ void render(); +/** + * @brief Displays screen if game over or game complete + * @details Screen will display player's final score and display game over or + * game complete + */ void restart(); -void button_a(); + +///////////// functions //////////////// + +/** Level Class +@author Andrew Milner University of Leeds +@brief Sets position of all level objects +@date April 2019 + +@code int main() { - init(); - start_screen(); - - + init(); // initialises screen and default game settings + start_screen(); // waits for user to press start to begin + + // game loop, reads input and updates game accordingly while (1) { - contrast(); - render(); - game.update(lcd, pad); - restart(); - wait(0.1); + contrast(); // adjusts contrast of screen + render(); // draws all level objects on to screen + game.update(lcd, pad); // updates movement, collected keys, lives, time left + restart(); // restart screen if game over or end screen if game complete displays final score + wait(0.1); // wait function to control fps + } +} +@endcode +*/ - } - -} - +//initialises all classes and libraries and default game settings void init() { lcd.init(); @@ -55,19 +95,20 @@ lcd.refresh(); lcd.setBrightness(1.0); pad.init(); - pad.leds_off(); - contrast(); game.game_init(); + contrast(); } +// detects which level is being played and draws the level objects with collision settings void render() { - game.draw_l1(lcd, pad); - game.draw_l2(lcd, pad); - game.draw_l3(lcd, pad); - leds(); + game.draw_l1(lcd, pad); // level 1 + game.draw_l2(lcd, pad); // level 2 + game.draw_l3(lcd, pad); // level 3 + leds(); // function to update leds to reflect time and lives left } +// controls contrast of the screen void contrast() { lcd.refresh(); @@ -76,39 +117,50 @@ lcd.clear(); } +// displays start screen and waits for user to press start void start_screen() -{ - lcd.printString("*MANIC MILNER*",0,1); - lcd.printString(" Press start! ",0,4); +{ + lcd.drawSprite(2,20,8,3,(int *)miner_right); + lcd.drawSprite(79,20,8,3,(int *)miner_left); + lcd.drawRect(0,0,84,48, FILL_TRANSPARENT); + lcd.printString("MANIC MILNER",7,1); + lcd.printString("Press start!",8,4); lcd.refresh(); while ( pad.check_event(Gamepad::START_PRESSED) == false) { } } +// displays appropriate screen with final score for game over and game complete void restart() { if (game.game_over() == true) { lcd.clear(); game.get_score(lcd); - lcd.printString("Game Over! ",12,0); - lcd.printString("Score ",4,2); - lcd.printString("Press reset to try again! ",0,4); - lcd.printString("try again! ",16,5); + lcd.drawRect(0,0,84,48, FILL_TRANSPARENT); + lcd.printString("Game Over! ",14,1); + lcd.printString("Score ",18,2); + lcd.printString("Play Again?",10,4); } if (game.game_complete(lcd) == true) { lcd.clear(); game.get_score(lcd); - lcd.printString("YOU WIN!!! ",12,0); - lcd.printString("Score ",4,2); - lcd.printString("Well done!!!",12,4); + lcd.drawRect(0,0,84,48, FILL_TRANSPARENT); + lcd.printString("YOU WIN!!! ",12,1); + lcd.printString("Score ",18,2); + lcd.printString("Well done!!!",8,4); } } +// leds indicate how many lives and time left void leds() -{ +{ + // fsm to display lives left int l_leds[4] = {0b111,0b110,0b100,0b000}; + //fsm to display how much time (oxygen) left int r_leds[4] = {0b111,0b110,0b100,0b000}; - + + // function keeps track of time elapsed and changes leds accordingly oxygen = l_leds[game.oxygen_leds()]; + // function keeps track of lives left and changes leds accordingly lives = r_leds[game.lives_leds()]; } \ No newline at end of file