
Ellis Blackford Stroud 201155309
Dependencies: mbed FATFileSystem
main.cpp@5:0b31909caf7f, 2019-04-17 (annotated)
- Committer:
- ellisbhastroud
- Date:
- Wed Apr 17 10:27:09 2019 +0000
- Revision:
- 5:0b31909caf7f
- Parent:
- 4:035448357749
- Child:
- 8:d410856c6d04
Levels Added Not 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 | 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 | |
ellisbhastroud | 4:035448357749 | 42 | //game loop to run game |
ellisbhastroud | 2:81cfa8310f55 | 43 | |
ellisbhastroud | 3:a8960004d261 | 44 | while(1){ |
ellisbhastroud | 3:a8960004d261 | 45 | |
ellisbhastroud | 4:035448357749 | 46 | lcd.clear(); |
ellisbhastroud | 5:0b31909caf7f | 47 | golf.update_ball(pad, frame_rate); |
ellisbhastroud | 5:0b31909caf7f | 48 | golf.drawGame(lcd); |
ellisbhastroud | 3:a8960004d261 | 49 | lcd.refresh(); |
ellisbhastroud | 2:81cfa8310f55 | 50 | |
ellisbhastroud | 4:035448357749 | 51 | wait(1.0f/frame_rate); //time between loops/frames |
ellisbhastroud | 4:035448357749 | 52 | |
ellisbhastroud | 2:81cfa8310f55 | 53 | } |
ellisbhastroud | 3:a8960004d261 | 54 | |
ellisbhastroud | 1:6179c2d67d19 | 55 | } |
ellisbhastroud | 1:6179c2d67d19 | 56 | |
ellisbhastroud | 1:6179c2d67d19 | 57 | void init() |
ellisbhastroud | 1:6179c2d67d19 | 58 | { |
ellisbhastroud | 1:6179c2d67d19 | 59 | lcd.init(); |
ellisbhastroud | 1:6179c2d67d19 | 60 | pad.init(); |
ellisbhastroud | 4:035448357749 | 61 | menu.init(); |
ellisbhastroud | 5:0b31909caf7f | 62 | golf.init(); |
ellisbhastroud | 4:035448357749 | 63 | lcd.setContrast(0.5f); |
ellisbhastroud | 1:6179c2d67d19 | 64 | } |