Josh Davy / Mbed OS Flip_OS_5

Dependencies:   el17jd

Committer:
joshdavy
Date:
Tue Apr 02 10:45:44 2019 +0000
Revision:
2:b62e8be35a5d
Parent:
1:37802772843e
Child:
3:b34685dbdb8d
Basic Sprite Rendering

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 2:b62e8be35a5d 12 int processedTime;
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 1:37802772843e 22
joshdavy 2:b62e8be35a5d 23 ////// Constants //////
joshdavy 2:b62e8be35a5d 24 #define GRAVITY (0,-1)
joshdavy 2:b62e8be35a5d 25
joshdavy 2:b62e8be35a5d 26
joshdavy 2:b62e8be35a5d 27
joshdavy 1:37802772843e 28 /////////////// objects ///////////////
joshdavy 1:37802772843e 29 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
joshdavy 1:37802772843e 30 Gamepad pad;
joshdavy 1:37802772843e 31 Game game;
joshdavy 1:37802772843e 32
joshdavy 1:37802772843e 33
joshdavy 2:b62e8be35a5d 34
joshdavy 1:37802772843e 35 ///////////// prototypes ///////////////
joshdavy 1:37802772843e 36 void init();
joshdavy 1:37802772843e 37 void welcome();
joshdavy 1:37802772843e 38
joshdavy 1:37802772843e 39 // initialies all classes and libraries
joshdavy 1:37802772843e 40 void init()
joshdavy 2:b62e8be35a5d 41
joshdavy 1:37802772843e 42 {
joshdavy 2:b62e8be35a5d 43
joshdavy 1:37802772843e 44 // need to initialise LCD and Gamepad
joshdavy 1:37802772843e 45 lcd.init();
joshdavy 2:b62e8be35a5d 46 lcd.setContrast(0.4);
joshdavy 1:37802772843e 47 pad.init();
joshdavy 1:37802772843e 48
joshdavy 2:b62e8be35a5d 49
joshdavy 2:b62e8be35a5d 50 processedTime = time(NULL);
joshdavy 1:37802772843e 51
joshdavy 1:37802772843e 52
joshdavy 1:37802772843e 53 }
joshdavy 1:37802772843e 54 // simple splash screen displayed on start-up
joshdavy 1:37802772843e 55 void welcome() {
joshdavy 1:37802772843e 56
joshdavy 2:b62e8be35a5d 57
joshdavy 2:b62e8be35a5d 58 lcd.printString(" WOo2 ",0,1);
joshdavy 1:37802772843e 59 lcd.printString(" Press Start ",0,4);
joshdavy 1:37802772843e 60 lcd.refresh();
joshdavy 1:37802772843e 61
joshdavy 1:37802772843e 62 // wait flashing LEDs until start button is pressed
joshdavy 1:37802772843e 63 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
joshdavy 1:37802772843e 64 pad.leds_on();
joshdavy 1:37802772843e 65 wait(0.1);
joshdavy 1:37802772843e 66 pad.leds_off();
joshdavy 1:37802772843e 67 wait(0.1);
joshdavy 2:b62e8be35a5d 68 printf("Welcome\n");
joshdavy 1:37802772843e 69 }
joshdavy 2:b62e8be35a5d 70
joshdavy 1:37802772843e 71 }
joshdavy 1:37802772843e 72
joshdavy 1:37802772843e 73 int main()
joshdavy 1:37802772843e 74 {
joshdavy 1:37802772843e 75 init(); // initialise and then display welcome screen...
joshdavy 1:37802772843e 76 welcome(); // waiting for the user to start
joshdavy 2:b62e8be35a5d 77 lcd.clear();
joshdavy 2:b62e8be35a5d 78 lcd.refresh();
joshdavy 2:b62e8be35a5d 79 printf("MAIN\n");
joshdavy 1:37802772843e 80
joshdavy 1:37802772843e 81
joshdavy 1:37802772843e 82
joshdavy 1:37802772843e 83 // game loop - read input, update the game state and render the display
joshdavy 1:37802772843e 84 while (1) {
joshdavy 2:b62e8be35a5d 85
joshdavy 2:b62e8be35a5d 86 printf("TIME: %i\n",processedTime);
joshdavy 2:b62e8be35a5d 87
joshdavy 1:37802772843e 88 game.read_input(pad);
joshdavy 1:37802772843e 89 game.update(pad);
joshdavy 1:37802772843e 90 game.draw(lcd);
joshdavy 2:b62e8be35a5d 91 wait(0.1);
joshdavy 2:b62e8be35a5d 92
joshdavy 1:37802772843e 93
joshdavy 1:37802772843e 94 }
joshdavy 1:37802772843e 95 }