ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Revision:
3:28a3c118e071
Parent:
2:16ae940b0aee
Child:
4:ce4eea1c2a28
--- a/main.cpp	Wed Mar 13 15:10:36 2019 +0000
+++ b/main.cpp	Sat Mar 16 10:38:04 2019 +0000
@@ -15,98 +15,6 @@
 Gamepad gamepad;
 Skateboarder skater;  
 
-int skate_right[17][12] =   {
-    
-    { 0,0,0,0,1,1,1,0,0,0,0,0 },
-    { 0,0,0,0,1,1,1,1,0,0,0,0 },
-    { 0,0,1,1,1,1,1,1,0,0,0,0 },
-    { 0,0,0,0,1,0,1,1,0,0,0,0 },
-    { 0,0,0,0,1,1,1,0,0,0,0,0 },
-    { 0,0,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,1,1,1,1,1,1,1,0,0,0 },
-    { 0,1,1,0,1,1,0,0,1,1,0,0 },
-    { 0,1,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,0,0,1,0,1,0,0,0,0,0 },
-    { 0,0,0,0,1,0,0,1,0,0,0,0 },
-    { 0,1,0,0,1,0,0,0,1,0,1,0 },
-    { 0,0,1,1,1,1,1,1,1,1,0,0 },
-    { 0,0,0,1,0,0,0,0,1,0,0,0 },
-    
-    
-};
-
-int skate_left[17][12] =   {
-    
-    { 0,0,0,0,1,1,1,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,1,1,0,0,0 },
-    { 0,0,0,1,1,0,1,0,0,0,0,0 },
-    { 0,0,0,0,1,1,1,0,0,0,0,0 },
-    { 0,0,0,0,0,1,1,0,0,0,0,0 },
-    { 0,0,0,0,0,1,1,1,0,0,0,0 },
-    { 0,1,1,1,1,1,1,1,0,0,0,0 },
-    { 0,0,0,1,1,1,1,1,1,0,0,0 },
-    { 0,0,0,0,1,1,0,0,1,0,0,0 },
-    { 0,0,0,0,1,1,0,0,0,1,0,0 },
-    { 0,0,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,0,1,0,1,0,0,0,0,0,0 },
-    { 0,0,1,0,0,1,0,0,0,0,0,0 },
-    { 1,1,0,0,0,1,0,0,0,1,0,0 },
-    { 0,1,1,1,1,1,1,1,1,0,0,0 },
-    { 0,0,0,1,0,0,0,0,1,0,0,0 },
-    
-    
-};
-
-int skate_standing_left[17][12] =   {
-    
-    { 0,0,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,1,1,0,0,0 },
-    { 0,0,0,1,0,0,1,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,0,0,0,0,0 },
-    { 0,0,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,0,0,0,0,0 },
-    { 0,0,1,1,1,1,0,1,0,0,0,0 },
-    { 1,1,0,1,1,1,0,1,0,0,0,0 },
-    { 0,0,0,1,1,1,0,0,0,0,0,0 },
-    { 0,0,1,1,1,1,0,0,0,0,0,0 },
-    { 1,0,1,0,0,1,0,0,0,0,0,0 },
-    { 1,1,0,0,0,1,0,0,0,0,0,0 },
-    { 0,1,0,0,0,1,0,0,0,0,0,0 },
-    { 1,0,1,0,0,1,0,0,0,0,0,0 },
-    { 0,0,0,1,0,1,0,0,0,0,0,0 },
-    { 0,0,1,0,1,1,1,0,0,0,0,0 },
-    
-    
-};
-
-int skate_standing_right[17][12] =   {
-    
-    { 0,0,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,0,0,0,0,0 },
-    { 0,1,1,1,1,1,1,0,0,0,0,0 },
-    { 0,0,0,1,0,0,1,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,0,0,0,0,0 },
-    { 0,0,0,0,1,1,0,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,0,0,0,0,0 },
-    { 0,0,1,1,1,1,0,1,0,0,0,0 },
-    { 0,1,0,1,1,1,0,0,1,0,0,0 },
-    { 0,1,0,1,1,1,0,0,0,0,0,0 },
-    { 0,0,0,1,1,1,1,1,0,0,0,0 },
-    { 0,0,0,1,0,0,0,1,0,1,0,0 },
-    { 0,0,0,1,0,0,0,1,1,0,0,0 },
-    { 0,0,0,1,0,0,0,1,0,1,0,0 },
-    { 0,0,0,1,0,0,1,0,0,0,0,0 },
-    { 0,0,0,1,0,1,0,0,0,0,0,0 },
-    { 0,0,1,1,1,0,1,0,0,0,0,0 },
-    
-    
-};
-
 void init_game();
 void process_inputs();
 void update_lcd(int x, int y, Sprite_value sprite);
@@ -116,31 +24,38 @@
     init_game();
     int moving_counter = 0;
     int x; 
-    int y; 
+    int y;
+    int level = 0; 
     int jump_counter = 0; 
-    Skate_Direction direction;
+    Skate_Direction direction = Left;
     Sprite_value sprite;
        
     while(1){
         lcd.clear();
         Vector2D coord = gamepad.get_mapped_coord(); 
         
-        skater.set_y_position( gamepad.check_event(Gamepad::A_PRESSED), jump_counter );
+        if((x >= 1 && x <= 30 && y < 15) || (x >= 45 && x <= 80 && y < 15)){
+        level = 1;    
+        } else {
+        level = 0;
+        }
+        
+        skater.set_y_position( gamepad.check_event(Gamepad::A_PRESSED), jump_counter, level );
         y = skater.get_y_position();
         jump_counter = skater.get_jump_counter();
         
         skater.set_x_position( coord.x, moving_counter, direction );
         x = skater.get_x_position();
         moving_counter = skater.get_moving_counter();
-        sprite = skater.get_sprite();
-        
+        sprite = skater.get_sprite_value();
+        direction = skater.get_direction();
+                    
         update_lcd(x, y, sprite);
        
         lcd.refresh();
         wait(0.01); 
-    
-    }     
- }  
+}     
+}  
  
 void init_game() {
     gamepad.init();
@@ -148,18 +63,13 @@
     lcd.setContrast(0.5); 
     lcd.normalMode();      
     lcd.setBrightness(0.5); 
-    }
+}
     
 void update_lcd(int x, int y, Sprite_value sprite) {
-    if(sprite == Skate_right){
-    lcd.drawSprite(x,y,17,12,(int *)skate_right);
-    } else if(sprite == Skate_left){
-    lcd.drawSprite(x,y,17,12,(int *)skate_left);
-    } else if(sprite == Stand_left){
-    lcd.drawSprite(x,y,17,12,(int *)skate_standing_left);
-    } else if (sprite == Stand_right){
-    lcd.drawSprite(x,y,17,12,(int *)skate_standing_right);
-    }
-    lcd.drawLine(5,40,80,40,FILL_BLACK);  
-    }
+    int* skate_sprite = skater.get_sprite(sprite);
+    lcd.drawSprite(x,y,17,12,(int *)skate_sprite);
+    lcd.drawLine(5,40,80,40,FILL_BLACK);
+    lcd.drawLine(5,22,30,22,FILL_BLACK);
+    lcd.drawLine(50,22,80,22,FILL_BLACK);     
+}
     
\ No newline at end of file