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: Tank/Tank.cpp
- Revision:
- 16:a2c945279b79
- Parent:
- 15:fa5282fcd134
- Child:
- 17:cb39d9fa08dc
--- a/Tank/Tank.cpp Fri Apr 19 15:58:51 2019 +0000 +++ b/Tank/Tank.cpp Wed Apr 24 13:44:12 2019 +0000 @@ -1,6 +1,6 @@ /* Tank.cpp -Produces tank on the left side of the -lcd and dictates it's movement +Produces a tank object +and dictates it's movement 1.4.19 */ #include "Tank.h" @@ -56,31 +56,25 @@ { _speed = s; } -// Movement -void Tank::_limit_movement() -{ - if (_position_x == _left_lim - 1) { - _position_x = _left_lim; - } else if (_position_x == _right_lim + 1) { - _position_x = _right_lim; - } -} - +// Other Methods void Tank::move_position(int d) { int slowness = 9 - _speed; int i = _move_counter % slowness; if (d > 0) { - if (i == 0) {_position_x++;} - _move_counter++; + _move_counter++; + if (i == 0 && _position_x < _right_lim) { + _position_x++; + } } - else if (d < 0) { - if (i == 0) {_position_x--;} - _move_counter--; + else if (d < 0) { + _move_counter--; + if (i == 0 && _position_x > _left_lim) { + _position_x--; + } } - _limit_movement(); } -// Other Methods + void Tank::lose_health() { _health--;