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: Alien/Alien.cpp
- Revision:
- 13:b85f14d35be1
- Parent:
- 12:be491ab6e742
- Child:
- 14:e88bcf5c0887
--- a/Alien/Alien.cpp Wed Apr 01 14:40:29 2020 +0000 +++ b/Alien/Alien.cpp Wed Apr 01 16:00:44 2020 +0000 @@ -3,6 +3,8 @@ void Alien::init(int x, int y, int size) { Alive = true; + StartX = x; + StartY = y; X = x; Y = y; Size = size; @@ -20,16 +22,19 @@ return p; } -void Alien::update(N5110 &lcd) { +void Alien::update(N5110 &lcd, int step_x, int remainder_x) { X+=Speed; - - if (X < 1) { - X = 1; + int _step_x = step_x; + int _remainder_x = remainder_x; + if (X < 1 + _remainder_x*_step_x) { + X = 1 + _remainder_x*_step_x; Speed = -Speed; + Y = Y + 2; } - if (X > WIDTH - Size - 1) { - X = WIDTH - Size - 1; + if (X > WIDTH - Size - 1 - (4-_remainder_x)*_step_x) { + X = WIDTH - Size - 1 - (4-_remainder_x)*_step_x; Speed = -Speed; + Y = Y + 2; } collision(lcd); }