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:
7:0af4ced868f5
Parent:
6:12e8433382b3
Child:
8:dd1037c5435b
--- a/main.cpp	Thu Apr 16 16:25:53 2020 +0000
+++ b/main.cpp	Sat Apr 18 16:36:52 2020 +0000
@@ -27,7 +27,8 @@
 Map map;
 
 // Global varable definitions 
-volatile int g_lcd_frame_time_flag = 0;   
+volatile int g_lcd_frame_time_flag = 0;  
+int move_map = 0 ; 
 
 // Function definitions 
 void lcd_frame_time_isr();
@@ -35,7 +36,7 @@
 int main()
 { 
     // Sets fram rate of lcd by using time-triggered tasks
-    ticker.attach(&lcd_frame_time_isr,0.04);
+    ticker.attach(&lcd_frame_time_isr,0.03);
     
     pad.init();
     lcd.init();
@@ -50,11 +51,29 @@
         if (g_lcd_frame_time_flag) {
             g_lcd_frame_time_flag = 0;
             
+           
+            
             lcd.setContrast(pot_1.read());
-            spaceship.clear_spaceship(lcd);
+            //spaceship.clear_spaceship(lcd);
+            lcd.clear();
             spaceship.movement(pad);
             spaceship.draw(lcd);
-            map.draw_triangle(lcd); 
+            
+            int position_x_spaceship_= spaceship.get_position_x_spaceship();
+            //usb.printf("position_x_spaceship_ = %d\n", position_x_spaceship_);
+            
+            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();     
         }
         // MCU put to sleep between each frame to save power