ELEC2645 (2018/19) / Mbed 2 deprecated el17dg

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Files at this revision

API Documentation at this revision

Comitter:
Noximilien
Date:
Mon Mar 04 20:15:55 2019 +0000
Parent:
4:02c63aaa2df9
Child:
6:100b46be4bea
Commit message:
Have made the ship moving around in the "start game". Have done 4 different models of stars and a model of a blaster. Have made that the ship would not leave the set border limit (beyond the screen).

Changed in this revision

Models/models.h Show annotated file Show diff for this revision Revisions of this file
game/game.cpp Show annotated file Show diff for this revision Revisions of this file
game/game.h Show annotated file Show diff for this revision Revisions of this file
main/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Models/models.h	Sun Mar 03 23:36:34 2019 +0000
+++ b/Models/models.h	Mon Mar 04 20:15:55 2019 +0000
@@ -4,25 +4,64 @@
 #include "mbed.h"
 #include "N5110.h"
 #include "Gamepad.h"
-
-
+#include "main.h"
 
 
 
 
 
-int SpaceShip1[210] = {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
-                       0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,
-                       0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,
-                       0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,
-                       1,0,1,0,0,1,1,1,1,1,0,0,1,0,1,
-                       0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,
-                       0,1,1,1,1,0,0,0,0,0,1,1,1,1,0,
-                       0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,
-                       0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,
-                       0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,
-                       0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,
-                       0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,
-                       0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
-                       0,0,0,0,0,0,0,1,0,0,0,0,0,0,0
-                      };
\ No newline at end of file
+int spaceship1_width = 15;
+int spaceship1_height = 14;
+
+int spaceShip1[210] = {
+    0,0,0,0,0,0,0,0,0,1,0,0,0,0,
+    0,0,0,0,0,0,0,1,1,0,0,0,0,0,
+    0,0,0,0,0,0,0,1,0,1,0,0,0,0,
+    0,0,0,0,1,1,1,1,0,0,0,0,0,0,
+    0,0,0,0,1,0,0,1,0,0,0,0,0,0,
+    0,0,1,1,1,0,0,0,1,1,1,1,0,0,
+    0,0,0,1,1,0,1,0,0,1,0,0,1,0,
+    1,1,1,0,1,1,0,0,0,1,1,0,0,1,
+    0,0,0,1,1,0,1,0,0,1,0,0,1,0,
+    0,0,1,1,1,0,0,0,1,1,1,1,0,0,
+    0,0,0,0,1,0,0,1,0,0,0,0,0,0,
+    0,0,0,0,1,1,1,1,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,1,0,1,0,0,0,0,
+    0,0,0,0,0,0,0,1,1,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,1,0,0,0,0
+};
+
+void starMinor(int x, int y){
+    lcd.setPixel(x,y,true);
+}
+
+int starSmall[9] = {
+    0,1,0,
+    1,1,1,
+    0,1,0
+};
+
+int starMedium[25] = {
+    1,0,0,0,1,
+    0,1,1,1,0,
+    0,1,1,1,0,
+    0,1,1,1,0,
+    1,0,0,0,1
+};
+
+int starBig[49] = {
+    1,0,0,1,0,0,1,
+    0,1,0,1,0,1,0,
+    0,0,1,1,1,0,0,
+    1,1,1,1,1,1,1,
+    0,0,1,1,1,0,0,
+    0,1,0,1,0,1,0,
+    1,0,0,1,0,0,1
+};
+
+int simpleLaserShot[3] = {1,1,1};
+    
+
+
+
+
--- a/game/game.cpp	Sun Mar 03 23:36:34 2019 +0000
+++ b/game/game.cpp	Mon Mar 04 20:15:55 2019 +0000
@@ -5,12 +5,25 @@
 #include "Gamepad.h"
 
 #include "models.h"
-
 #include "main.h"
 #include "game.h"
 
+//int x_ship_origin = 0;
+//int y_ship_origin = 24;
+
+int x_ship_pos = 0;
+int y_ship_pos = 24;
+const int ship_step_incremetion = 2;
+
 bool Game::updateAndDraw() {
-    lcd.printString("Game is running", 1, 3);
+    
+    
+    shipMovment();
+    lcd.drawSprite(x_ship_pos, y_ship_pos, spaceship1_width, spaceship1_height, spaceShip1);
+    
+    /*char buffer[4];
+    sprintf(buffer,"%i\n",(int)(x_dir.read()*84));
+    printf(buffer);*/
     
     bool want_to_pause = false;
     if (gamepad.check_event(gamepad.START_PRESSED)){
@@ -18,3 +31,43 @@
     }
     return want_to_pause;
 }
+
+
+void Game::shipMovment(){           // The position of the ship
+        
+    if(x_ship_pos <= 48 && x_ship_pos >= 0){
+        if(x_dir.read() > 0.6f){
+           x_ship_pos -= ship_step_incremetion;
+        }
+        else if(x_dir.read() < 0.4f){
+           x_ship_pos += ship_step_incremetion;
+        }
+    } 
+    
+    else if (x_ship_pos <= 48){ x_ship_pos = 0;}     //Limits for x direction border IMPROVE IF POSSIBLE.
+    else { x_ship_pos = 48;}
+    
+    
+    if (y_ship_pos <= (47 - spaceship1_height) && y_ship_pos >= 0){
+        if(y_dir.read() > 0.6f){
+           y_ship_pos -= ship_step_incremetion; 
+        }
+        else if(y_dir.read() < 0.4f){
+           y_ship_pos += ship_step_incremetion; 
+        }
+    }
+    else if (y_ship_pos >= (47 - spaceship1_height)){ y_ship_pos = 47 - spaceship1_height;}     //Limits for y direction border IMPROVE IF POSSIBLE.
+    else if (y_ship_pos < 0){ y_ship_pos = 0;}
+       
+}
+
+
+void Game::shipFire(){
+    //if (gamepad.check_event(gamepad.B_PRESSED){
+        
+    //}
+    
+    
+}
+
+
--- a/game/game.h	Sun Mar 03 23:36:34 2019 +0000
+++ b/game/game.h	Mon Mar 04 20:15:55 2019 +0000
@@ -6,6 +6,8 @@
 public:
     bool updateAndDraw();  
 private:
+    void shipMovment();
+    void shipFire();
     
 };
 
--- a/main/main.cpp	Sun Mar 03 23:36:34 2019 +0000
+++ b/main/main.cpp	Mon Mar 04 20:15:55 2019 +0000
@@ -37,8 +37,6 @@
 //char line_buffer[MAX_LINE_LENGTH];
 
 
-int x_movement = 20;
-int y_movement = 30;
 
 ScreenOption current_screen = ScreenOption_Menu;
 
@@ -66,7 +64,6 @@
             }
         }
         
-        
         lcd.refresh();
         wait_ms(1000/10);
     }