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: TankL/TankL.cpp
- Revision:
- 10:d4fb12e9e7cd
- Parent:
- 8:d4e419dad90f
- Child:
- 11:4e2eb64031a0
diff -r fe912235dd71 -r d4fb12e9e7cd TankL/TankL.cpp --- a/TankL/TankL.cpp Wed Apr 10 14:27:37 2019 +0000 +++ b/TankL/TankL.cpp Fri Apr 12 12:01:47 2019 +0000 @@ -15,25 +15,6 @@ } */ -void TankL::draw(N5110 &lcd) -{ - const int tank_l_spr[6][10] = { - { 0,0,0,1,1,1,0,0,0,0 }, - { 0,0,1,1,1,1,1,0,0,0 }, - { 0,0,1,1,1,1,1,1,1,0 }, - { 1,1,1,1,1,1,1,1,1,1 }, - { 1,0,1,0,1,0,1,0,1,0 }, - { 0,1,0,1,0,1,0,1,0,0 }, - }; - lcd.drawSprite(_position_x,42 - _position_y,6,10,(int *)tank_l_spr); -} - -void TankL::set_position(int x, int y) -{ - _position_x = x; - _position_y = y; -} - int TankL::get_position_x() { return _position_x; @@ -49,11 +30,41 @@ return _hitbox[i]; } +void TankL::set_position(int x, int y) +{ + _position_x = x; + _position_y = y; +} + void TankL::set_health(int h) { _health = h; } +void TankL::set_speed(int s) +{ + _speed = s; +} + +void TankL::set_angle(float angle) +{ + _angle = angle; +} + +void TankL::move_position(int d) +{ + int slowness = 24 / _speed; + int i = _move_counter % slowness; + if (d > 0) { + if (i == 0) {_position_x++;} + _move_counter++; + } + else if (d < 0) { + if (i == 0) {_position_x--;} + _move_counter--; + } +} + void TankL::lose_health() { _health--; @@ -70,4 +81,62 @@ i++; } } +} + +void TankL::draw(N5110 &lcd) +{ + const int tank_l_spr[6][10] = { + { 0,0,0,1,1,1,0,0,0,0 }, + { 0,0,1,1,1,1,1,0,0,0 }, + { 0,0,1,1,1,1,1,1,1,0 }, + { 1,1,1,1,1,1,1,1,1,1 }, + { 1,0,1,0,1,0,1,0,1,0 }, + { 0,1,0,1,0,1,0,1,0,0 }, + }; + lcd.drawSprite(_position_x,42 - _position_y,6,10,(int *)tank_l_spr); + + if (_angle < 18) { + const int turret_spr1[3][7] = { + { 0,0,1,0,0,0,0 }, + { 0,1,1,1,1,1,1 }, + { 1,1,1,1,1,1,0 }, + }; + lcd.drawSprite(2 + _position_x,42 - _position_y,3,7,(int *)turret_spr1); + } + else if (_angle >= 18 && _angle < 36) { + const int turret_spr2[3][7] = { + { 0,0,1,1,1,1,1 }, + { 0,1,1,1,1,0,0 }, + { 1,1,1,1,1,1,0 }, + }; + lcd.drawSprite(2 + _position_x,42 - _position_y,3,7,(int *)turret_spr2); + } + else if (_angle >= 36 && _angle < 54) { + const int turret_spr3[4][7] = { + { 0,0,0,0,1,0,0 }, + { 0,0,1,1,0,0,0 }, + { 0,1,1,1,0,0,0 }, + { 1,1,1,1,1,1,0 }, + }; + lcd.drawSprite(2 + _position_x,41 - _position_y,4,7,(int *)turret_spr3); + } + else if (_angle >= 54 && _angle < 72) { + const int turret_spr4[4][7] = { + { 0,0,0,1,0,0,0 }, + { 0,0,1,1,0,0,0 }, + { 0,1,1,1,0,0,0 }, + { 1,1,1,1,1,1,0 }, + }; + lcd.drawSprite(2 + _position_x,41 - _position_y,4,7,(int *)turret_spr4); + } + else { + const int turret_spr5[5][7] = { + { 0,0,1,0,0,0,0 }, + { 0,0,1,0,0,0,0 }, + { 0,0,1,0,0,0,0 }, + { 0,1,1,1,0,0,0 }, + { 1,1,1,1,1,1,0 }, + }; + lcd.drawSprite(2 + _position_x,40 - _position_y,5,7,(int *)turret_spr5); + } } \ No newline at end of file