Ellis Blackford Stroud 201155309
Dependencies: mbed FATFileSystem
main.cpp@9:bc34f2243e43, 2019-04-20 (annotated)
- Committer:
- ellisbhastroud
- Date:
- Sat Apr 20 10:42:17 2019 +0000
- Revision:
- 9:bc34f2243e43
- Parent:
- 8:d410856c6d04
- Child:
- 10:9f54a6366e94
Levels addition fully functioning
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:bc34f2243e43 | 26 | |
ellisbhastroud | 5:0b31909caf7f | 27 | |
ellisbhastroud | 4:035448357749 | 28 | int frame_rate = 40; |
ellisbhastroud | 0:c6ceddb241df | 29 | |
ellisbhastroud | 0:c6ceddb241df | 30 | int main() |
ellisbhastroud | 0:c6ceddb241df | 31 | { |
ellisbhastroud | 1:6179c2d67d19 | 32 | init(); |
ellisbhastroud | 2:81cfa8310f55 | 33 | lcd.clear(); |
ellisbhastroud | 2:81cfa8310f55 | 34 | menu.print_welcome(lcd); |
ellisbhastroud | 5:0b31909caf7f | 35 | lcd.clear(); |
ellisbhastroud | 3:a8960004d261 | 36 | bool start_game = false; |
ellisbhastroud | 3:a8960004d261 | 37 | |
ellisbhastroud | 5:0b31909caf7f | 38 | while(start_game == false) { //menu loop navigates menu until game started |
ellisbhastroud | 5:0b31909caf7f | 39 | |
ellisbhastroud | 5:0b31909caf7f | 40 | menu.menu_screen(pad, lcd); |
ellisbhastroud | 5:0b31909caf7f | 41 | start_game = menu.menu_change(lcd, pad); //changes menu screen to selected screen the returns true when start game |
ellisbhastroud | 3:a8960004d261 | 42 | } |
ellisbhastroud | 9:bc34f2243e43 | 43 | lcd.clear(); |
ellisbhastroud | 9:bc34f2243e43 | 44 | golf.printLevel(lcd); |
ellisbhastroud | 9:bc34f2243e43 | 45 | lcd.refresh(); |
ellisbhastroud | 9:bc34f2243e43 | 46 | wait(1); |
ellisbhastroud | 9:bc34f2243e43 | 47 | frame_rate = menu.get_frame_rate(); //changes frame rate to the value chosen in settings |
ellisbhastroud | 4:035448357749 | 48 | //game loop to run game |
ellisbhastroud | 2:81cfa8310f55 | 49 | |
ellisbhastroud | 3:a8960004d261 | 50 | while(1){ |
ellisbhastroud | 9:bc34f2243e43 | 51 | |
ellisbhastroud | 9:bc34f2243e43 | 52 | if(golf.get_hole_flag() == false) { //if ball not in hole |
ellisbhastroud | 9:bc34f2243e43 | 53 | |
ellisbhastroud | 9:bc34f2243e43 | 54 | lcd.clear(); |
ellisbhastroud | 9:bc34f2243e43 | 55 | golf.read_input(pad); |
ellisbhastroud | 9:bc34f2243e43 | 56 | golf.update_ball(pad, frame_rate); |
ellisbhastroud | 9:bc34f2243e43 | 57 | golf.drawGame(lcd, pad); |
ellisbhastroud | 9:bc34f2243e43 | 58 | lcd.refresh(); |
ellisbhastroud | 9:bc34f2243e43 | 59 | wait(1.0f/frame_rate); //time between loops/frames (at lower frame rates ball may be harder to get in hole) |
ellisbhastroud | 9:bc34f2243e43 | 60 | |
ellisbhastroud | 9:bc34f2243e43 | 61 | } else if(golf.get_hole_flag() == true) { //if ball goes in hole end level and start new level |
ellisbhastroud | 9:bc34f2243e43 | 62 | |
ellisbhastroud | 9:bc34f2243e43 | 63 | inverseFlash(); //flashes screen pixels on and off |
ellisbhastroud | 9:bc34f2243e43 | 64 | inverseFlash(); |
ellisbhastroud | 9:bc34f2243e43 | 65 | lcd.clear(); |
ellisbhastroud | 9:bc34f2243e43 | 66 | golf.new_level(); //moves ball to new level position and increments level |
ellisbhastroud | 9:bc34f2243e43 | 67 | golf.reset_hole_flag(); //so that the game loop can continue |
ellisbhastroud | 9:bc34f2243e43 | 68 | golf.printLevel(lcd); //notifying user of start of new level |
ellisbhastroud | 9:bc34f2243e43 | 69 | lcd.refresh(); |
ellisbhastroud | 9:bc34f2243e43 | 70 | wait(1); |
ellisbhastroud | 9:bc34f2243e43 | 71 | } |
ellisbhastroud | 2:81cfa8310f55 | 72 | } |
ellisbhastroud | 1:6179c2d67d19 | 73 | } |
ellisbhastroud | 1:6179c2d67d19 | 74 | |
ellisbhastroud | 1:6179c2d67d19 | 75 | void init() |
ellisbhastroud | 1:6179c2d67d19 | 76 | { |
ellisbhastroud | 1:6179c2d67d19 | 77 | lcd.init(); |
ellisbhastroud | 1:6179c2d67d19 | 78 | pad.init(); |
ellisbhastroud | 4:035448357749 | 79 | menu.init(); |
ellisbhastroud | 5:0b31909caf7f | 80 | golf.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 | } |