Mortal Kombat Game ELEC2645

Dependencies:   mbed N5110 ShiftReg Joystick

Revision:
6:a1a7dc264fed
Parent:
3:1d99b6ad4f9e
Child:
18:22bda659c70a
diff -r 889ad974b64d -r a1a7dc264fed Abandoned.cpp
--- a/Abandoned.cpp	Tue Apr 20 09:01:35 2021 +0000
+++ b/Abandoned.cpp	Wed Apr 21 22:56:55 2021 +0000
@@ -1,6 +1,198 @@
-// This file includes abandoned code that was replaced because it did not work
+// This file includes abandoned code that was replaced 
+/*
+
+void move_sprite() {
+    // getting joystick coordinates using read() function
+    // joystick centered at (0.50,0.50) with utmost left at (1.00,0.50) and utmost right being (0.00,0.50)
+    // read each of the pins
+    float x = joy_h.read();
+    float y = joy_v.read();
+    printf("x = %.2f | y = %.2f \n",x,y);
+    // get x position of fighter
+    int x_pos = fighter.get_x();
+    printf("fighter x pos = %i \n", x_pos);
+    
+/ *
+Code idea:
+if joystick is not moved , display standing sprite
+if joystick is moved right, toggle between runright and midrunright
+if joystick is moved left, toggle between runleft and midrunleft
+* /
+    if(x > 0.48 && x < 0.52) { // joystick not moved - we use ± 0.02 to take account of fluctuation in joystick tolerance and noice on ADC
+          fighter.draw(lcd); // draw standing fighter 
+          lcd.refresh();
+          wait(0.3);
+
+           // Preform kick move if user presses button A
+        if (buttonA.read() == 1) {
+            fighter.kick_right(lcd);  // draw kick on same coordinates as the standing sprite
+            lcd.refresh();
+            wait(0.3);
+        }
+        // Preform punch move if user presses button B
+        if (buttonB.read() == 1) {
+            fighter.punch_right(lcd);  // draw kick 
+            lcd.refresh();
+            wait(0.3);
+        }
+        // Guard if user presses button C
+        while (buttonC.read() == 1) {
+            fighter.guard(lcd);  // draw guard move frame
+            lcd.refresh();
+            wait(0.3);
+        }
+    }
+    else if(x < 0.48) { //  joystick moved to the right
+        // print  the  move_right animation, refresh, then print the 2nd move_right animation (toggling animations to create moving legs!)
+        fighter.add_x(5);           // increment by 5
+        fighter.move_right(lcd);
+        lcd.refresh();
+        wait(0.1);
+        fighter.move_right2(lcd);
+        lcd.refresh();
+        wait(0.08);
+        
+        if (x_pos >= 65) {   // code to stop fighter moving out of lcd screen
+            fighter.add_x(-5);
+        }
+    
+        
+        // kick if user presses button A
+        if (buttonA.read() == 1) {
+                fighter.kick_right(lcd);
+                lcd.refresh();
+                wait(0.3);
+            }
+        // Preform punch move if user presses button B
+        if (buttonB.read() == 1) {
+            fighter.punch_right(lcd);  // draw kick on same coordinates as the sprite
+            lcd.refresh();
+            wait(0.3);
+        }
+        // Guard if user presses button C
+        while (buttonC.read() == 1) {       // we use while not if here because user would hold to guard 
+            fighter.guard(lcd);  // draw kick on same coordinates as the sprite
+            lcd.refresh();
+            wait(0.3);
+        }
+    }
+    
+    else if(x > 0.52) { // joystick moved to the left
+        fighter.add_x(-5);      // decrement left by 5
+        fighter.move_left(lcd);
+        lcd.refresh();
+        wait(0.1);
+        fighter.move_left2(lcd);
+        lcd.refresh();
+        wait(0.08);
+        
+        if (x_pos <= 6) {   // code to stop fighter moving out of lcd screen
+            fighter.add_x(5);
+        }
+
+    // kick if user presses button A
+        if (buttonA.read() == 1) {
+            fighter.kick_left(lcd);
+            lcd.refresh();
+            wait(0.3);
+        }
+        if (buttonB.read() == 1) {
+            fighter.punch_left(lcd);  // draw punch on same coordinates as the sprite
+            lcd.refresh();
+            wait(0.3);
+        }
+        // Guard if user presses button C
+        if (buttonC.read() == 1) {
+            fighter.guard(lcd);  // draw guard on same coordinates as the sprite
+            lcd.refresh();
+            wait(0.3);
+        }
+    }
+}
+
+void move_enemy() {
+    // read each of the pins
+    float x = joy_h.read();
+    float y = joy_v.read();
+    printf("x = %.2f | y = %.2f \n",x,y);
+    // get x position of enemy
+    int x_pos = enemy.get_x();
+    printf("enemy x pos = %i \n", x_pos);
+
+    if(x > 0.48 && x < 0.52) { // joystick not moved - we use ± 0.02 to take account of fluctuation in joystick tolerance and noice on ADC
+          enemy.draw(lcd); // draw enemy
+          lcd.refresh();
+          wait(0.3);
+       // Preform kick move if user presses button A
+        if (buttonA.read() == 1) {
+            enemy.kick_right(lcd);  // draw kick on same coordinates as the standing sprite
+            lcd.refresh();
+            wait(0.3);
+        }
+        // Preform punch move if user presses button B
+        if (buttonB.read() == 1) {
+            enemy.sword_right(lcd);  // draw sword move on same coordinates as the standing sprite
+            lcd.refresh();
+            wait(0.3);
+        }
+    }
+    else if(x < 0.48) { //  joystick moved to the right
+        enemy.add_x(5);           // increment by 5
+        // print  the  move_right animation, refresh, then print the 2nd move_right animation (toggling animations to create moving legs!)
+        enemy.move_right(lcd); // draw standing fighter, multiply by speed -69 (negative to correct for direction!)
+        lcd.refresh();
+        wait(0.1);
+        enemy.move_right2(lcd);
+        lcd.refresh();
+        wait(0.08);
+        
+        if (x_pos >= 65) {   // code to stop enemy moving out of lcd screen
+            enemy.add_x(-5);
+        }
+        
+        // kick if user presses button A
+        if (buttonA.read() == 1) {
+            enemy.kick_right(lcd);
+            lcd.refresh();
+            wait(0.3);
+        }
+        // Preform punch move if user presses button B
+        if (buttonB.read() == 1) {
+            enemy.sword_right(lcd);  // draw kick on same coordinates as the sprite
+            lcd.refresh();
+            wait(0.3);
+        }
+    }
+    else if(x > 0.52) { // joystick moved to the left
+        enemy.add_x(-5);           // decrement by 5
+        enemy.move_left(lcd);
+        lcd.refresh();
+        wait(0.1);
+        enemy.move_left2(lcd);
+        lcd.refresh();
+        wait(0.08);
+    
+    
+    if (x_pos <= 6) {   // code to stop enemy moving out of lcd screen
+            enemy.add_x(5);
+        }
+
+    // kick if user presses button A
+        if (buttonA.read() == 1) {
+            enemy.kick_left(lcd);
+            lcd.refresh();
+            wait(0.3);
+        }
+        if (buttonB.read() == 1) {
+            enemy.sword_left(lcd);  // draw kick on same coordinates as the sprite
+            lcd.refresh();
+            wait(0.3);
+        }
+    }
+}
 
 /*
+
 int get_user_input(int &input) {
     while (1) {
         if (buttonA.read() == 1) {