Mortal Kombat Game ELEC2645

Dependencies:   mbed N5110 ShiftReg Joystick

Revision:
18:22bda659c70a
Parent:
14:7f23841685ad
Child:
19:6c63e1dd7c85
--- a/main.cpp	Tue Apr 27 23:21:21 2021 +0000
+++ b/main.cpp	Thu Apr 29 22:40:08 2021 +0000
@@ -6,8 +6,8 @@
 #include "Menu.h"
 #include "Enemy.h"
 #include "GameEngine.h"
-///////////// defines /////////////////////
-#define GROUND         34
+///////////// definitions /////////////////
+#define HEALTH          30
 ///////////// objects /////////////////////
 GameEngine game;
 Fighter fighter;
@@ -25,29 +25,27 @@
 //////////// functions ////////////////////
 void init();
 void menu_screen();
-void move_sprite();
 void draw_background();
-void move_enemy();
+void game_over(int loser);
 
 
 int main() {
     init();
+    // int fighter_health = game.get_fighter_health();
     // menu_screen();
     while(1) {
         lcd.clear();
         draw_background();
-        // fighter.move_fighter(lcd, buttonA, buttonB, buttonC, buttonD, joy_v, joy_h);
         game.start(lcd, buttonA, buttonB, buttonC, buttonD, joy_v, joy_h);
         lcd.refresh();
-        wait(0.22);
+        wait(0.2);
     }
 }
 
 void init() { // initialize all devices
     lcd.init();
     lcd.setContrast(0.5);
-    game.init();
-    // fighter.init();
+    game.init(lcd, buttonA, buttonB, buttonC);
 }
 
 void menu_screen() {
@@ -67,89 +65,11 @@
         lcd.drawLine(82,46,82,25,1);   // draws second side wall
         lcd.refresh();
     }
+    
 
+void game_over(int loser) {
+    lcd.clear(); 
+    lcd.printString(" Game Over! ",15,2);
+    }
 
 
-/*
-// IGNORE THIS FUNCTION FOR NOW (look at fighter class function 'draw')
-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);
-            
-        }
-        if (buttonB.read() == 1) {
-            enemy.sword_left(lcd);  // draw kick on same coordinates as the sprite
-            
-        }
-    }
-}
-*/
-
-