ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Revision:
43:500b8cff3715
Parent:
41:e1fa36c0492e
Child:
44:a6a361bea806
--- a/RosenEngine/RosenEngine.cpp	Wed May 08 09:22:16 2019 +0000
+++ b/RosenEngine/RosenEngine.cpp	Wed May 08 15:50:40 2019 +0000
@@ -73,23 +73,24 @@
         int index = inde.x;
         Vector2D closest = find_closest2(index);
         // Draw ships and weapons depending on the ship being used
-        switch (_shipno) {
-        case 0:
+        switch (_shipUsed) {
+        case kestrel:
             _ship.set_dimensions(9,6);
-            _ship.draw_ship(lcd,_shipno);
-            _weapons.draw(lcd,pad,_shipno,closest);
+            _ship.draw_ship(lcd,_shipUsed);
+            _weapons.draw(lcd,pad,_shipUsed,closest);
             break;
-        case 1:
+        case imperion:
             _ship.set_dimensions(7,10);
-            _ship.draw_ship(lcd,_shipno);
-            _weapons.draw(lcd,pad,_shipno,closest);
+            _ship.draw_ship(lcd,_shipUsed);
+            _weapons.draw(lcd,pad,_shipUsed,closest);
             break;
-        case 2:
+        case orion:
             _ship.set_dimensions(7,10);
-            _ship.draw_ship(lcd,_shipno);
-            _weapons.draw(lcd,pad,_shipno,closest);
+            _ship.draw_ship(lcd,_shipUsed);
+            _weapons.draw(lcd,pad,_shipUsed,closest);
             break;
     }
+    printf("_shipUsed = %d\n",_shipUsed);
 }
 
 void RosenEngine::update(Gamepad &pad)
@@ -97,6 +98,7 @@
     _enemy.update_seeker(_shipPos.x, _shipPos.y);
     _enemy.update_shooter(_shipPos.x, _shipPos.y);
     _enemy.update_shw();
+    set_shipUsed();
     update_shooter_weapon(pad);
     shooter_ship_collision(pad);
     seeker_ship_collision(pad);
@@ -112,18 +114,18 @@
 }
 void RosenEngine::update_shooter_weapon(Gamepad &pad)
 {
-    if(_shipno == 0) {
+    if(_shipUsed == kestrel) {
         _ship.update_ship(_joystick.x,_joystick.y);
         _weapons.update();
         kestrelw_seeker_collision(pad);
     }
     //printf("if shipno == 0\n");
-    if(_shipno == 1 && A == false) {
+    if(_shipUsed == imperion && A == false) {
         _ship.update_ship(_joystick.x,_joystick.y);
         _weapons.update();
     }
     //printf("if shipno == 1\n");
-    if(_shipno == 2) {
+    if(_shipUsed == orion) {
         _ship.update_ship(_joystick.x,_joystick.y);
         _weapons.update();
     }
@@ -147,16 +149,16 @@
 }
 void RosenEngine::set_ship_size()
 {
-    switch (_shipno) {
-        case 0:
+    switch (_shipUsed) {
+        case kestrel:
             _shipWidth = 9;
             _shipHeight = 6;
             break;
-        case 1:
+        case imperion:
             _shipWidth = 7;
             _shipHeight = 10;
             break;
-        case 2:
+        case orion:
             _shipWidth = 7;
             _shipHeight = 10;
             break;
@@ -178,6 +180,11 @@
     _shipno = _menu.get_xcursor();
     return _shipno;
 }
+SHIP RosenEngine::set_shipUsed()
+{
+    int shipno = _menu.get_xcursor();
+    _shipUsed = (SHIP)shipno;
+}
 void RosenEngine::ship_select(N5110 &lcd)
 {
     _menu.update(_d);
@@ -336,7 +343,7 @@
 {
     bool col1, col2, col3;
     int sel = 0;
-    Vector2D missle_pos = _weapons.get_pos(_shipno);
+    Vector2D missle_pos = _weapons.get_pos(_shipUsed);
     col1 = check_collision(_seekerPos[0].x,_seekerPos[0].y,9,6,missle_pos.x,missle_pos.y,1,1);
     col2 = check_collision(_seekerPos[1].x,_seekerPos[1].y,9,6,missle_pos.x,missle_pos.y,1,1);
     col3 = check_collision(_seekerPos[2].x,_seekerPos[2].y,9,6,missle_pos.x,missle_pos.y,1,1);
@@ -359,7 +366,7 @@
 {
     bool col1,col2,col3;
     int sel = 0;
-    if(_shipno == 1) {
+    if(_shipUsed == imperion) {
         if(_shipPos.y > _seekerPos[0].y + 6) {
             col1 = check_collision1(_seekerPos[0].x,9,_shipPos.x  + 2,3);
             if (col1 == true && A == true && _no_seekers >= 1) {
@@ -387,7 +394,7 @@
 }
 void RosenEngine::kestrelw_shooter_collision(Gamepad &pad)
 {
-    Vector2D missle_pos = _weapons.get_pos(_shipno);
+    Vector2D missle_pos = _weapons.get_pos(_shipUsed);
     bool col1, col2, col3;
     int sel = 0;
     col1 = check_collision(_shooterPos[0].x,_shooterPos[0].y,9,6,missle_pos.x,missle_pos.y,1,1);