Dependencies:   mbed FATFileSystem

Committer:
ellisbhastroud
Date:
Thu Apr 18 10:42:42 2019 +0000
Revision:
8:d410856c6d04
Parent:
5:0b31909caf7f
Child:
9:bc34f2243e43
Course map draw and bounce algorithms complete

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ellisbhastroud 0:c6ceddb241df 1 /*
ellisbhastroud 0:c6ceddb241df 2 ELEC2645 Embedded Systems Project
ellisbhastroud 0:c6ceddb241df 3 School of Electronic & Electrical Engineering
ellisbhastroud 0:c6ceddb241df 4 University of Leeds
ellisbhastroud 0:c6ceddb241df 5 Name: Ellis Blackford Stroud
ellisbhastroud 0:c6ceddb241df 6 Username: el17ebs
ellisbhastroud 0:c6ceddb241df 7 Student ID Number: 201155309
ellisbhastroud 1:6179c2d67d19 8 Date: 09/05/19
ellisbhastroud 0:c6ceddb241df 9 */
ellisbhastroud 5:0b31909caf7f 10
ellisbhastroud 0:c6ceddb241df 11 #include "mbed.h"
ellisbhastroud 1:6179c2d67d19 12 #include "Gamepad.h"
ellisbhastroud 1:6179c2d67d19 13 #include "N5110.h"
ellisbhastroud 1:6179c2d67d19 14 #include "Menu.h"
ellisbhastroud 5:0b31909caf7f 15 #include "GolfEngine.h"
ellisbhastroud 0:c6ceddb241df 16
ellisbhastroud 1:6179c2d67d19 17 // objects
ellisbhastroud 1:6179c2d67d19 18 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
ellisbhastroud 1:6179c2d67d19 19 Gamepad pad;
ellisbhastroud 2:81cfa8310f55 20 Menu menu;
ellisbhastroud 5:0b31909caf7f 21 GolfEngine golf;
ellisbhastroud 2:81cfa8310f55 22 void init();
ellisbhastroud 5:0b31909caf7f 23
ellisbhastroud 4:035448357749 24 int frame_rate = 40;
ellisbhastroud 0:c6ceddb241df 25
ellisbhastroud 0:c6ceddb241df 26 int main()
ellisbhastroud 0:c6ceddb241df 27 {
ellisbhastroud 1:6179c2d67d19 28 init();
ellisbhastroud 2:81cfa8310f55 29 lcd.clear();
ellisbhastroud 2:81cfa8310f55 30 menu.print_welcome(lcd);
ellisbhastroud 5:0b31909caf7f 31 lcd.clear();
ellisbhastroud 3:a8960004d261 32 bool start_game = false;
ellisbhastroud 3:a8960004d261 33
ellisbhastroud 5:0b31909caf7f 34 while(start_game == false) { //menu loop navigates menu until game started
ellisbhastroud 5:0b31909caf7f 35
ellisbhastroud 5:0b31909caf7f 36 menu.menu_screen(pad, lcd);
ellisbhastroud 5:0b31909caf7f 37 start_game = menu.menu_change(lcd, pad); //changes menu screen to selected screen the returns true when start game
ellisbhastroud 3:a8960004d261 38 }
ellisbhastroud 4:035448357749 39
ellisbhastroud 5:0b31909caf7f 40 frame_rate = menu.get_frame_rate(); //can be changed in the settings screen
ellisbhastroud 4:035448357749 41 //game loop to run game
ellisbhastroud 2:81cfa8310f55 42
ellisbhastroud 3:a8960004d261 43 while(1){
ellisbhastroud 3:a8960004d261 44
ellisbhastroud 4:035448357749 45 lcd.clear();
ellisbhastroud 8:d410856c6d04 46 golf.read_input(pad);
ellisbhastroud 5:0b31909caf7f 47 golf.update_ball(pad, frame_rate);
ellisbhastroud 8:d410856c6d04 48 golf.drawGame(lcd, pad);
ellisbhastroud 3:a8960004d261 49 lcd.refresh();
ellisbhastroud 4:035448357749 50 wait(1.0f/frame_rate); //time between loops/frames
ellisbhastroud 4:035448357749 51
ellisbhastroud 2:81cfa8310f55 52 }
ellisbhastroud 3:a8960004d261 53
ellisbhastroud 1:6179c2d67d19 54 }
ellisbhastroud 1:6179c2d67d19 55
ellisbhastroud 1:6179c2d67d19 56 void init()
ellisbhastroud 1:6179c2d67d19 57 {
ellisbhastroud 1:6179c2d67d19 58 lcd.init();
ellisbhastroud 1:6179c2d67d19 59 pad.init();
ellisbhastroud 4:035448357749 60 menu.init();
ellisbhastroud 5:0b31909caf7f 61 golf.init();
ellisbhastroud 4:035448357749 62 lcd.setContrast(0.5f);
ellisbhastroud 1:6179c2d67d19 63 }