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: Coin/Coin.cpp
- Revision:
- 16:37d98c281eb3
- Parent:
- 15:a080c64cf301
- Child:
- 17:ce6b54422113
--- a/Coin/Coin.cpp Mon May 06 18:39:40 2019 +0000 +++ b/Coin/Coin.cpp Wed May 08 09:05:27 2019 +0000 @@ -3,6 +3,7 @@ Coin::Coin(){ x_coin = 41; y_coin = 42; + _spawn = true; } Coin::~Coin(){ @@ -23,16 +24,16 @@ } void Coin::drawSprite(N5110 &lcd){ - lcd.drawSprite(x_coin,y_coin,2,2,(int *)coin_01); + lcd.drawSprite(x_coin,y_coin,2,2,(int *)coin_01); } void Coin::collect(N5110 &lcd){ } - +/* bool Coin::northCollision(int x, int y, N5110 &lcd){ for (int i = 0; i < 2; i++){ - if (lcd.getPixel(x + i,y) == 1){ + if (lcd.getPixel(x + i,y - 1) == 1){ return true; } } @@ -59,9 +60,35 @@ bool Coin::westCollision(int x, int y, N5110 &lcd){ for (int i = 0; i < 2; i++){ - if (lcd.getPixel(x,y + i) == 1){ + if (lcd.getPixel(x - 1,y + i) == 1){ return true; } } return false; +} +*/ +bool Coin::collidePlayer(int x, int y, Gamepad &pad) { + + for (int ix = 0; ix < 7; ix++) { + for (int iy = 0; iy < 7; iy++) { + if ( x + ix == x_coin - 1 && + y + iy == y_coin) { + pad.tone(650,0.25); + return true; + + } + } + } + return false; +} + +void Coin::spawn(int x, int y, N5110 &lcd, Gamepad &pad) { + drawSprite(lcd); + if (collidePlayer(x,y,pad) == true) { + x_coin = 100; + y_coin = 100; + + } else { + + } } \ No newline at end of file