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:
- 15:4efa04a6a376
- Parent:
- 14:529f798adae4
- Child:
- 16:e0542761fc8c
--- a/Doodler/Doodler.cpp Sun Apr 21 16:10:19 2019 +0000 +++ b/Doodler/Doodler.cpp Tue Apr 23 23:14:06 2019 +0000 @@ -7,12 +7,12 @@ void Doodler::init(int radius, float position_x, float position_y, double velocity_y){ // initial position of doodler at centre _radius = radius; - _velocity_y = (double)velocity_y; + _gravity = 1.1; // moves down + _up = -0.5; // elasticity _position_x = position_x; _position_y = position_y; - _gravity = 1.1; // moves down - _up = -0.5; // elasticity + _velocity_y = (double)velocity_y; if ((double)_velocity_y > 0.00){ // no jump _velocity_y = (double)_velocity_y*(double)_gravity; // falls accelerating } else if ( (double)_velocity_y == 0.00){ @@ -29,19 +29,9 @@ lcd.drawCircle(_position_x, _position_y, _radius, FILL_BLACK); } -void Doodler::update(Direction d, float mag, double velocity_y){ -//////////////////////////// y - direction of doodler ///////////////////////////////////// - _position_x = get_position_x(); - _position_y = get_position_y(); - _velocity_y = (double)velocity_y; - if ((double)_velocity_y >= 0.00){ // no jump - _position_y += _velocity_y; - } else { // jump has started until vel = 0 - _position_y += _velocity_y*5; - } - -/////////////////////////// x - direction of doodler ///////////////////////////////////////// - _velocity_x = int(mag*5.0f); // 5 frames times the magnitude of the joystick (int holds that value) +void Doodler::update(Direction d, float mag){ + // 5 frames times the magnitude of the joystick (int holds that value) + _velocity_x = int(mag*5.0f); if (d == W){ // if direction is left _position_x -= _velocity_x; } else if (d == E){ @@ -54,9 +44,14 @@ if (_position_x < _radius){ // left side _position_x = _radius; } + _velocity_y = (double)get_velocity_y(); + if ((double)_velocity_y >= 0.00){ // no jump + _position_y += _velocity_y; + } else { // jump has started until vel = 0 + _position_y += _velocity_y*5; + } } - float Doodler::get_position_x(){ float p_x = _position_x; return p_x;