ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Revision:
25:faba9eb44514
Parent:
24:ab821bfeb383
Child:
26:a53d41adf40b
--- a/RosenEngine/RosenEngine.cpp	Sun Apr 14 18:11:32 2019 +0000
+++ b/RosenEngine/RosenEngine.cpp	Thu Apr 18 06:53:52 2019 +0000
@@ -72,9 +72,17 @@
     Vector2D ship_pos = _ship.get_pos();
     ship_xpos = ship_pos.x;
     ship_ypos = ship_pos.y;
-    ship_width = 9;
     _weapons.init(ship_xpos, ship_ypos, ship_width);
     _ycursor = _menu.get_ycursor();
+
+    if(_shipno == 0) {
+        ship_width = 9;
+        ship_height = 6;
+    }
+    if(_shipno == 1) {
+        ship_width = 7;
+        ship_height = 10;
+    }
 }
 void RosenEngine::title(N5110 &lcd)
 {
@@ -98,91 +106,105 @@
 }
 void RosenEngine::check_enemy_ship_collision()
 {
-    Vector2D ship_pos = _ship.get_pos();
+    // Vector2D ship_pos = _ship.get_pos();
     Vector2D seeker_pos = _enemy.get_seekerpos();
-    int ship_x[9];
-    int ship_y[6];
-    int seeker_x[9];
-    int seeker_y[6];
-    bool xcol = false;
-    bool ycol = false;
-
+    int seeker_xpos = seeker_pos.x, seeker_ypos = seeker_pos.y;
+    int sxcol = 0;
+    int sycol = 0;
+    int ship_x[9],ship_y[6],seeker_x[9],seeker_y[6];
+    // printf("shipx = %d, shipy = %d\n",ship_xpos,ship_ypos);
     // create an array of all x positions for the ship sprite i.e along its width (ship_x)
-    for(int countx = 0; countx<=9; countx=countx+1) {
-        ship_x[countx] = ship_pos.x + countx;
-        seeker_x[countx] = seeker_pos.x + countx;
-        // printf("ship_x = %d, seeker_x = %d\n", ship_x[countx], seeker_x[countx]);
+    for(int cx = 0; cx<=9; cx=cx+1) {
+        ship_x[cx] = ship_xpos + cx;
+        seeker_x[cx] = seeker_xpos + cx;
+        // printf("ship_x = %d, seeker_x = %d\n", ship_x[cx], seeker_x[cx]);
     }
 
     // create an array of all y positions for the ship sprite i.e along its height (ship_y)
-    for(int county = 0; county<=6; county=county+1) {
-        ship_y[county] = ship_pos.y + county;
-        seeker_y[county] = seeker_pos.y + county;
-        //printf("ship_y = %d, seeker_y = %d\n", ship_y[county], seeker_y[county]);
+    for(int cy = 0; cy<=6; cy=cy+1) {
+        ship_y[cy] = (ship_ypos ) + cy ;
+        seeker_y[cy] = seeker_ypos + cy;
+        // printf("ship_y = %d, seeker_y = %d\n", ship_y[cy], seeker_y[cy]);
     }
     // check all values of ship position against all values of seekers x position
     for(int nx = 0; nx<=9; nx=nx+1) {
         for(int mx = 0; mx<=9; mx=mx+1) {
             if(ship_x[nx] == seeker_x[mx]) {
-                xcol = true;
+                sxcol = 1;
             }
         }
     }
     for(int ny = 0; ny<=6; ny=ny+1) {
         for(int my = 0; my<=6; my=my+1) {
             if(ship_y[ny] == seeker_y[my]) {
-                ycol = true;
+                sycol = 1;
             }
         }
     }
 
-    printf("xcol = %d, ycol = %d\n", xcol, ycol);
-    if(xcol == true && ycol == true) {
+    printf("sxcol = %d, sycol = %d\n", sxcol, sycol);
+    if(sxcol == 1 && sycol == 1) {
         _health.update(1);
         _enemy.reset_seeker();
     }
 }
 void RosenEngine::check_enemy_projectile_collision()
 {
-    Vector2D ship_pos = _ship.get_pos();
-    int lazer_x[3];
-    int seeker_x[9];
-    int seeker_y[38];
-    bool xcol = false;
+    Vector2D seeker_pos = _enemy.get_seekerpos();
+    int lazer_x[3],seeker_x[9],seeker_y[38];
+    int wxcol = 0;
+    int wycol = 0;
 
     // get seekers x any y values and put into arrays
-    Vector2D seeker_pos = _enemy.get_seekerpos();
-    for(int countx = 0; countx<=9; countx=countx+1) {
-        seeker_x[countx] = seeker_pos.x + countx;
+    for(int cx = 0; cx<=9; cx=cx+1) {
+        seeker_x[cx] = seeker_pos.x + cx;
     }
-    for(int county = 0; county<=6; county=county+1) {
-        seeker_y[county] = seeker_pos.y + county;
+    for(int cy = 0; cy<=6; cy=cy+1) {
+        seeker_y[cy] = seeker_pos.y + cy;
     }
-    // kestrel canon
+
+    // kestrel artemis missle
     if(_shipno == 0) {
+        Vector2D missle_pos = _weapons.get_pos(_shipno);
 
+        for(int cx = 0; cx<=9; cx=cx+1) {
+            seeker_x[cx] = seeker_pos.x + cx;
+            if(seeker_x[cx] == missle_pos.x) {
+                // printf("seeker_xpos = %f, missle_xpos = %f\n",seeker_pos.x,missle_pos.x);
+                wxcol = 1;
+            }
+        }
+        for(int cy = 0; cy<=7; cy=cy+1) {
+            seeker_y[cy] = seeker_pos.y + cy;
+            if(seeker_y[cy] == missle_pos.y) {
+                // printf("seeker_ypos = %f, missle_ypos = %f\n",seeker_pos.y,missle_pos.y);
+                wycol = 1;
+            }
+        }
+        if(wxcol == 1 && wycol == 1) {
+            _enemy.reset_seeker();
+        }
     }
-    
-    // imperion lazer
+
+
+// imperion lazer
     if(_shipno == 1) {
-        for(int countx = 0; countx<=3; countx=countx+1) {
-            lazer_x[countx] = (ship_pos.x + 2) + countx;
+        for(int cx = 0; cx<=3; cx=cx+1) {
+            lazer_x[cx] = (ship_xpos + 2) + cx;
         }
         // ony register collision if seeker is above ship
-        if(seeker_pos.y + 6 < ship_pos.y) {
+        if(seeker_pos.y + 6 < ship_ypos) {
             // check all values of ship position against all values of seekers x position
             for(int nx = 0; nx<=3; nx=nx+1) {
                 for(int mx = 0; mx<=9; mx=mx+1) {
                     if(lazer_x[nx] == seeker_x[mx]) {
-                        xcol = true;
+                        wxcol = 1;
                     }
                 }
             }
         }
-        if(xcol == true && A == true) {
+        if(wxcol == 1 && A == true) {
             _enemy.reset_seeker();
         }
-
     }
-
 }
\ No newline at end of file