Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

https://os.mbed.com/media/uploads/evanso/84bc1a30759fd6a1e3f1fd1fae3e97c2.png

Hello, soldier, you have been specially selected as the defender of planet earth.

Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.

But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.

As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.

Files at this revision

API Documentation at this revision

Comitter:
evanso
Date:
Tue Apr 28 23:31:22 2020 +0000
Parent:
15:90b6821bcf64
Child:
17:25d79cca203a
Commit message:
Began work on weapons class. slightly changed map movement and spaceship movement functions to adjust where the spaceship sits on the screen when moving, in order to allow space for bullets.

Changed in this revision

GameEngine/GameEngine.cpp Show annotated file Show diff for this revision Revisions of this file
GameEngine/GameEngine.h Show annotated file Show diff for this revision Revisions of this file
Spaceship/Spaceship.cpp Show annotated file Show diff for this revision Revisions of this file
Spaceship/Spaceship.h Show annotated file Show diff for this revision Revisions of this file
Spaceship/Spaceship_test.h Show annotated file Show diff for this revision Revisions of this file
Weapons/Weapons.cpp Show annotated file Show diff for this revision Revisions of this file
Weapons/Weapons.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
test.h Show annotated file Show diff for this revision Revisions of this file
--- a/GameEngine/GameEngine.cpp	Tue Apr 28 19:13:12 2020 +0000
+++ b/GameEngine/GameEngine.cpp	Tue Apr 28 23:31:22 2020 +0000
@@ -33,17 +33,33 @@
     
     //refresh's screen
     lcd.refresh(); 
+    
+    
+    //draws map again so when moveing mountains are vitable on screen
+    map.draw_map(lcd, move_map_);
+    lcd.refresh();
 }
 
 void GameEngine::calculate_map_movement(){ 
-    // Gets postition of spaceship       
+    // Gets postition of spaceship and sprite direction      
     int position_x_spaceship_= spaceship.get_position_x_spaceship();      
-   
+    
+     
     // moves the map in oposite direction to spaceship when it's position is at min and max x positions and joystick has direction     
-    if (position_x_spaceship_ == 21 && d_ != CENTRE){
+    if (d_ == W || d_ == NW || d_ == SW){
         move_map_ = 1;
-    }else if (position_x_spaceship_ == 53 && d_ != CENTRE){ 
-        move_map_ = -1;  
+        
+        // moves map fater when changing direction to offset ship 
+        if (position_x_spaceship_ != 57){
+            move_map_ = 1;
+        }
+    }else if (d_ == E || d_ == NE || d_ == SE){ 
+        move_map_ = -1; 
+        
+        // moves map fater when changing direction to offset ship
+        if (position_x_spaceship_ != 14){
+            move_map_ = -1;
+        } 
     }else {
         move_map_ = 0;
     }
--- a/GameEngine/GameEngine.h	Tue Apr 28 19:13:12 2020 +0000
+++ b/GameEngine/GameEngine.h	Tue Apr 28 23:31:22 2020 +0000
@@ -46,6 +46,9 @@
         // Changes the drawing x postion of map, 1 moves right, -1 moves left and 0 doesnt change map position 
         int move_map_;
         
+        // // Changes the drawing x postion of map, 1 moves right, -1 moves left and 0 doesnt change map position 
+        int offset_map_;
+        
         // Direction of joystick
         Direction d_; 
     
--- a/Spaceship/Spaceship.cpp	Tue Apr 28 19:13:12 2020 +0000
+++ b/Spaceship/Spaceship.cpp	Tue Apr 28 23:31:22 2020 +0000
@@ -27,7 +27,7 @@
     position_y_spaceship_ = 22;
     
     // sets origonal spaceship direction to facing East
-    spaceship_sprite_direction_ = true; 
+    spaceship_sprite_direction_ = true;
 }
  
 void Spaceship::draw(N5110 &lcd) {
@@ -52,10 +52,10 @@
     }  
     
     // checks x postion of spaceship and alters x position 
-    if (position_x_spaceship_ > 52) {
-        position_x_spaceship_ = 52;
-    }else if (position_x_spaceship_ < 22) {
-        position_x_spaceship_ = 22;
+    if (position_x_spaceship_ > 56) {
+        position_x_spaceship_ = 56;
+    }else if (position_x_spaceship_ < 15) {
+        position_x_spaceship_ = 15;
     }
 }   
  
@@ -64,13 +64,13 @@
     switch (d_) {
     case CENTRE: set_spaceship_peram(0, 0, false , false); break;
     case N: set_spaceship_peram(0, -1, false , false); break;
-    case NE: set_spaceship_peram(1, -1, true, true); break;
-    case E: set_spaceship_peram(1, 0, true, true); break;
-    case SE: set_spaceship_peram(1, 1, true, true); break;
+    case NE: set_spaceship_peram(-1, -1, true, true); break;
+    case E: set_spaceship_peram(-1, 0, true, true); break;
+    case SE: set_spaceship_peram(-1, 1, true, true); break;
     case S: set_spaceship_peram(0, 1, false, false); break;
-    case SW: set_spaceship_peram(-1, 1, true, false); break;
-    case W: set_spaceship_peram(-1, 0, true, false); break;
-    case NW: set_spaceship_peram(-1, -1, true, false); break;
+    case SW: set_spaceship_peram(1, 1, true, false); break;
+    case W: set_spaceship_peram(1, 0, true, false); break;
+    case NW: set_spaceship_peram(1, -1, true, false); break;
     }
     //printf("y= %d\n", position_y_spaceship_);
 }
