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@7:68e06dda79f7, 2019-04-17 (annotated)
- Committer:
- joshdavy
- Date:
- Wed Apr 17 12:39:46 2019 +0000
- Revision:
- 7:68e06dda79f7
- Parent:
- 6:2ca1516ec1e2
- Child:
- 8:21b6d4dbce44
Level Rendering Complete. Basic Collision Detection.;
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 | 5:b9cf407bcc63 | 21 | #include "Music.h" |
joshdavy | 5:b9cf407bcc63 | 22 | #include "SoundData.h" |
joshdavy | 1:37802772843e | 23 | |
joshdavy | 3:b34685dbdb8d | 24 | Timer processedTime; |
joshdavy | 1:37802772843e | 25 | |
joshdavy | 2:b62e8be35a5d | 26 | ////// Constants ////// |
joshdavy | 3:b34685dbdb8d | 27 | |
joshdavy | 2:b62e8be35a5d | 28 | |
joshdavy | 2:b62e8be35a5d | 29 | |
joshdavy | 2:b62e8be35a5d | 30 | |
joshdavy | 1:37802772843e | 31 | /////////////// objects /////////////// |
joshdavy | 1:37802772843e | 32 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
joshdavy | 1:37802772843e | 33 | Gamepad pad; |
joshdavy | 1:37802772843e | 34 | Game game; |
joshdavy | 7:68e06dda79f7 | 35 | Music play; |
joshdavy | 1:37802772843e | 36 | |
joshdavy | 1:37802772843e | 37 | |
joshdavy | 2:b62e8be35a5d | 38 | |
joshdavy | 1:37802772843e | 39 | ///////////// prototypes /////////////// |
joshdavy | 1:37802772843e | 40 | void init(); |
joshdavy | 1:37802772843e | 41 | void welcome(); |
joshdavy | 1:37802772843e | 42 | |
joshdavy | 1:37802772843e | 43 | // initialies all classes and libraries |
joshdavy | 1:37802772843e | 44 | void init() |
joshdavy | 2:b62e8be35a5d | 45 | |
joshdavy | 1:37802772843e | 46 | { |
joshdavy | 2:b62e8be35a5d | 47 | |
joshdavy | 1:37802772843e | 48 | // need to initialise LCD and Gamepad |
joshdavy | 1:37802772843e | 49 | lcd.init(); |
joshdavy | 2:b62e8be35a5d | 50 | lcd.setContrast(0.4); |
joshdavy | 1:37802772843e | 51 | pad.init(); |
joshdavy | 3:b34685dbdb8d | 52 | processedTime.reset(); |
joshdavy | 7:68e06dda79f7 | 53 | game.init(); |
joshdavy | 7:68e06dda79f7 | 54 | play.init(data1,NUM_ELEMENTS); |
joshdavy | 3:b34685dbdb8d | 55 | |
joshdavy | 1:37802772843e | 56 | |
joshdavy | 1:37802772843e | 57 | |
joshdavy | 1:37802772843e | 58 | } |
joshdavy | 1:37802772843e | 59 | // simple splash screen displayed on start-up |
joshdavy | 1:37802772843e | 60 | void welcome() { |
joshdavy | 1:37802772843e | 61 | |
joshdavy | 2:b62e8be35a5d | 62 | |
joshdavy | 2:b62e8be35a5d | 63 | lcd.printString(" WOo2 ",0,1); |
joshdavy | 1:37802772843e | 64 | lcd.printString(" Press Start ",0,4); |
joshdavy | 1:37802772843e | 65 | lcd.refresh(); |
joshdavy | 1:37802772843e | 66 | |
joshdavy | 1:37802772843e | 67 | // wait flashing LEDs until start button is pressed |
joshdavy | 1:37802772843e | 68 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
joshdavy | 1:37802772843e | 69 | pad.leds_on(); |
joshdavy | 1:37802772843e | 70 | wait(0.1); |
joshdavy | 1:37802772843e | 71 | pad.leds_off(); |
joshdavy | 1:37802772843e | 72 | wait(0.1); |
joshdavy | 2:b62e8be35a5d | 73 | printf("Welcome\n"); |
joshdavy | 1:37802772843e | 74 | } |
joshdavy | 2:b62e8be35a5d | 75 | |
joshdavy | 1:37802772843e | 76 | } |
joshdavy | 1:37802772843e | 77 | |
joshdavy | 5:b9cf407bcc63 | 78 | int tick = 0.000125; |
joshdavy | 5:b9cf407bcc63 | 79 | |
joshdavy | 1:37802772843e | 80 | int main() |
joshdavy | 1:37802772843e | 81 | { |
joshdavy | 3:b34685dbdb8d | 82 | |
joshdavy | 3:b34685dbdb8d | 83 | |
joshdavy | 1:37802772843e | 84 | init(); // initialise and then display welcome screen... |
joshdavy | 1:37802772843e | 85 | welcome(); // waiting for the user to start |
joshdavy | 2:b62e8be35a5d | 86 | lcd.clear(); |
joshdavy | 2:b62e8be35a5d | 87 | lcd.refresh(); |
joshdavy | 2:b62e8be35a5d | 88 | printf("MAIN\n"); |
joshdavy | 1:37802772843e | 89 | |
joshdavy | 1:37802772843e | 90 | |
joshdavy | 1:37802772843e | 91 | |
joshdavy | 1:37802772843e | 92 | // game loop - read input, update the game state and render the display |
joshdavy | 7:68e06dda79f7 | 93 | |
joshdavy | 7:68e06dda79f7 | 94 | game.init(); |
joshdavy | 1:37802772843e | 95 | while (1) { |
joshdavy | 3:b34685dbdb8d | 96 | processedTime.start(); |
joshdavy | 6:2ca1516ec1e2 | 97 | printf("TIME: %i\n",processedTime.read_ms()); |
joshdavy | 7:68e06dda79f7 | 98 | |
joshdavy | 7:68e06dda79f7 | 99 | |
joshdavy | 6:2ca1516ec1e2 | 100 | game.read_input(pad); |
joshdavy | 6:2ca1516ec1e2 | 101 | game.update(pad); |
joshdavy | 6:2ca1516ec1e2 | 102 | game.draw(lcd); |
joshdavy | 6:2ca1516ec1e2 | 103 | wait(0.1); |
joshdavy | 6:2ca1516ec1e2 | 104 | |
joshdavy | 6:2ca1516ec1e2 | 105 | |
joshdavy | 6:2ca1516ec1e2 | 106 | // if (processedTime.read_us() > 125) { |
joshdavy | 6:2ca1516ec1e2 | 107 | // player.play_next(); |
joshdavy | 6:2ca1516ec1e2 | 108 | // processedTime.reset(); |
joshdavy | 6:2ca1516ec1e2 | 109 | // } |
joshdavy | 2:b62e8be35a5d | 110 | |
joshdavy | 2:b62e8be35a5d | 111 | |
joshdavy | 1:37802772843e | 112 | |
joshdavy | 1:37802772843e | 113 | } |
joshdavy | 1:37802772843e | 114 | } |