16

Dependencies:   Ball Ball1 Gamepad N5110 Paddle1 PongEngine cab lab mbed

Fork of Pong by Craig Evans

Revision:
3:910d7e87f367
Parent:
1:25a839625a1e
Child:
4:d349e5d847cf
--- a/main.cpp	Wed Mar 01 13:57:15 2017 +0000
+++ b/main.cpp	Sun Mar 05 21:18:09 2017 +0000
@@ -22,16 +22,19 @@
 void init();
 void update_game(UserInput input);
 void render();
+void welcome();
 ///////////// functions ////////////////
 int main()
 {
-    int fps = 8;
+    int fps = 8;  // frames per second
 
     init();
+    welcome();
     
     render();  // draw initial frame 
-    wait(1.0f/fps);
+    wait(1.0f/fps);  
 
+    // game loop - read input, update the game state and render
     while (1) {
         pong.read_input(pad);
         pong.update(pad);
@@ -42,21 +45,35 @@
 
 void init()
 {
+    // need to initialise LCD and Gamepad 
     lcd.init();
     pad.init();
-    
-    float rand1 = pad.read_pot();
-    Vector2D rand2 = pad.get_coord();
-    int seed = int(1.0e6f*(rand1 + (rand2.x/rand2.y)));
-    // create some random number from ADC pins to use in srand
-    
-    pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_RADIUS,BALL_SPEED,seed);
+     
+    // initialise the game
+    pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_RADIUS,BALL_SPEED);
 
 }
 
 void render()
 {
-    lcd.clear();  // clear screen, re-draw and refresh
+    // clear screen, re-draw and refresh
+    lcd.clear();  
     pong.draw(lcd);
     lcd.refresh();
+}
+
+void welcome() {
+    
+    lcd.printString("    Pong!    ",0,1);  
+    lcd.printString(" Press Start ",0,4);
+    lcd.refresh();
+     
+    // wait flashing LEDs until start button is pressed 
+    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
+        pad.leds_on();
+        wait(0.1);
+        pad.leds_off();
+        wait(0.1);
+    }
+ 
 }
\ No newline at end of file