Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Skateboarder/Stakeboarder.cpp
- Revision:
- 10:8bf3713d9e9c
- Parent:
- 9:fff2009f826e
- Child:
- 14:9861fe85c803
diff -r fff2009f826e -r 8bf3713d9e9c Skateboarder/Stakeboarder.cpp --- a/Skateboarder/Stakeboarder.cpp Sun Mar 24 19:22:50 2019 +0000 +++ b/Skateboarder/Stakeboarder.cpp Tue Mar 26 11:03:05 2019 +0000 @@ -1,5 +1,6 @@ #include "Skateboarder.h" +// Define all the different possible sprite arrays. 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 }, @@ -120,6 +121,7 @@ { 0,0,1,0,0,0,0,1,0,0 }, }; +// Constructor and destructor. Skateboarder::Skateboarder() {} Skateboarder::~Skateboarder() {} @@ -137,6 +139,9 @@ } void Skateboarder::process_x_variables(float joy_x) { + // Sets the value of the Sprite_value enum according to joystick direction + // and previous direction if the joystick is not moving. Adds or subtracts + // one from moving counter for horizontal movement. if (joy_x > 0.1) { _moving_counter = _moving_counter++; _skate_direction = Right; @@ -153,6 +158,7 @@ } void Skateboarder::check_duck(float joy_y) { + // Re-write the Sprite_value if the duck condition is met. if (joy_y < -0.1 && _skate_direction == Right) { _sprite_value = Skate_duck_right; } else if (joy_y < -0.1 && _skate_direction == Left) { @@ -161,23 +167,24 @@ } -void Skateboarder::set_y_position(bool jump, int jump_counter, int level) { +void Skateboarder::set_y_position(bool jump, int jump_counter, int level_condition) { _jump_counter = jump_counter; - _level = level; + _level_condition = level_condition; + // Set jump counter to 40 if button is pressed. Second condition is to restrict + // double jump. Keep subtracting jump counter from default y position, subtracting + // one from the jump counter on every iteration until it is equal to 0. 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; - } - else { - _y = 5 - 0.25*_jump_counter; - } - */ + if(_level_condition == 1 && jump){ + _level = 5; + } else if (_level_condition == 0) { + _level = 23; + } + _y = _level - 0.5*_jump_counter; } + int Skateboarder::get_x_position() { return _x; }