Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

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