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:
- 22:8e38efeae0c9
- Parent:
- 21:7d4827af00d6
- Child:
- 23:5e8a435e568f
--- a/Coin/Coin.cpp Wed May 08 23:17:35 2019 +0000
+++ b/Coin/Coin.cpp Thu May 09 12:10:56 2019 +0000
@@ -1,60 +1,75 @@
#include "Coin.h"
-Coin::Coin(){
- _spawn = true;
+Coin::Coin()
+{
+ coin = 0;
+ _spawn = true;
}
-Coin::~Coin(){
+Coin::~Coin()
+{
}
-void Coin::init(int x,int y){
- x_coin = x;
- y_coin = y;
+void Coin::init(int x, int y)
+{
+ x_coin = x;
+ y_coin = y;
+ //_collected = false;
+}
+
+int Coin::get_x_coin()
+{
+ return x_coin;
}
-int Coin::get_x_coin(){
- return x_coin;
+int Coin::get_y_coin()
+{
+ return y_coin;
}
-int Coin::get_y_coin(){
- return y_coin;
+int Coin::get_coins()
+{
+ return coin;
}
-void Coin::drawSprite(N5110 &lcd){
- lcd.drawSprite(x_coin,y_coin,2,2,(int *)coin_01);
+void Coin::drawSprite(N5110 &lcd)
+{
+ lcd.drawSprite(x_coin,y_coin,2,2,(int *)coin_01);
}
-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) {
- ++coin;
- pad.tone(650,0.25);
- return true;
- } else if ( x + ix == x_coin + 2 && y + iy == y_coin) {
- ++coin;
- pad.tone(650,0.25);
- return true;
- } else if ( x + ix == x_coin && y + iy == y_coin - 1) {
- ++coin;
- pad.tone(650,0.25);
- return true;
- } else if ( x + ix == x_coin && y + iy == y_coin + 2) {
- ++coin;
- pad.tone(650,0.25);
- return true;
- }
- }
+bool Coin::collidePlayer(int x, int y, Gamepad &pad)
+{
+ // detects for all x and y values whether the hitboxes of the coin //
+ // and controllable character collide //
+ 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;
+ } else if ( x + ix == x_coin + 2 && y + iy == y_coin) {
+ pad.tone(650,0.25);
+ return true;
+ } else if ( x + ix == x_coin && y + iy == y_coin - 1) {
+ pad.tone(650,0.25);
+ return true;
+ } else if ( x + ix == x_coin && y + iy == y_coin + 2) {
+ pad.tone(650,0.25);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
-void Coin::spawn(int x, int y, N5110 &lcd, Gamepad &pad) {
- drawSprite(lcd);
- if (collidePlayer(x,y,pad) == true) {
- //coin++;
- x_coin = 100;
- y_coin = 100;
- }
+void Coin::spawn(int x, int y, N5110 &lcd, Gamepad &pad)
+{
+ // if collision true the increment coin value //
+ // and move the sprite off screen //
+ drawSprite(lcd);
+ if (collidePlayer(x,y,pad) == true) {
+ x_coin = 100;
+ y_coin = 100;
+ coin++;
+ }
}
\ No newline at end of file