Josh Davy / Mbed OS Flip_OS_5

Dependencies:   el17jd

Committer:
joshdavy
Date:
Wed Apr 10 11:03:07 2019 +0000
Revision:
6:2ca1516ec1e2
Parent:
5:b9cf407bcc63
Child:
7:68e06dda79f7
Began implementing "levels" which store the blocks/enemies of each stage

Who changed what in which revision?

UserRevisionLine numberNew 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 5:b9cf407bcc63 35 Music player;
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 2:b62e8be35a5d 53
joshdavy 5:b9cf407bcc63 54
joshdavy 5:b9cf407bcc63 55 player.init(data1,NUM_ELEMENTS);
joshdavy 3:b34685dbdb8d 56
joshdavy 1:37802772843e 57
joshdavy 1:37802772843e 58
joshdavy 1:37802772843e 59 }
joshdavy 1:37802772843e 60 // simple splash screen displayed on start-up
joshdavy 1:37802772843e 61 void welcome() {
joshdavy 1:37802772843e 62
joshdavy 2:b62e8be35a5d 63
joshdavy 2:b62e8be35a5d 64 lcd.printString(" WOo2 ",0,1);
joshdavy 1:37802772843e 65 lcd.printString(" Press Start ",0,4);
joshdavy 1:37802772843e 66 lcd.refresh();
joshdavy 1:37802772843e 67
joshdavy 1:37802772843e 68 // wait flashing LEDs until start button is pressed
joshdavy 1:37802772843e 69 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
joshdavy 1:37802772843e 70 pad.leds_on();
joshdavy 1:37802772843e 71 wait(0.1);
joshdavy 1:37802772843e 72 pad.leds_off();
joshdavy 1:37802772843e 73 wait(0.1);
joshdavy 2:b62e8be35a5d 74 printf("Welcome\n");
joshdavy 1:37802772843e 75 }
joshdavy 2:b62e8be35a5d 76
joshdavy 1:37802772843e 77 }
joshdavy 1:37802772843e 78
joshdavy 5:b9cf407bcc63 79 int tick = 0.000125;
joshdavy 5:b9cf407bcc63 80
joshdavy 1:37802772843e 81 int main()
joshdavy 1:37802772843e 82 {
joshdavy 3:b34685dbdb8d 83
joshdavy 3:b34685dbdb8d 84
joshdavy 1:37802772843e 85 init(); // initialise and then display welcome screen...
joshdavy 1:37802772843e 86 welcome(); // waiting for the user to start
joshdavy 2:b62e8be35a5d 87 lcd.clear();
joshdavy 2:b62e8be35a5d 88 lcd.refresh();
joshdavy 2:b62e8be35a5d 89 printf("MAIN\n");
joshdavy 1:37802772843e 90
joshdavy 1:37802772843e 91
joshdavy 1:37802772843e 92
joshdavy 1:37802772843e 93 // game loop - read input, update the game state and render the display
joshdavy 1:37802772843e 94 while (1) {
joshdavy 3:b34685dbdb8d 95 processedTime.start();
joshdavy 6:2ca1516ec1e2 96 printf("TIME: %i\n",processedTime.read_ms());
joshdavy 5:b9cf407bcc63 97 //
joshdavy 6:2ca1516ec1e2 98 game.read_input(pad);
joshdavy 6:2ca1516ec1e2 99 game.update(pad);
joshdavy 6:2ca1516ec1e2 100 game.draw(lcd);
joshdavy 6:2ca1516ec1e2 101 wait(0.1);
joshdavy 6:2ca1516ec1e2 102
joshdavy 6:2ca1516ec1e2 103
joshdavy 6:2ca1516ec1e2 104 // if (processedTime.read_us() > 125) {
joshdavy 6:2ca1516ec1e2 105 // player.play_next();
joshdavy 6:2ca1516ec1e2 106 // processedTime.reset();
joshdavy 6:2ca1516ec1e2 107 // }
joshdavy 2:b62e8be35a5d 108
joshdavy 2:b62e8be35a5d 109
joshdavy 1:37802772843e 110
joshdavy 1:37802772843e 111 }
joshdavy 1:37802772843e 112 }