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:
8:dd1037c5435b
Parent:
7:0af4ced868f5
Child:
9:1ddb8dc93e48
--- a/main.cpp	Sat Apr 18 16:36:52 2020 +0000
+++ b/main.cpp	Sun Apr 19 17:46:57 2020 +0000
@@ -16,19 +16,22 @@
 #include "N5110.h"
 #include "Spaceship.h"
 #include "Map.h"
+#include "GameEngine.h"
 
 
 // Objects
 Gamepad pad;
 N5110 lcd;
 Ticker ticker;
-Spaceship spaceship;
+GameEngine engine;
 AnalogIn pot_1(PTB2);
+Spaceship spaceship;
 Map map;
+AnalogIn adc(PTD5);
+
 
 // Global varable definitions 
 volatile int g_lcd_frame_time_flag = 0;  
-int move_map = 0 ; 
 
 // Function definitions 
 void lcd_frame_time_isr();
@@ -37,45 +40,17 @@
 { 
     // Sets fram rate of lcd by using time-triggered tasks
     ticker.attach(&lcd_frame_time_isr,0.03);
-    
-    pad.init();
-    lcd.init();
-    spaceship.init();
-    map.init();
-    lcd.setContrast(0.45);
-    lcd.refresh(); 
-    spaceship.draw(lcd);
+    engine.init(lcd, spaceship, map, pad, adc);
     
     while (1) {
+        
         // Checks flag and prints spaceship on lcd then resets flag
         if (g_lcd_frame_time_flag) {
-            g_lcd_frame_time_flag = 0;
-            
-           
-            
-            lcd.setContrast(pot_1.read());
-            //spaceship.clear_spaceship(lcd);
-            lcd.clear();
-            spaceship.movement(pad);
-            spaceship.draw(lcd);
-            
-            int position_x_spaceship_= spaceship.get_position_x_spaceship();
-            //usb.printf("position_x_spaceship_ = %d\n", position_x_spaceship_);
+            g_lcd_frame_time_flag = 0; // resets flag 
             
-            Direction joystick_direction = pad.get_direction();
-            //usb.printf("joystick_direction = %d\n", joystick_direction);
-            
-            if (position_x_spaceship_ == 22 && joystick_direction != CENTRE){
-                move_map = 1;
-            }else if (position_x_spaceship_ == 52 && joystick_direction != CENTRE){ 
-                move_map = -1;  
-            }else {
-                move_map = 0;
-            } 
-            
-            map.draw_map(lcd, move_map); 
-            lcd.refresh();     
+            engine.gameplay_loop(lcd, spaceship, map, pad, pot_1);   
         }
+        
         // MCU put to sleep between each frame to save power 
         sleep();   
     }