ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lewisgw
Date:
Sun Mar 17 13:36:10 2019 +0000
Parent:
3:28a3c118e071
Child:
5:eda40cdde3e7
Commit message:
Skater can now duck when joystick is in non zero horizontal direction and negative vertical direction.

Changed in this revision

Engine/Engine.cpp Show annotated file Show diff for this revision Revisions of this file
Engine/Engine.h Show annotated file Show diff for this revision Revisions of this file
Skateboarder/Skateboarder.h Show annotated file Show diff for this revision Revisions of this file
Skateboarder/Stakeboarder.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Skateboarder/Skateboarder.h	Sat Mar 16 10:38:04 2019 +0000
+++ b/Skateboarder/Skateboarder.h	Sun Mar 17 13:36:10 2019 +0000
@@ -17,7 +17,9 @@
     Skate_right,
     Skate_left,
     Stand_left,
-    Stand_right
+    Stand_right,
+    Skate_duck_right,
+    Skate_duck_left
 };
 
 class Skateboarder {
@@ -26,7 +28,7 @@
     Skateboarder();
     ~Skateboarder();
     
-    void set_x_position(float joy_x, int moving_counter, Skate_Direction direction);
+    void set_x_position(float joy_x, int moving_counter, Skate_Direction direction, float joy_y);
     void set_y_position(bool jump, int jump_counter, int level); 
     int get_x_position();
     int get_moving_counter();
--- a/Skateboarder/Stakeboarder.cpp	Sat Mar 16 10:38:04 2019 +0000
+++ b/Skateboarder/Stakeboarder.cpp	Sun Mar 17 13:36:10 2019 +0000
@@ -1,93 +1,139 @@
 #include "Skateboarder.h"
 
-    int skate_right[17][12] =   {
+int skate_right[17][10] =   {
+    
+    { 0,0,0,1,1,1,0,0,0,0 },
+    { 0,0,0,1,1,1,1,0,0,0 },
+    { 0,1,1,1,1,1,1,0,0,0 },
+    { 0,0,0,1,0,1,1,0,0,0 },
+    { 0,0,0,1,1,1,0,0,0,0 },
+    { 0,0,0,1,1,0,0,0,0,0 },
+    { 0,0,0,1,1,0,0,0,0,0 },
+    { 0,1,1,1,1,1,1,1,0,0 },
+    { 1,1,0,1,1,0,0,1,1,0 },
+    { 1,0,0,1,1,0,0,0,0,0 },
+    { 0,0,0,1,1,0,0,0,0,0 },
+    { 0,0,0,1,1,0,0,0,0,0 },
+    { 0,0,0,1,0,1,0,0,0,0 },
+    { 0,0,0,1,0,0,1,0,0,0 },
+    { 1,0,0,1,0,0,0,1,0,1 },
+    { 0,1,1,1,1,1,1,1,1,0 },
+    { 0,0,1,0,0,0,0,1,0,0 },
+    
     
-    { 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][10] =   {
+    
+    { 0,0,0,0,1,1,1,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,1,1,0,1,0,0,0 },
+    { 0,0,0,0,1,1,1,0,0,0 },
+    { 0,0,0,0,0,1,1,0,0,0 },
+    { 0,0,0,0,0,1,1,1,0,0 },
+    { 0,1,1,1,1,1,1,1,0,0 },
+    { 0,0,0,1,1,1,1,1,1,0 },
+    { 0,0,0,0,1,1,0,0,1,0 },
+    { 0,0,0,0,1,1,0,0,0,1 },
+    { 0,0,0,0,1,1,0,0,0,0 },
+    { 0,0,0,1,0,1,0,0,0,0 },
+    { 0,0,1,0,0,1,0,0,0,0 },
+    { 1,1,0,0,0,1,0,0,0,1 },
+    { 0,1,1,1,1,1,1,1,1,0 },
+    { 0,0,0,1,0,0,0,0,1,0 },
     
     
 };
 
-int skate_left[17][12] =   {
+int skate_stand_left[17][10] =   {
     
-    { 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 },
+    { 0,0,0,0,1,1,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,1,0,0,1,0,0,0 },
+    { 0,0,0,1,1,1,1,0,0,0 },
+    { 0,0,0,0,1,1,0,0,0,0 },
+    { 0,0,0,1,1,1,1,0,0,0 },
+    { 0,0,1,1,1,1,0,1,0,0 },
+    { 1,1,0,1,1,1,0,1,0,0 },
+    { 0,0,0,1,1,1,0,0,0,0 },
+    { 0,0,1,1,1,1,0,0,0,0 },
+    { 1,0,1,0,0,1,0,0,0,0 },
+    { 1,1,0,0,0,1,0,0,0,0 },
+    { 0,1,0,0,0,1,0,0,0,0 },
+    { 1,0,1,0,0,1,0,0,0,0 },
+    { 0,0,0,1,0,1,0,0,0,0 },
+    { 0,0,1,0,1,1,1,0,0,0 },
     
     
 };
 
-int skate_standing_left[17][12] =   {
+int skate_stand_right[17][10] =   {
     
-    { 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 },
+    { 0,0,0,1,1,0,0,0,0,0 },
+    { 0,0,1,1,1,1,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,1,1,1,1,0,0,0,0 },
+    { 0,0,0,1,1,0,0,0,0,0 },
+    { 0,0,1,1,1,1,0,0,0,0 },
+    { 0,1,1,1,1,0,1,0,0,0 },
+    { 1,0,1,1,1,0,0,1,0,0 },
+    { 1,0,1,1,1,0,0,0,0,0 },
+    { 0,0,1,1,1,1,1,0,0,0 },
+    { 0,0,1,0,0,0,1,0,1,0 },
+    { 0,0,1,0,0,0,1,1,0,0 },
+    { 0,0,1,0,0,0,1,0,1,0 },
+    { 0,0,1,0,0,1,0,0,0,0 },
+    { 0,0,1,0,1,0,0,0,0,0 },
+    { 0,1,1,1,0,1,0,0,0,0 },
     
     
 };
 
-int skate_standing_right[17][12] =   {
+int skate_duck_right[17][10] =   {
+    
+    { 0,0,0,0,0,0,0,0,0,0 },
+    { 0,0,0,0,0,0,0,0,0,0 },
+    { 0,0,0,0,0,0,0,0,0,0 },
+    { 0,0,0,0,0,0,0,0,0,0 },
+    { 0,0,0,0,1,1,0,0,0,0 },
+    { 0,0,0,1,1,1,1,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,1,1,0,0,0,0 },
+    { 0,0,1,1,1,1,1,1,0,0 },
+    { 0,1,0,1,1,1,1,0,1,1 },
+    { 1,0,0,1,1,1,1,0,0,0 },
+    { 0,0,0,1,1,1,1,0,0,0 },
+    { 0,0,1,1,0,0,1,1,0,0 },
+    { 1,0,1,1,0,0,1,1,0,1 },
+    { 0,1,1,1,1,1,1,1,1,0 },
+    { 0,0,1,0,0,0,0,1,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,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 },
+};
+
+int skate_duck_left[17][10] =   {
+    
+    { 0,0,0,0,0,0,0,0,0,0 },
+    { 0,0,0,0,0,0,0,0,0,0 },
+    { 0,0,0,0,0,0,0,0,0,0 },
+    { 0,0,0,0,0,0,0,0,0,0 },
+    { 0,0,0,0,1,1,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,1,0,0,1,0,0,0 },
+    { 0,0,0,0,1,1,0,0,0,0 },
+    { 0,0,1,1,1,1,1,1,0,0 },
+    { 1,1,0,1,1,1,1,0,1,0 },
+    { 0,0,0,1,1,1,1,0,0,1 },
+    { 0,0,0,1,1,1,1,0,0,0 },
+    { 0,0,1,1,0,0,1,1,0,0 },
+    { 1,0,1,1,0,0,1,1,0,1 },
+    { 0,1,1,1,1,1,1,1,1,0 },
+    { 0,0,1,0,0,0,0,1,0,0 },
     
     
 };
@@ -96,11 +142,9 @@
 
 Skateboarder::~Skateboarder(){}
 
-void Skateboarder::set_x_position(float joy_x, int moving_counter, Skate_Direction direction) {
-    
+void Skateboarder::set_x_position(float joy_x, int moving_counter, Skate_Direction direction, float joy_y) {
     _skate_direction = direction;
     _moving_counter = moving_counter;
-    
     if(joy_x > float(0.1)){
     _moving_counter = _moving_counter++;
     _skate_direction = Right;
@@ -114,31 +158,31 @@
     } else { 
     _sprite_value = Stand_right;
     }      
-    _x = 40 + 0.4*_moving_counter;           
-    
+    _x = 40 + 0.4*_moving_counter;
+    if(joy_y < float(-0.1) && joy_x > float(0.1)){
+    _sprite_value = Skate_duck_right;         
+    } else if(joy_y < float(-0.1) && joy_x < float(-0.1)){
+    _sprite_value = Skate_duck_left;        
+    }
     }
     
 void Skateboarder::set_y_position(bool jump, int jump_counter, int level) {
     
     _jump_counter = jump_counter;
     _level = level;
-    if(jump) {
+   
+    if(jump && _jump_counter < 10) {
     _jump_counter = 40;
     }
     if(_jump_counter !=0){
     _jump_counter--;        
     }
-    
-    
-    
     if(_level == 0){
     _y = 23 - 0.5*_jump_counter;
-    } 
-     
+    }  
     else {
-    _y = 5 - 0.25*_jump_counter;    // need to get rid of double jump use if(jump)        
+    _y = 5 - 0.25*_jump_counter;        
     }
-    
     }
 
 
@@ -173,8 +217,12 @@
     } else if(sprite == Skate_left){
     return *skate_left;
     } else if(sprite == Stand_left){
-    return *skate_standing_left;
+    return *skate_stand_left;
+    } else if(sprite == Skate_duck_right){
+    return *skate_duck_right;
+    } else if(sprite == Skate_duck_left){
+    return *skate_duck_left;
     } else {
-    return *skate_standing_right;
+    return *skate_stand_right;
     }
 }    
\ No newline at end of file
--- a/main.cpp	Sat Mar 16 10:38:04 2019 +0000
+++ b/main.cpp	Sun Mar 17 13:36:10 2019 +0000
@@ -44,7 +44,7 @@
         y = skater.get_y_position();
         jump_counter = skater.get_jump_counter();
         
-        skater.set_x_position( coord.x, moving_counter, direction );
+        skater.set_x_position( coord.x, moving_counter, direction, coord.y );
         x = skater.get_x_position();
         moving_counter = skater.get_moving_counter();
         sprite = skater.get_sprite_value();
@@ -67,7 +67,7 @@
     
 void update_lcd(int x, int y, Sprite_value sprite) {
     int* skate_sprite = skater.get_sprite(sprite);
-    lcd.drawSprite(x,y,17,12,(int *)skate_sprite);
+    lcd.drawSprite(x,y,17,10,(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);