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/Coin.cpp@21:7d4827af00d6, 2019-05-08 (annotated)
- Committer:
- S_Tingle
- Date:
- Wed May 08 23:17:35 2019 +0000
- Revision:
- 21:7d4827af00d6
- Parent:
- 19:1073cc64cb0b
- Child:
- 22:8e38efeae0c9
added all coins
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
S_Tingle | 13:c3b550fc2445 | 1 | #include "Coin.h" |
S_Tingle | 13:c3b550fc2445 | 2 | |
S_Tingle | 13:c3b550fc2445 | 3 | Coin::Coin(){ |
S_Tingle | 16:37d98c281eb3 | 4 | _spawn = true; |
S_Tingle | 13:c3b550fc2445 | 5 | } |
S_Tingle | 13:c3b550fc2445 | 6 | |
S_Tingle | 13:c3b550fc2445 | 7 | Coin::~Coin(){ |
S_Tingle | 13:c3b550fc2445 | 8 | |
S_Tingle | 13:c3b550fc2445 | 9 | } |
S_Tingle | 13:c3b550fc2445 | 10 | |
S_Tingle | 13:c3b550fc2445 | 11 | void Coin::init(int x,int y){ |
S_Tingle | 13:c3b550fc2445 | 12 | x_coin = x; |
S_Tingle | 13:c3b550fc2445 | 13 | y_coin = y; |
S_Tingle | 13:c3b550fc2445 | 14 | } |
S_Tingle | 13:c3b550fc2445 | 15 | |
S_Tingle | 14:d0650d0de063 | 16 | int Coin::get_x_coin(){ |
S_Tingle | 13:c3b550fc2445 | 17 | return x_coin; |
S_Tingle | 13:c3b550fc2445 | 18 | } |
S_Tingle | 13:c3b550fc2445 | 19 | |
S_Tingle | 14:d0650d0de063 | 20 | int Coin::get_y_coin(){ |
S_Tingle | 13:c3b550fc2445 | 21 | return y_coin; |
S_Tingle | 13:c3b550fc2445 | 22 | } |
S_Tingle | 13:c3b550fc2445 | 23 | |
S_Tingle | 13:c3b550fc2445 | 24 | void Coin::drawSprite(N5110 &lcd){ |
S_Tingle | 16:37d98c281eb3 | 25 | lcd.drawSprite(x_coin,y_coin,2,2,(int *)coin_01); |
S_Tingle | 13:c3b550fc2445 | 26 | } |
S_Tingle | 13:c3b550fc2445 | 27 | |
S_Tingle | 16:37d98c281eb3 | 28 | bool Coin::collidePlayer(int x, int y, Gamepad &pad) { |
S_Tingle | 16:37d98c281eb3 | 29 | for (int ix = 0; ix < 7; ix++) { |
S_Tingle | 16:37d98c281eb3 | 30 | for (int iy = 0; iy < 7; iy++) { |
S_Tingle | 21:7d4827af00d6 | 31 | if ( x + ix == x_coin - 1 && y + iy == y_coin) { |
S_Tingle | 17:ce6b54422113 | 32 | ++coin; |
S_Tingle | 16:37d98c281eb3 | 33 | pad.tone(650,0.25); |
S_Tingle | 19:1073cc64cb0b | 34 | return true; |
S_Tingle | 21:7d4827af00d6 | 35 | } else if ( x + ix == x_coin + 2 && y + iy == y_coin) { |
S_Tingle | 18:ba4159ab4da7 | 36 | ++coin; |
S_Tingle | 18:ba4159ab4da7 | 37 | pad.tone(650,0.25); |
S_Tingle | 19:1073cc64cb0b | 38 | return true; |
S_Tingle | 21:7d4827af00d6 | 39 | } else if ( x + ix == x_coin && y + iy == y_coin - 1) { |
S_Tingle | 18:ba4159ab4da7 | 40 | ++coin; |
S_Tingle | 18:ba4159ab4da7 | 41 | pad.tone(650,0.25); |
S_Tingle | 19:1073cc64cb0b | 42 | return true; |
S_Tingle | 21:7d4827af00d6 | 43 | } else if ( x + ix == x_coin && y + iy == y_coin + 2) { |
S_Tingle | 18:ba4159ab4da7 | 44 | ++coin; |
S_Tingle | 18:ba4159ab4da7 | 45 | pad.tone(650,0.25); |
S_Tingle | 18:ba4159ab4da7 | 46 | return true; |
S_Tingle | 19:1073cc64cb0b | 47 | } |
S_Tingle | 16:37d98c281eb3 | 48 | } |
S_Tingle | 16:37d98c281eb3 | 49 | } |
S_Tingle | 16:37d98c281eb3 | 50 | return false; |
S_Tingle | 16:37d98c281eb3 | 51 | } |
S_Tingle | 16:37d98c281eb3 | 52 | |
S_Tingle | 16:37d98c281eb3 | 53 | void Coin::spawn(int x, int y, N5110 &lcd, Gamepad &pad) { |
S_Tingle | 21:7d4827af00d6 | 54 | drawSprite(lcd); |
S_Tingle | 16:37d98c281eb3 | 55 | if (collidePlayer(x,y,pad) == true) { |
S_Tingle | 21:7d4827af00d6 | 56 | //coin++; |
S_Tingle | 16:37d98c281eb3 | 57 | x_coin = 100; |
S_Tingle | 16:37d98c281eb3 | 58 | y_coin = 100; |
S_Tingle | 16:37d98c281eb3 | 59 | } |
S_Tingle | 13:c3b550fc2445 | 60 | } |