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.

Revision:
17:25d79cca203a
Parent:
16:1ee3d3804557
Child:
18:11068b98e261
--- a/GameEngine/GameEngine.cpp	Tue Apr 28 23:31:22 2020 +0000
+++ b/GameEngine/GameEngine.cpp	Wed Apr 29 12:35:14 2020 +0000
@@ -14,7 +14,6 @@
     spaceship.init();
     map.init(pad);
     move_map_= 0;
-
 }
 
 void GameEngine::gameplay_loop() {
@@ -25,45 +24,45 @@
     // Gets movements  
     read_joystick_direction();
     spaceship.movement(d_);
-    calculate_map_movement();
+    weapons.calc_bullets_start_pos(spaceship.get_pos(),spaceship.get_spaceship_sprite_direction());
     
     // Redraws 
     spaceship.draw(lcd);
-    map.draw_map(lcd, move_map_);
-    
+    map.draw_map(lcd, calc_map_movement());
+
     //refresh's screen
     lcd.refresh(); 
     
-    
-    //draws map again so when moveing mountains are vitable on screen
+    //draws map again and refreshes screen so map moves faster than spaceship but doesnt require double pixel moement 
     map.draw_map(lcd, move_map_);
     lcd.refresh();
 }
 
-void GameEngine::calculate_map_movement(){ 
+int GameEngine::calc_map_movement(){ 
     // Gets postition of spaceship and sprite direction      
-    int position_x_spaceship_= spaceship.get_position_x_spaceship();      
-    
-     
+    Vector2D spaceship_pos= spaceship.get_pos();      
+
     // moves the map in oposite direction to spaceship when it's position is at min and max x positions and joystick has direction     
     if (d_ == W || d_ == NW || d_ == SW){
         move_map_ = 1;
         
         // moves map fater when changing direction to offset ship 
-        if (position_x_spaceship_ != 57){
-            move_map_ = 1;
+        if (spaceship_pos.x != 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;
+        if (spaceship_pos.x != 14){
+           move_map_ = -1;
         } 
     }else {
-        move_map_ = 0;
+         move_map_ = 0;
     }
     
+    return move_map_;
+    
     // Debug and check variables when function is called 
     #ifdef CALCULATE_MAP_MOVEMENT_DEBUG   
         printf("move map = %d\n", move_map_);