ELEC2645 (2016/17) / Mbed 2 deprecated gravitygame_abdulrahmanalhinaisub

Dependencies:   Gamepad N5110 mbed

Fork of gravitygame_abdulrahmanalhinai by Abdul Rahman Alhinai

Revision:
5:8d882354e387
Parent:
4:d349e5d847cf
--- a/main.cpp	Sun Mar 05 23:19:55 2017 +0000
+++ b/main.cpp	Fri May 05 12:43:45 2017 +0000
@@ -1,13 +1,19 @@
+/*
+@author abdul rahman alhinai 200904758
+@brief main folder of the game (gravity) 
+@date may 2017
+*/
 ///////// pre-processor directives ////////
 #include "mbed.h"
 #include "Gamepad.h"
+#include "FXOS8700CQ.h"
 #include "N5110.h"
 #include "PongEngine.h"
 
-#define PADDLE_WIDTH 2
-#define PADDLE_HEIGHT 8
-#define BALL_SIZE 2
-#define BALL_SPEED 3
+#define PADDLE_RADIUS 4
+#define BALL_SIZE 3
+#define BALL_SPEED 2
+#define BALL_LVL 0
 
 /////////////// structs /////////////////
 struct UserInput {
@@ -15,6 +21,7 @@
     float mag;
 };
 /////////////// objects ///////////////
+FXOS8700CQ device(I2C_SDA,I2C_SCL);
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 Gamepad pad;
 PongEngine pong;
@@ -27,17 +34,19 @@
 int main()
 {
     int fps = 8;  // frames per second
-
+ device.init();
     init();
     welcome();
-    
-    render();  // draw initial frame 
-    wait(1.0f/fps);  
+    Data values = device.get_values();
+
+
+    render();  // draw initial frame
+    wait(1.0f/fps);
 
     // game loop - read input, update the game state and render the display
     while (1) {
-        pong.read_input(pad);
-        pong.update(pad);
+        pong.read_input(pad,device);
+        pong.update(BALL_SPEED,pad,lcd,device);
         render();
         wait(1.0f/fps);
     }
@@ -45,35 +54,36 @@
 
 void init()
 {
-    // need to initialise LCD and Gamepad 
+    // need to initialise LCD and Gamepad
     lcd.init();
     pad.init();
-     
+ device.init();
     // initialise the game
-    pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED);
+    pong.init(PADDLE_RADIUS,BALL_SIZE,BALL_SPEED,device);
 
 }
 
 void render()
 {
     // clear screen, re-draw and refresh
-    lcd.clear();  
+    lcd.clear();
     pong.draw(lcd);
     lcd.refresh();
 }
 
-void welcome() {
-    
-    lcd.printString("     Pong!    ",0,1);  
+void welcome()
+{
+
+    lcd.printString("    gravity    ",0,1);
     lcd.printString("  Press Start ",0,4);
     lcd.refresh();
-     
-    // wait flashing LEDs until start button is pressed 
+
+    // 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