Ellis Blackford Stroud 201155309

Dependencies:   mbed FATFileSystem

Committer:
ellisbhastroud
Date:
Mon Apr 08 15:10:28 2019 +0000
Revision:
4:035448357749
Parent:
3:a8960004d261
Child:
5:0b31909caf7f
Settings section of menu fully functioning.

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 0:c6ceddb241df 10 #include "mbed.h"
ellisbhastroud 1:6179c2d67d19 11 #include "Gamepad.h"
ellisbhastroud 1:6179c2d67d19 12 #include "N5110.h"
ellisbhastroud 1:6179c2d67d19 13 #include "Menu.h"
ellisbhastroud 3:a8960004d261 14 #include "Ball.h"
ellisbhastroud 3:a8960004d261 15
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 3:a8960004d261 21 Ball ball;
ellisbhastroud 2:81cfa8310f55 22 void init();
ellisbhastroud 4:035448357749 23 int frame_rate = 40;
ellisbhastroud 0:c6ceddb241df 24
ellisbhastroud 0:c6ceddb241df 25 int main()
ellisbhastroud 0:c6ceddb241df 26 {
ellisbhastroud 1:6179c2d67d19 27 init();
ellisbhastroud 2:81cfa8310f55 28 lcd.clear();
ellisbhastroud 2:81cfa8310f55 29 menu.print_welcome(lcd);
ellisbhastroud 4:035448357749 30 menu.print_menu(lcd);
ellisbhastroud 3:a8960004d261 31 bool start_game = false;
ellisbhastroud 3:a8960004d261 32
ellisbhastroud 4:035448357749 33 while(start_game== false) { //menu loop navigates menu until game started
ellisbhastroud 4:035448357749 34
ellisbhastroud 4:035448357749 35 lcd.refresh();
ellisbhastroud 3:a8960004d261 36 menu.menu_select(pad, lcd); //main menu cursor code loops until start pressed
ellisbhastroud 4:035448357749 37 start_game = menu.menu_change(lcd, pad); //changes menu screen to choice returns true if game started
ellisbhastroud 3:a8960004d261 38 }
ellisbhastroud 4:035448357749 39
ellisbhastroud 4:035448357749 40 frame_rate = menu.get_frame_rate();
ellisbhastroud 4:035448357749 41
ellisbhastroud 4:035448357749 42 //game loop to run game
ellisbhastroud 2:81cfa8310f55 43
ellisbhastroud 3:a8960004d261 44 int x_pos = 24;
ellisbhastroud 3:a8960004d261 45 int y_pos = 24;
ellisbhastroud 3:a8960004d261 46 ball.init(x_pos, y_pos);
ellisbhastroud 3:a8960004d261 47
ellisbhastroud 3:a8960004d261 48 while(1){
ellisbhastroud 3:a8960004d261 49
ellisbhastroud 4:035448357749 50 lcd.clear();
ellisbhastroud 3:a8960004d261 51 ball.shoot_ball(pad);
ellisbhastroud 4:035448357749 52 ball.move_ball(frame_rate, lcd);
ellisbhastroud 4:035448357749 53 ball.draw_screen(lcd, pad);
ellisbhastroud 3:a8960004d261 54 lcd.refresh();
ellisbhastroud 2:81cfa8310f55 55
ellisbhastroud 4:035448357749 56 wait(1.0f/frame_rate); //time between loops/frames
ellisbhastroud 4:035448357749 57
ellisbhastroud 2:81cfa8310f55 58 }
ellisbhastroud 3:a8960004d261 59
ellisbhastroud 1:6179c2d67d19 60 }
ellisbhastroud 1:6179c2d67d19 61
ellisbhastroud 1:6179c2d67d19 62 void init()
ellisbhastroud 1:6179c2d67d19 63 {
ellisbhastroud 1:6179c2d67d19 64 lcd.init();
ellisbhastroud 1:6179c2d67d19 65 pad.init();
ellisbhastroud 4:035448357749 66 menu.init();
ellisbhastroud 4:035448357749 67 lcd.setContrast(0.5f);
ellisbhastroud 1:6179c2d67d19 68 }