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
Coin.cpp
00001 #include "Coin.h" 00002 00003 Coin::Coin() 00004 { 00005 coin = 0; 00006 _spawn = true; 00007 } 00008 00009 Coin::~Coin() 00010 { 00011 00012 } 00013 00014 void Coin::init(int x, int y) 00015 { 00016 x_coin = x; 00017 y_coin = y; 00018 } 00019 00020 int Coin::get_x_coin() 00021 { 00022 return x_coin; 00023 } 00024 00025 int Coin::get_y_coin() 00026 { 00027 return y_coin; 00028 } 00029 00030 // gets current number of coins collected // 00031 int Coin::get_coins() 00032 { 00033 return coin; 00034 } 00035 00036 void Coin::drawSprite(N5110 &lcd) 00037 { 00038 lcd.drawSprite(x_coin,y_coin,2,2,(int *)coin_01); 00039 } 00040 00041 bool Coin::collidePlayer(int x, int y, Gamepad &pad) 00042 { 00043 // detects for all x and y values whether the hitboxes of the coin // 00044 // and controllable character collide // 00045 for (int ix = 0; ix < 7; ix++) { 00046 for (int iy = 0; iy < 7; iy++) { 00047 if ( x + ix == x_coin - 1 && y + iy == y_coin) { 00048 pad.tone(650,0.25); 00049 return true; 00050 } else if ( x + ix == x_coin + 2 && y + iy == y_coin) { 00051 pad.tone(650,0.25); 00052 return true; 00053 } else if ( x + ix == x_coin && y + iy == y_coin - 1) { 00054 pad.tone(650,0.25); 00055 return true; 00056 } else if ( x + ix == x_coin && y + iy == y_coin + 2) { 00057 pad.tone(650,0.25); 00058 return true; 00059 } 00060 } 00061 } 00062 return false; 00063 } 00064 00065 void Coin::spawn(int x, int y, N5110 &lcd, Gamepad &pad) 00066 { 00067 // if collision true the increment coin value // 00068 // and move the sprite off screen // 00069 drawSprite(lcd); 00070 if (collidePlayer(x,y,pad) == true) { 00071 x_coin = 100; 00072 y_coin = 100; 00073 coin++; 00074 } 00075 }
Generated on Wed Jul 13 2022 21:10:10 by
