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:
- 10:9189419fda68
- Parent:
- 9:8e695df3cc36
- Child:
- 12:be491ab6e742
diff -r 8e695df3cc36 -r 9189419fda68 Alien/Alien.cpp --- a/Alien/Alien.cpp Fri Mar 27 11:55:53 2020 +0000 +++ b/Alien/Alien.cpp Fri Mar 27 22:58:56 2020 +0000 @@ -2,6 +2,7 @@ void Alien::init(int y, int size) { + Alive = true; X = WIDTH/2 - Size/2; Y = y; Size = size; @@ -9,7 +10,9 @@ } void Alien::render(N5110 &lcd) { - lcd.drawRect(X, Y, Size, Size, FILL_BLACK); + if(Alive == true){ + lcd.drawRect(X, Y, Size, Size, FILL_BLACK); + } } Vector2D Alien::get_position() { @@ -17,7 +20,7 @@ return p; } -void Alien::update() { +void Alien::update(N5110 &lcd) { X+=Speed; if (X < 1) { @@ -28,5 +31,15 @@ X = WIDTH - Size - 1; Speed = -Speed; } + collision(lcd); +} + +void Alien::collision(N5110 &lcd) { + for(int i = X; i < X + Size; i++) { + if(lcd.getPixel(i,Y + Size + 1)) { + Alive = false; + } + } } +