ELEC2645 (2018/19) / Mbed 2 deprecated el17dg

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Revision:
8:c18c240665aa
Parent:
7:42376925945c
Child:
9:5ad5501c702e
--- a/game/game.cpp	Mon Mar 11 09:52:00 2019 +0000
+++ b/game/game.cpp	Mon Mar 11 14:48:49 2019 +0000
@@ -7,6 +7,7 @@
 #include "models.h"
 #include "main.h"
 #include "game.h"
+#include "enemy.h"
 
 //int x_ship_origin = 0;
 //int y_ship_origin = 24;
@@ -20,27 +21,26 @@
 int start_blast_x_position = 0;
 int start_blast_y_position = 0;
 
-const int ship_step_incremetion = 2;
+const int ship_speed = 2;
+const int blaster_speed = 2;
 bool is_fire_shot = false;
 
+Enemy enemy;
 
 bool Game::updateAndDraw() {
 
     shipMovment();
+    enemy.enemyMovement();
     
     if (gamepad.check_event(gamepad.B_PRESSED)){
         is_fire_shot = true;
         start_blast_x_position = x_ship_pos + spaceship1_width;
         start_blast_y_position = y_ship_pos + (spaceship1_height/2);        /////////////////////////////////////////////
     }
-    if (is_fire_shot){
-        
-    shipFire();
     
-    }    
+    if (is_fire_shot){ shipFire(); }    
     
-    
-    lcd.drawSprite(x_ship_pos, y_ship_pos, spaceship1_width, spaceship1_height, spaceShip1);
+    lcd.drawSprite(x_ship_pos, y_ship_pos, spaceship1_width, spaceship1_height, (int *)spaceShip1);
     printf("%i\n", fire_shot_traveled);
     /*char buffer[4];
     sprintf(buffer,"%i\n",(int)(x_dir.read()*84));
@@ -59,10 +59,10 @@
         
     if(x_ship_pos <= 48 && x_ship_pos >= 0){
         if(x_dir.read() > 0.6f){
-           x_ship_pos -= ship_step_incremetion;
+           x_ship_pos -= ship_speed;
         }
         else if(x_dir.read() < 0.4f){
-           x_ship_pos += ship_step_incremetion;
+           x_ship_pos += ship_speed;
         }
     } 
     
@@ -72,10 +72,10 @@
     
     if (y_ship_pos <= (47 - spaceship1_height) && y_ship_pos >= 0){
         if(y_dir.read() > 0.6f){
-           y_ship_pos -= ship_step_incremetion; 
+           y_ship_pos -= ship_speed; 
         }
         else if(y_dir.read() < 0.4f){
-           y_ship_pos += ship_step_incremetion; 
+           y_ship_pos += ship_speed; 
         }
     }
     else if (y_ship_pos >= (47 - spaceship1_height)){ y_ship_pos = 47 - spaceship1_height;}     //Limits for y direction border IMPROVE IF POSSIBLE.
@@ -88,21 +88,17 @@
 
 void Game::shipFire(){                          //IMPROVE OR SIMPLIFY - Make it into a spearate class so that I could do multiple shots at the same time.
     
-    //int shoot_begins_x = start_blast_x_position;
-    //int shoot_begins_y = start_blast_y_position;
-    
-    
     if (fire_shot_time_counter == 0){
-        lcd.drawSprite(start_blast_x_position, (start_blast_y_position), 1, 6, simpleLaserShot);
+        lcd.drawSprite(start_blast_x_position, (start_blast_y_position), 1, 3, (int *)simpleLaserShot);
               
     }
     else if (fire_shot_time_counter == 1){      ///////////////////////////////////////////////////////////////////////////////////////////////////
-        lcd.drawSprite(fire_shot_traveled, (start_blast_y_position), 1, 3, simpleLaserShotDissapear);
+        lcd.drawSprite(fire_shot_traveled, (start_blast_y_position), 1, 3, (int *)simpleLaserShotDissapear);
         
-        shot_step_counter += 3;
+        shot_step_counter += blaster_speed;
         fire_shot_traveled = start_blast_x_position + shot_step_counter;
         
-        lcd.drawSprite(fire_shot_traveled, (start_blast_y_position), 1, 3, simpleLaserShot);
+        lcd.drawSprite(fire_shot_traveled, (start_blast_y_position), 1, 3, (int *)simpleLaserShot);
         
         fire_shot_time_counter = 0;      
     }
@@ -117,5 +113,3 @@
         is_fire_shot = !is_fire_shot;   
     } 
 }
-
-