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: Doodler/Doodler.cpp
- Revision:
- 8:90e789413e0b
- Parent:
- 7:0d9cee90ab0d
- Child:
- 9:5e53bca2a4c2
--- a/Doodler/Doodler.cpp Sun Apr 14 17:07:02 2019 +0000 +++ b/Doodler/Doodler.cpp Tue Apr 16 16:16:08 2019 +0000 @@ -10,43 +10,49 @@ _x = (70/2)+6; _y = 24; _radius = radius; - _velocity.y = 1; // dropped down - _gravity = 1; // moves down - _up = -0.5; + _velocity.y = 1.5; // dropped down + _gravity = 1.5; // moves down + _up = 0.9; } void Doodler::draw(N5110 &lcd){ lcd.drawCircle(_x, _y, _radius, FILL_BLACK); } -void Doodler::update(Direction d, float mag){ - if (_y < 43 ){ - _y += _velocity.y; - _velocity.y = _gravity; // gravity pulls it down - } else { - _velocity.y = _up; //jumps - _y += _velocity.y*20; - } +void Doodler::update(Direction d, float mag, Vector2D current_pos, Vector2D current_vel){ +////////////// y - direction of doodler //////////////////////// + _current_pos = current_pos; /// tienes que ponerlo para la direccion de x tambien y borrar lo del engine + _current_vel = current_vel; - _velocity.x = int(mag*5.0f); // 5 frames times the magnitude of the joystick (int holds that value) + if ((_current_vel.y > 0) || (_current_vel.y == 0 )){ // no jump or jump finishes + _new_vel.y *= _gravity; // falls accelerating + } else if(_current_vel.y < 0){ // jump has started and continues + _new_vel.y *= (-_up); // jumps decelerating upwards (0<_up<1 so _velocity.y reaches 0) + } + _current_pos.y += _new_vel.y; + +////////////// x - direction of doodler //////////////////////// + _new_vel.x = int(mag*5.0f); // 5 frames times the magnitude of the joystick (int holds that value) if (d == W){ // if direction is left - _x-= _velocity.x; + _current_pos.x-= _new_vel.x; } else if (d == E){ - _x+= _velocity.x; + _current_pos.x+= _new_vel.x; } + // checking doodler does not leave screen: + if (_current_pos.x > WIDTH-4){ // right side + _current_pos.x = WIDTH-4; + } + if (_current_pos.x < _radius){ // left side + _current_pos.x = _radius; + } -// checking doodler does not leave screen: - if (_x > WIDTH-4){ // right side - _x = WIDTH-4; - } - if (_x < _radius){ // left side - _x = _radius; - } + set_position(_current_pos); + set_velocity(_new_vel); } Vector2D Doodler::get_position(){ - Vector2D p = {_x,_y}; + Vector2D p = {_x,_y}; return p; } @@ -61,6 +67,6 @@ } void Doodler::set_position(Vector2D p){ - _x = p.x; - _y = p.y; + _x = (int)p.x; //integer position values + _y = (int)p.y; } \ No newline at end of file