James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Revision:
29:42651f87522b
Parent:
28:cc7a93ebd7e7
Child:
30:c36a08e8f5de
--- a/Map/Map.cpp	Thu Apr 25 16:26:34 2019 +0000
+++ b/Map/Map.cpp	Sat Apr 27 12:50:30 2019 +0000
@@ -7,14 +7,15 @@
 }
 
 void Map::init(){
-    _coord.x = 100;
-    _coord.y = 100;
+    _coord.x = 0;
+    _coord.y = 0;
 }
 
-void Map::read_input(FXOS8700CQ &accelerometer){
+void Map::read_input(FXOS8700CQ &accelerometer, Ball &ball){
     Data values = accelerometer.get_values();
-    _map_change.x = -5*values.ay;
-    _map_change.y = -5*values.ax;
+    int ball_speed = ball.get_ball_speed();
+    _map_change.x = -(1+0.5*ball_speed)*values.ay;
+    _map_change.y = -(1+0.5*ball_speed)*values.ax;
 }
 
 void Map::update(){
@@ -22,8 +23,8 @@
     _coord.y += _map_change.y;
     if(_coord.x < 0){ _coord.x = 0;}        //boundary conditions to stop the 
     if(_coord.y < 0){ _coord.y = 0;}        //the programme trying to display
-    if(_coord.x > 416) {_coord.x = 416;}    //undefined region outside the
-    if(_coord.y > 152) {_coord.y = 152;}    //gamemap array
+    if(_coord.x > 506) {_coord.x = 506;}    //undefined region outside the
+    if(_coord.y > 176) {_coord.y = 176;}    //gamemap array
 }
 
 void Map::draw(N5110 &lcd){
@@ -44,4 +45,28 @@
 
 void Map::set_map_display(Vector2D coord){
     _coord = coord;
-}
\ No newline at end of file
+}
+
+bool Map::check_wall_collision(Gamepad &gamepad, Ball &ball){
+    bool collision = false;
+    Vector2D c = ball.get_position();
+    Vector2D ball_pixels[37] = {
+        {c.x,c.y},{c.x+1,c.y},{c.x+2,c.y},{c.x+3,c.y},{c.x-1,c.y},{c.x-2,c.y},
+        {c.x-3,c.y},{c.x,c.y+1},{c.x+1,c.y+1},{c.x+2,c.y+1},{c.x+3,c.y+1},
+        {c.x-1,c.y+1},{c.x-2,c.y+1},{c.x-3,c.y+1},{c.x,c.y-1},{c.x+1,c.y-1},
+        {c.x+2,c.y-1},{c.x+3,c.y-1},{c.x-1,c.y-1},{c.x-2,c.y-1},{c.x-3,c.y-1},
+        {c.x,c.y+2},{c.x+1,c.y+2},{c.x+2,c.y+2},{c.x-1,c.y+2},{c.x-2,c.y+2},
+        {c.x,c.y-2},{c.x+1,c.y-2},{c.x+2,c.y-2},{c.x-1,c.y-2},{c.x-2,c.y-2},
+        {c.x,c.y+3},{c.x+1,c.y+3},{c.x-1,c.y+3},{c.x,c.y-3},{c.x+1,c.y-3},
+        {c.x-1,c.y-3}   };
+    for(int i = 0; i < 37; i++){
+        int y = ball_pixels[i].y;
+        int x = ball_pixels[i].x;
+        if(gamemap[y][x] == 1){
+            collision = true;
+            printf("colliding pixel = %d,%d\n", x, y);
+            break;
+        } else { collision = false; }
+    }
+    return collision;
+}