@@ -85,6 +85,7 @@
     }
 }
 
+
 int Spaceship::get_position_x_spaceship(){
     return position_x_spaceship_;
 }
--- a/Spaceship/Spaceship.h	Tue Apr 28 19:13:12 2020 +0000
+++ b/Spaceship/Spaceship.h	Tue Apr 28 23:31:22 2020 +0000
@@ -40,22 +40,28 @@
          */
         int get_position_x_spaceship();
         
-         /** Gets the y postion of spaceship 
+        /** Gets the y postion of spaceship 
          * @return position_y_spaceship_ 
          */
         int get_position_y_spaceship();
         
+        /** Gets sprtie directon if spaceship 
+         * @details true = east, false = west
+         * @return spaceship_sprite_direction_ 
+         */
+        bool get_spaceship_sprite_direction(); 
+        
     private:
     // Function prototypes -----------------------------------------------------
     
-       /** Sets the x, y position and sprite direction of the spaceship for movement function  
-        * @peram x_change, y_change, sprite_change, sprite_param 
-        */
+        /** Sets the x, y position and sprite direction of the spaceship for movement function  
+         * @peram x_change, y_change, sprite_change, sprite_param 
+         */
         void set_spaceship_peram(int x_change,int y_change, bool sprite_change, bool sprite_param);
         
-       /** Checks sapceship x and y position and stops spacship comming of the screen in y direction
-        * holds spaceship in middle 3rd of screen in x direction 
-        */
+        /** Checks sapceship x and y position and stops spacship comming of the screen in y direction
+         * holds spaceship in middle 3rd of screen in x direction 
+         */
         void off_screen_x_y_checker();
         
     // Variables ---------------------------------------------------------------
@@ -68,7 +74,7 @@
         
         // Boolean flag for if sprite direction is changed
         bool spaceship_sprite_direction_;
-    
+        
 };
  
 #endif
