ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Revision:
9:fff2009f826e
Parent:
8:5327418f823a
Child:
10:8bf3713d9e9c
diff -r 5327418f823a -r fff2009f826e Skateboarder/Stakeboarder.cpp
--- a/Skateboarder/Stakeboarder.cpp	Sat Mar 23 15:36:56 2019 +0000
+++ b/Skateboarder/Stakeboarder.cpp	Sun Mar 24 19:22:50 2019 +0000
@@ -1,183 +1,172 @@
 #include "Skateboarder.h"
 
-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 },
-    
-    
+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 },  
 };
 
-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][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_stand_left[17][10] =   {
-    
-    { 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_stand_left[17][10] =   { 
+  { 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_stand_right[17][10] =   {
-    
-    { 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_stand_right[17][10] =   { 
+  { 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_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 },
-    
-    
+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 }, 
 };
 
 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 },
-    
-    
+  { 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 },   
 };
 
-Skateboarder::Skateboarder(){} 
+Skateboarder::Skateboarder() {} 
 
-Skateboarder::~Skateboarder(){}
+Skateboarder::~Skateboarder() {}
 
-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)){
+void Skateboarder::set_x_position_and_sprite(
+    float joy_x, 
+    int moving_counter, 
+    Skate_Direction direction, 
+    float joy_y) {
+  _skate_direction = direction;
+  _moving_counter = moving_counter;
+  process_x_variables(joy_x);    
+  _x = 40 + 0.4*_moving_counter;
+  check_duck(joy_y);
+}
+    
+void Skateboarder::process_x_variables(float joy_x) {
+  if (joy_x > 0.1) {
     _moving_counter = _moving_counter++;
     _skate_direction = Right;
     _sprite_value = Skate_right;
-    } else if(joy_x < float(-0.1)) {
+  } else if (joy_x < -0.1) {
     _moving_counter = _moving_counter--;
     _skate_direction = Left;
     _sprite_value = Skate_left; 
-    } else if (_skate_direction == Left){
+  } else if (_skate_direction == Left) {
     _sprite_value = Stand_left;
-    } else { 
+  } else { 
     _sprite_value = Stand_right;
-    }      
-    _x = 40 + 0.4*_moving_counter;
-    if(joy_y < float(-0.1) && _skate_direction == Right){
+  } 
+}
+    
+void Skateboarder::check_duck(float joy_y) {
+  if (joy_y < -0.1 && _skate_direction == Right) {
     _sprite_value = Skate_duck_right;         
-    } else if(joy_y < float(-0.1) && _skate_direction == Left){
+  } else if (joy_y < -0.1 && _skate_direction == Left) {
     _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 && _jump_counter < 10) {
-    _jump_counter = 40;
-    }
-    if(_jump_counter !=0){
-    _jump_counter--;        
-    }
-    _y = 23 - 0.5*_jump_counter;
+  _jump_counter = jump_counter;
+  _level = level; 
+  if (jump && _jump_counter < 10) _jump_counter = 40;
+  if (_jump_counter !=0) _jump_counter--;        
+  _y = 23 - 0.5*_jump_counter;
     /*
     if(_level == 0){
     _y = 23 - 0.5*_jump_counter;
@@ -186,73 +175,72 @@
     _y = 5 - 0.25*_jump_counter;        
     }
     */
-    }
-
+}
 
 
-int Skateboarder::get_x_position(){
-    return _x;
-    }
+int Skateboarder::get_x_position() {
+  return _x;
+}
 
-int Skateboarder::get_moving_counter(){
-    return _moving_counter;
-    }
+int Skateboarder::get_moving_counter() {
+  return _moving_counter;
+}
   
-int Skateboarder::get_y_position(){
-    return _y;
-    }
+int Skateboarder::get_y_position() {
+  return _y;
+}
 
-int Skateboarder::get_jump_counter(){
-    return _jump_counter;
-    }
+int Skateboarder::get_jump_counter() {
+  return _jump_counter;
+}
 
-Skate_Direction Skateboarder::get_direction(){
-    return _skate_direction;
-    }
+Skate_Direction Skateboarder::get_direction() {
+  return _skate_direction;
+}
     
-Sprite_value Skateboarder::get_sprite_value(){
-    return _sprite_value;
-    }   
+Sprite_value Skateboarder::get_sprite_value() {
+  return _sprite_value;
+}   
 
-int * Skateboarder::get_sprite(Sprite_value sprite){
-    if(sprite == Skate_right){
+int * Skateboarder::get_sprite(Sprite_value sprite) {
+  if (sprite == Skate_right) {
     return *skate_right;
-    } else if(sprite == Skate_left){
+  } else if (sprite == Skate_left) {
     return *skate_left;
-    } else if(sprite == Stand_left){
+  } else if (sprite == Stand_left) {
     return *skate_stand_left;
-    } else if(sprite == Skate_duck_right){
+  } else if (sprite == Skate_duck_right) {
     return *skate_duck_right;
-    } else if(sprite == Skate_duck_left){
+  } else if (sprite == Skate_duck_left) {
     return *skate_duck_left;
-    } else {
+  } else {
     return *skate_stand_right;
-    }
+  }
 } 
 
 void Skateboarder::fall(bool fall_flag) {
-     _fall_flag = fall_flag;
-     _y++;
-     if(_y == 80) {
-     _fall_flag = false;
-     _reset_flag = true;
-     }
-     }
+  _fall_flag = fall_flag;
+  _y++;
+  if (_y == 80) {
+    _fall_flag = false;
+    _reset_flag = true;
+  }
+}
      
 bool Skateboarder::get_fall_flag() {
-     return _fall_flag;
-     }
+  return _fall_flag;
+}
      
 bool Skateboarder::get_reset_flag() {
-     return _reset_flag;
-     }
+  return _reset_flag;
+}
      
 void Skateboarder::set_reset_flag(bool flag) {
-     if(flag) {
-     _reset_flag = true;
-     } else {
-     _reset_flag = false;
-     }
-     }
+  if (flag) {
+    _reset_flag = true;
+  } else {
+    _reset_flag = false;
+  }
+}
      
      
\ No newline at end of file