Ellis Blackford Stroud 201155309

Dependencies:   mbed FATFileSystem

Committer:
ellisbhastroud
Date:
Tue Apr 23 12:03:38 2019 +0000
Revision:
10:9f54a6366e94
Parent:
9:bc34f2243e43
Child:
12:7f7fadb5c106
Added corner bounces to bounce check algorithm. More levels now added with complex courses.

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 9:bc34f2243e43 22
ellisbhastroud 9:bc34f2243e43 23 //functions
ellisbhastroud 2:81cfa8310f55 24 void init();
ellisbhastroud 9:bc34f2243e43 25 void inverseFlash();
ellisbhastroud 10:9f54a6366e94 26 //
ellisbhastroud 10:9f54a6366e94 27 int frame_rate;
ellisbhastroud 0:c6ceddb241df 28
ellisbhastroud 0:c6ceddb241df 29 int main()
ellisbhastroud 0:c6ceddb241df 30 {
ellisbhastroud 1:6179c2d67d19 31 init();
ellisbhastroud 2:81cfa8310f55 32 lcd.clear();
ellisbhastroud 2:81cfa8310f55 33 menu.print_welcome(lcd);
ellisbhastroud 5:0b31909caf7f 34 lcd.clear();
ellisbhastroud 3:a8960004d261 35 bool start_game = false;
ellisbhastroud 3:a8960004d261 36
ellisbhastroud 5:0b31909caf7f 37 while(start_game == false) { //menu loop navigates menu until game started
ellisbhastroud 5:0b31909caf7f 38
ellisbhastroud 5:0b31909caf7f 39 menu.menu_screen(pad, lcd);
ellisbhastroud 5:0b31909caf7f 40 start_game = menu.menu_change(lcd, pad); //changes menu screen to selected screen the returns true when start game
ellisbhastroud 3:a8960004d261 41 }
ellisbhastroud 9:bc34f2243e43 42 lcd.clear();
ellisbhastroud 9:bc34f2243e43 43 golf.printLevel(lcd);
ellisbhastroud 9:bc34f2243e43 44 lcd.refresh();
ellisbhastroud 9:bc34f2243e43 45 wait(1);
ellisbhastroud 9:bc34f2243e43 46 frame_rate = menu.get_frame_rate(); //changes frame rate to the value chosen in settings
ellisbhastroud 10:9f54a6366e94 47 golf.init(frame_rate); //resets variables for game and sets frame rate
ellisbhastroud 10:9f54a6366e94 48
ellisbhastroud 4:035448357749 49 //game loop to run game
ellisbhastroud 2:81cfa8310f55 50
ellisbhastroud 3:a8960004d261 51 while(1){
ellisbhastroud 9:bc34f2243e43 52
ellisbhastroud 9:bc34f2243e43 53 if(golf.get_hole_flag() == false) { //if ball not in hole
ellisbhastroud 9:bc34f2243e43 54
ellisbhastroud 9:bc34f2243e43 55 lcd.clear();
ellisbhastroud 9:bc34f2243e43 56 golf.read_input(pad);
ellisbhastroud 10:9f54a6366e94 57 golf.update_ball(pad);
ellisbhastroud 9:bc34f2243e43 58 golf.drawGame(lcd, pad);
ellisbhastroud 9:bc34f2243e43 59 lcd.refresh();
ellisbhastroud 9:bc34f2243e43 60 wait(1.0f/frame_rate); //time between loops/frames (at lower frame rates ball may be harder to get in hole)
ellisbhastroud 9:bc34f2243e43 61
ellisbhastroud 9:bc34f2243e43 62 } else if(golf.get_hole_flag() == true) { //if ball goes in hole end level and start new level
ellisbhastroud 9:bc34f2243e43 63
ellisbhastroud 9:bc34f2243e43 64 inverseFlash(); //flashes screen pixels on and off
ellisbhastroud 9:bc34f2243e43 65 inverseFlash();
ellisbhastroud 9:bc34f2243e43 66 lcd.clear();
ellisbhastroud 9:bc34f2243e43 67 golf.new_level(); //moves ball to new level position and increments level
ellisbhastroud 9:bc34f2243e43 68 golf.reset_hole_flag(); //so that the game loop can continue
ellisbhastroud 9:bc34f2243e43 69 golf.printLevel(lcd); //notifying user of start of new level
ellisbhastroud 9:bc34f2243e43 70 lcd.refresh();
ellisbhastroud 9:bc34f2243e43 71 wait(1);
ellisbhastroud 9:bc34f2243e43 72 }
ellisbhastroud 2:81cfa8310f55 73 }
ellisbhastroud 1:6179c2d67d19 74 }
ellisbhastroud 1:6179c2d67d19 75
ellisbhastroud 1:6179c2d67d19 76 void init()
ellisbhastroud 1:6179c2d67d19 77 {
ellisbhastroud 1:6179c2d67d19 78 lcd.init();
ellisbhastroud 1:6179c2d67d19 79 pad.init();
ellisbhastroud 4:035448357749 80 menu.init();
ellisbhastroud 4:035448357749 81 lcd.setContrast(0.5f);
ellisbhastroud 1:6179c2d67d19 82 }
ellisbhastroud 9:bc34f2243e43 83
ellisbhastroud 9:bc34f2243e43 84 void inverseFlash()
ellisbhastroud 9:bc34f2243e43 85 {
ellisbhastroud 9:bc34f2243e43 86 lcd.inverseMode();
ellisbhastroud 9:bc34f2243e43 87 lcd.refresh();
ellisbhastroud 9:bc34f2243e43 88 wait(0.25);
ellisbhastroud 9:bc34f2243e43 89 lcd.normalMode();
ellisbhastroud 9:bc34f2243e43 90 lcd.refresh();
ellisbhastroud 9:bc34f2243e43 91 wait(0.25);
ellisbhastroud 9:bc34f2243e43 92 lcd.inverseMode();
ellisbhastroud 9:bc34f2243e43 93 lcd.refresh();
ellisbhastroud 9:bc34f2243e43 94 wait(0.25);
ellisbhastroud 9:bc34f2243e43 95 lcd.normalMode();
ellisbhastroud 9:bc34f2243e43 96 lcd.refresh();
ellisbhastroud 9:bc34f2243e43 97 wait(0.25);
ellisbhastroud 9:bc34f2243e43 98 }