\ No newline at end of file
--- a/Spaceship/Spaceship_test.h	Tue Apr 28 19:13:12 2020 +0000
+++ b/Spaceship/Spaceship_test.h	Tue Apr 28 23:31:22 2020 +0000
@@ -72,7 +72,7 @@
         return true;
     } else {
         printf ( "Failed! value = %d  (expecting  %d)\n", actual_pixel_status, expected_pixel_status);
-        printf("\nactual psotion x,y= %d,%d : \n ",finish_x_postion, finish_y_postion );
+        // printf("\nactual psotion x,y= %d,%d : \n ",finish_x_postion, finish_y_postion );
         return false;
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weapons/Weapons.cpp	Tue Apr 28 23:31:22 2020 +0000
@@ -0,0 +1,16 @@
+#include "Weapons.h"
+
+Weapons::Weapons() {
+    
+}
+ 
+Weapons::~Weapons() {
+    
+}
+ 
+void Weapons::init() {
+}
+
+void Weapons::draw_laser_bullets(N5110 &lcd, int position_x_spaceship_, int position_y_spaceship_, bool spaceship_sprite_direction_){
+   
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weapons/Weapons.h	Tue Apr 28 23:31:22 2020 +0000
@@ -0,0 +1,46 @@
+#ifndef SPACESHIP_H
+#define SPACESHIP_H
+ 
+// Included libraries -----------------------------------------------------------
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+
+/** Weapons class
+@brief Draws and moves weapons 
+@author Benjamin Evans, University of Leeds
+@date April 2020
+*/
+ 
+class Weapons {
+    public:
+        /** Constructor */
+        Weapons();
+        
+        /** Destructor */
+        ~Weapons();
+        
+        /** Initalises Weapons */
+        void init();
+        
+        /** Draws laser bullets
+         * @param lcd, paosition_x_spaceship_, position_y_spaceship_ @details : N5110 object, x and y spaceship positions
+         */
+        void draw_laser_bullets(N5110 &lcd, int position_x_spaceship_, int position_y_spaceship_, bool spaceship_sprite_direction_);
+        
+        // Accessors and mutators -----------------------------------------------
+        
+    private:
+    // Function prototypes -----------------------------------------------------
+        
+    // Variables ---------------------------------------------------------------
+    
+        // Spaceships x position on lcd
+        int position_x_bullets_;
+        
+        // Spaceships y position on lcd
+        int position_y_bullets_;
+    
+};
+ 
+#endif
\ No newline at end of file
--- a/main.cpp	Tue Apr 28 19:13:12 2020 +0000
+++ b/main.cpp	Tue Apr 28 23:31:22 2020 +0000
@@ -23,9 +23,7 @@
 #endif
 
 // TO DO
-// Add map movement for gam engine test 
-// add debug funtion like fin does for random arrays 
-//sort order of gamplay loo
+// change test so they work with new map 
 
 // Objects ---------------------------------------------------------------------
 
--- a/test.h	Tue Apr 28 19:13:12 2020 +0000
+++ b/test.h	Tue Apr 28 23:31:22 2020 +0000
@@ -19,13 +19,13 @@
     // Runs test with all posible movment directions 
     if (spaceship_movement_test(CENTRE, 36, 22)) passed_counter++;
     if (spaceship_movement_test(N, 36, 21)) passed_counter++;
-    if (spaceship_movement_test(NE, 37, 21)) passed_counter++;
-    if (spaceship_movement_test(E, 37, 22)) passed_counter++;
-    if (spaceship_movement_test(SE, 37, 23)) passed_counter++;
+    if (spaceship_movement_test(NE, 35, 21)) passed_counter++;
+    if (spaceship_movement_test(E, 35, 22)) passed_counter++;
+    if (spaceship_movement_test(SE, 35, 23)) passed_counter++;
     if (spaceship_movement_test(S, 36, 23)) passed_counter++;
-    if (spaceship_movement_test(SW, 35, 23)) passed_counter++;
-    if (spaceship_movement_test(W, 35, 22)) passed_counter++;
-    if (spaceship_movement_test(NW, 35, 21)) passed_counter++;
+    if (spaceship_movement_test(SW, 37, 23)) passed_counter++;
+    if (spaceship_movement_test(W, 37, 22)) passed_counter++;
+    if (spaceship_movement_test(NW, 37, 21)) passed_counter++;
     
     // prints results
     printf ("\nspaceship_movement_test passed %d tests out of 9\n",passed_counter);
@@ -36,10 +36,10 @@
     int passed_counter = 0;
     
     // Runs test with max movement directions 
-    if (spaceship_draw_test(NE, 1, 52, 0)) passed_counter++;
-    if (spaceship_draw_test(SE, 1, 52, 44)) passed_counter++;
-    if (spaceship_draw_test(SW, 1, 32, 44)) passed_counter++;
-    if (spaceship_draw_test(NW, 1, 32, 0)) passed_counter++;
+    if (spaceship_draw_test(NE, 1, 15, 0)) passed_counter++;
+    if (spaceship_draw_test(SE, 1, 15, 44)) passed_counter++;
+    if (spaceship_draw_test(SW, 1, 64, 44)) passed_counter++;
+    if (spaceship_draw_test(NW, 1, 64, 0)) passed_counter++;
     
     // prints results
     printf ("\nspaceship_draw_test passed %d tests out of 4\n",passed_counter);