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@3:b34685dbdb8d, 2019-04-02 (annotated)
- Committer:
- joshdavy
- Date:
- Tue Apr 02 12:40:31 2019 +0000
- Revision:
- 3:b34685dbdb8d
- Parent:
- 2:b62e8be35a5d
- Child:
- 5:b9cf407bcc63
Moved player to its own inherited class to allow sprite to serve multiple puporses
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joshdavy | 0:4916a63a6cbf | 1 | /* |
joshdavy | 0:4916a63a6cbf | 2 | ELEC2645 Embedded Systems Project |
joshdavy | 0:4916a63a6cbf | 3 | School of Electronic & Electrical Engineering |
joshdavy | 0:4916a63a6cbf | 4 | University of Leeds |
joshdavy | 0:4916a63a6cbf | 5 | Name: Joshua Davy |
joshdavy | 0:4916a63a6cbf | 6 | Username: el17jd |
joshdavy | 0:4916a63a6cbf | 7 | Student ID Number: 201148379 |
joshdavy | 0:4916a63a6cbf | 8 | Date: 12/03/2019 |
joshdavy | 1:37802772843e | 9 | */ |
joshdavy | 1:37802772843e | 10 | const int fps = 15; |
joshdavy | 1:37802772843e | 11 | |
joshdavy | 3:b34685dbdb8d | 12 | |
joshdavy | 2:b62e8be35a5d | 13 | |
joshdavy | 1:37802772843e | 14 | |
joshdavy | 1:37802772843e | 15 | ///////// pre-processor directives //////// |
joshdavy | 1:37802772843e | 16 | #include "mbed.h" |
joshdavy | 1:37802772843e | 17 | #include "Gamepad.h" |
joshdavy | 1:37802772843e | 18 | #include "N5110.h" |
joshdavy | 1:37802772843e | 19 | #include "Sprite.h" |
joshdavy | 1:37802772843e | 20 | #include "Game.h" |
joshdavy | 1:37802772843e | 21 | |
joshdavy | 3:b34685dbdb8d | 22 | Timer processedTime; |
joshdavy | 1:37802772843e | 23 | |
joshdavy | 2:b62e8be35a5d | 24 | ////// Constants ////// |
joshdavy | 3:b34685dbdb8d | 25 | |
joshdavy | 2:b62e8be35a5d | 26 | |
joshdavy | 2:b62e8be35a5d | 27 | |
joshdavy | 2:b62e8be35a5d | 28 | |
joshdavy | 1:37802772843e | 29 | /////////////// objects /////////////// |
joshdavy | 1:37802772843e | 30 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
joshdavy | 1:37802772843e | 31 | Gamepad pad; |
joshdavy | 1:37802772843e | 32 | Game game; |
joshdavy | 1:37802772843e | 33 | |
joshdavy | 1:37802772843e | 34 | |
joshdavy | 2:b62e8be35a5d | 35 | |
joshdavy | 1:37802772843e | 36 | ///////////// prototypes /////////////// |
joshdavy | 1:37802772843e | 37 | void init(); |
joshdavy | 1:37802772843e | 38 | void welcome(); |
joshdavy | 1:37802772843e | 39 | |
joshdavy | 1:37802772843e | 40 | // initialies all classes and libraries |
joshdavy | 1:37802772843e | 41 | void init() |
joshdavy | 2:b62e8be35a5d | 42 | |
joshdavy | 1:37802772843e | 43 | { |
joshdavy | 2:b62e8be35a5d | 44 | |
joshdavy | 1:37802772843e | 45 | // need to initialise LCD and Gamepad |
joshdavy | 1:37802772843e | 46 | lcd.init(); |
joshdavy | 2:b62e8be35a5d | 47 | lcd.setContrast(0.4); |
joshdavy | 1:37802772843e | 48 | pad.init(); |
joshdavy | 3:b34685dbdb8d | 49 | processedTime.reset(); |
joshdavy | 2:b62e8be35a5d | 50 | |
joshdavy | 3:b34685dbdb8d | 51 | |
joshdavy | 1:37802772843e | 52 | |
joshdavy | 1:37802772843e | 53 | |
joshdavy | 1:37802772843e | 54 | } |
joshdavy | 1:37802772843e | 55 | // simple splash screen displayed on start-up |
joshdavy | 1:37802772843e | 56 | void welcome() { |
joshdavy | 1:37802772843e | 57 | |
joshdavy | 2:b62e8be35a5d | 58 | |
joshdavy | 2:b62e8be35a5d | 59 | lcd.printString(" WOo2 ",0,1); |
joshdavy | 1:37802772843e | 60 | lcd.printString(" Press Start ",0,4); |
joshdavy | 1:37802772843e | 61 | lcd.refresh(); |
joshdavy | 1:37802772843e | 62 | |
joshdavy | 1:37802772843e | 63 | // wait flashing LEDs until start button is pressed |
joshdavy | 1:37802772843e | 64 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
joshdavy | 1:37802772843e | 65 | pad.leds_on(); |
joshdavy | 1:37802772843e | 66 | wait(0.1); |
joshdavy | 1:37802772843e | 67 | pad.leds_off(); |
joshdavy | 1:37802772843e | 68 | wait(0.1); |
joshdavy | 2:b62e8be35a5d | 69 | printf("Welcome\n"); |
joshdavy | 1:37802772843e | 70 | } |
joshdavy | 2:b62e8be35a5d | 71 | |
joshdavy | 1:37802772843e | 72 | } |
joshdavy | 1:37802772843e | 73 | |
joshdavy | 1:37802772843e | 74 | int main() |
joshdavy | 1:37802772843e | 75 | { |
joshdavy | 3:b34685dbdb8d | 76 | |
joshdavy | 3:b34685dbdb8d | 77 | |
joshdavy | 1:37802772843e | 78 | init(); // initialise and then display welcome screen... |
joshdavy | 1:37802772843e | 79 | welcome(); // waiting for the user to start |
joshdavy | 2:b62e8be35a5d | 80 | lcd.clear(); |
joshdavy | 2:b62e8be35a5d | 81 | lcd.refresh(); |
joshdavy | 2:b62e8be35a5d | 82 | printf("MAIN\n"); |
joshdavy | 1:37802772843e | 83 | |
joshdavy | 1:37802772843e | 84 | |
joshdavy | 1:37802772843e | 85 | |
joshdavy | 1:37802772843e | 86 | // game loop - read input, update the game state and render the display |
joshdavy | 1:37802772843e | 87 | while (1) { |
joshdavy | 3:b34685dbdb8d | 88 | processedTime.start(); |
joshdavy | 3:b34685dbdb8d | 89 | printf("TIME: %i\n",processedTime.read_ms()); |
joshdavy | 2:b62e8be35a5d | 90 | |
joshdavy | 1:37802772843e | 91 | game.read_input(pad); |
joshdavy | 1:37802772843e | 92 | game.update(pad); |
joshdavy | 1:37802772843e | 93 | game.draw(lcd); |
joshdavy | 2:b62e8be35a5d | 94 | wait(0.1); |
joshdavy | 2:b62e8be35a5d | 95 | |
joshdavy | 1:37802772843e | 96 | |
joshdavy | 1:37802772843e | 97 | } |
joshdavy | 1:37802772843e | 98 | } |