ELEC2645 (2018/19) / Mbed 2 deprecated ll16o2l_ELEC2645

Dependencies:   mbed Gamepad

Committer:
ll16o2l
Date:
Mon Mar 25 11:54:51 2019 +0000
Revision:
1:2d3139578aca
Parent:
0:03363a508918
Child:
2:888634fff8ff
Made Main file with the starting message.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ll16o2l 0:03363a508918 1 /*
ll16o2l 0:03363a508918 2 ELEC2645 Embedded Systems Project
ll16o2l 0:03363a508918 3 School of Electronic & Electrical Engineering
ll16o2l 0:03363a508918 4 University of Leeds
ll16o2l 0:03363a508918 5 Name: Oliver Luong
ll16o2l 0:03363a508918 6 Username: ll16o2l
ll16o2l 0:03363a508918 7 Student ID Number:201140613
ll16o2l 0:03363a508918 8 Date:05/03/2019
ll16o2l 1:2d3139578aca 9 */
ll16o2l 1:2d3139578aca 10
ll16o2l 1:2d3139578aca 11 ///////// pre-processor directives ////////
ll16o2l 1:2d3139578aca 12 #include "mbed.h"
ll16o2l 1:2d3139578aca 13 #include "Gamepad.h"
ll16o2l 1:2d3139578aca 14 #include "N5110.h"
ll16o2l 1:2d3139578aca 15 #include "AsteroidEngine.h"
ll16o2l 1:2d3139578aca 16
ll16o2l 1:2d3139578aca 17 #ifdef WITH_TESTING
ll16o2l 1:2d3139578aca 18 # include "tests.h"
ll16o2l 1:2d3139578aca 19 #endif
ll16o2l 1:2d3139578aca 20
ll16o2l 1:2d3139578aca 21 /////////////// structs /////////////////
ll16o2l 1:2d3139578aca 22 struct UserInput {
ll16o2l 1:2d3139578aca 23 Direction d; //////////////////CHANGE
ll16o2l 1:2d3139578aca 24 float mag; ////////////////////CHANGE
ll16o2l 1:2d3139578aca 25 };
ll16o2l 1:2d3139578aca 26 /////////////// objects ///////////////
ll16o2l 1:2d3139578aca 27 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
ll16o2l 1:2d3139578aca 28 Gamepad pad;
ll16o2l 1:2d3139578aca 29 AsteroidEngine asteroid;
ll16o2l 1:2d3139578aca 30
ll16o2l 1:2d3139578aca 31 ///////////// prototypes ///////////////
ll16o2l 1:2d3139578aca 32 void init();
ll16o2l 1:2d3139578aca 33 void update_game(UserInput input);
ll16o2l 1:2d3139578aca 34 void render();
ll16o2l 1:2d3139578aca 35 void welcome();
ll16o2l 1:2d3139578aca 36
ll16o2l 1:2d3139578aca 37 ///////////// sprites ///////////////
ll16o2l 1:2d3139578aca 38
ll16o2l 1:2d3139578aca 39 // First declare the pixel map data using '1' for black,
ll16o2l 1:2d3139578aca 40 // or '0' for white pixels
ll16o2l 1:2d3139578aca 41 int Spacecraft_sprite[7][9] = {
ll16o2l 1:2d3139578aca 42 {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
ll16o2l 1:2d3139578aca 43 {0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
ll16o2l 1:2d3139578aca 44 {0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
ll16o2l 1:2d3139578aca 45 {0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
ll16o2l 1:2d3139578aca 46 {0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
ll16o2l 1:2d3139578aca 47 {0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
ll16o2l 1:2d3139578aca 48 {1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
ll16o2l 1:2d3139578aca 49 };
ll16o2l 1:2d3139578aca 50
ll16o2l 1:2d3139578aca 51 ///////////// functions ////////////////
ll16o2l 1:2d3139578aca 52 int main()
ll16o2l 1:2d3139578aca 53 {
ll16o2l 1:2d3139578aca 54 #ifdef WITH_TESTING
ll16o2l 1:2d3139578aca 55 int number_of_failures = run_all_tests();
ll16o2l 1:2d3139578aca 56
ll16o2l 1:2d3139578aca 57 if(number_of_failures > 0) return number_of_failures;
ll16o2l 1:2d3139578aca 58 #endif
ll16o2l 1:2d3139578aca 59
ll16o2l 1:2d3139578aca 60 int fps = 8; // frames per second
ll16o2l 1:2d3139578aca 61
ll16o2l 1:2d3139578aca 62 init(); // initialise and then display welcome screen...
ll16o2l 1:2d3139578aca 63 welcome(); // waiting for the user to start
ll16o2l 1:2d3139578aca 64
ll16o2l 1:2d3139578aca 65 render(); // first draw the initial frame
ll16o2l 1:2d3139578aca 66 wait(1.0f/fps); // and wait for one frame period
ll16o2l 1:2d3139578aca 67
ll16o2l 1:2d3139578aca 68
ll16o2l 1:2d3139578aca 69 // game loop - read input, update the game state and render the display
ll16o2l 1:2d3139578aca 70 while (1) {
ll16o2l 1:2d3139578aca 71 asteroid.read_input(pad);
ll16o2l 1:2d3139578aca 72 asteroid.update(pad);
ll16o2l 1:2d3139578aca 73 render();
ll16o2l 1:2d3139578aca 74 wait(1.0f/fps);
ll16o2l 1:2d3139578aca 75 }
ll16o2l 1:2d3139578aca 76 }
ll16o2l 1:2d3139578aca 77
ll16o2l 1:2d3139578aca 78 // initialies all classes and libraries
ll16o2l 1:2d3139578aca 79 void init()
ll16o2l 1:2d3139578aca 80 {
ll16o2l 1:2d3139578aca 81 // need to initialise LCD and Gamepad
ll16o2l 1:2d3139578aca 82 lcd.init();
ll16o2l 1:2d3139578aca 83 pad.init();
ll16o2l 1:2d3139578aca 84
ll16o2l 1:2d3139578aca 85 // initialise the game with correct ball and paddle sizes
ll16o2l 1:2d3139578aca 86 pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED); ////////////CHANGE
ll16o2l 1:2d3139578aca 87
ll16o2l 1:2d3139578aca 88 }
ll16o2l 1:2d3139578aca 89
ll16o2l 1:2d3139578aca 90 // this function draws each frame on the LCD
ll16o2l 1:2d3139578aca 91 void render()
ll16o2l 1:2d3139578aca 92 {
ll16o2l 1:2d3139578aca 93 // clear screen, re-draw and refresh
ll16o2l 1:2d3139578aca 94 lcd.clear();
ll16o2l 1:2d3139578aca 95 pong.draw(lcd); /////////////////CHANGE
ll16o2l 1:2d3139578aca 96 lcd.refresh();
ll16o2l 1:2d3139578aca 97 }
ll16o2l 1:2d3139578aca 98
ll16o2l 1:2d3139578aca 99 // simple splash screen displayed on start-up
ll16o2l 1:2d3139578aca 100 void welcome() {
ll16o2l 1:2d3139578aca 101
ll16o2l 1:2d3139578aca 102 lcd.printString(" Asteroids! ",0,1);
ll16o2l 1:2d3139578aca 103 lcd.printString(" Press Start ",0,4);
ll16o2l 1:2d3139578aca 104 lcd.refresh();
ll16o2l 1:2d3139578aca 105
ll16o2l 1:2d3139578aca 106 // wait flashing LEDs until start button is pressed
ll16o2l 1:2d3139578aca 107 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
ll16o2l 1:2d3139578aca 108 pad.leds_on();
ll16o2l 1:2d3139578aca 109 wait(0.1);
ll16o2l 1:2d3139578aca 110 pad.leds_off();
ll16o2l 1:2d3139578aca 111 wait(0.1);
ll16o2l 1:2d3139578aca 112 }
ll16o2l 1:2d3139578aca 113
ll16o2l 1:2d3139578aca 114 }