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@18:ba4159ab4da7, 2019-05-08 (annotated)
- Committer:
- S_Tingle
- Date:
- Wed May 08 15:01:45 2019 +0000
- Revision:
- 18:ba4159ab4da7
- Parent:
- 17:ce6b54422113
- Child:
- 19:1073cc64cb0b
new movement enemy1
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 | 17:ce6b54422113 | 24 | int Coin::coins(){ |
S_Tingle | 17:ce6b54422113 | 25 | return coin; |
S_Tingle | 17:ce6b54422113 | 26 | } |
S_Tingle | 17:ce6b54422113 | 27 | |
S_Tingle | 13:c3b550fc2445 | 28 | void Coin::drawSprite(N5110 &lcd){ |
S_Tingle | 16:37d98c281eb3 | 29 | lcd.drawSprite(x_coin,y_coin,2,2,(int *)coin_01); |
S_Tingle | 13:c3b550fc2445 | 30 | } |
S_Tingle | 13:c3b550fc2445 | 31 | |
S_Tingle | 16:37d98c281eb3 | 32 | bool Coin::collidePlayer(int x, int y, Gamepad &pad) { |
S_Tingle | 16:37d98c281eb3 | 33 | for (int ix = 0; ix < 7; ix++) { |
S_Tingle | 16:37d98c281eb3 | 34 | for (int iy = 0; iy < 7; iy++) { |
S_Tingle | 16:37d98c281eb3 | 35 | if ( x + ix == x_coin - 1 && |
S_Tingle | 16:37d98c281eb3 | 36 | y + iy == y_coin) { |
S_Tingle | 17:ce6b54422113 | 37 | ++coin; |
S_Tingle | 16:37d98c281eb3 | 38 | pad.tone(650,0.25); |
S_Tingle | 16:37d98c281eb3 | 39 | return true; |
S_Tingle | 18:ba4159ab4da7 | 40 | } else if ( x + ix == x_coin + 2 && |
S_Tingle | 18:ba4159ab4da7 | 41 | y + iy == y_coin) { |
S_Tingle | 18:ba4159ab4da7 | 42 | ++coin; |
S_Tingle | 18:ba4159ab4da7 | 43 | pad.tone(650,0.25); |
S_Tingle | 18:ba4159ab4da7 | 44 | return true; |
S_Tingle | 18:ba4159ab4da7 | 45 | } else if ( x + ix == x_coin && |
S_Tingle | 18:ba4159ab4da7 | 46 | y + iy == y_coin - 1) { |
S_Tingle | 18:ba4159ab4da7 | 47 | ++coin; |
S_Tingle | 18:ba4159ab4da7 | 48 | pad.tone(650,0.25); |
S_Tingle | 18:ba4159ab4da7 | 49 | return true; |
S_Tingle | 18:ba4159ab4da7 | 50 | } else if ( x + ix == x_coin && |
S_Tingle | 18:ba4159ab4da7 | 51 | y + iy == y_coin + 2) { |
S_Tingle | 18:ba4159ab4da7 | 52 | ++coin; |
S_Tingle | 18:ba4159ab4da7 | 53 | pad.tone(650,0.25); |
S_Tingle | 18:ba4159ab4da7 | 54 | return true; |
S_Tingle | 16:37d98c281eb3 | 55 | } |
S_Tingle | 16:37d98c281eb3 | 56 | } |
S_Tingle | 16:37d98c281eb3 | 57 | } |
S_Tingle | 16:37d98c281eb3 | 58 | return false; |
S_Tingle | 16:37d98c281eb3 | 59 | } |
S_Tingle | 16:37d98c281eb3 | 60 | |
S_Tingle | 16:37d98c281eb3 | 61 | void Coin::spawn(int x, int y, N5110 &lcd, Gamepad &pad) { |
S_Tingle | 16:37d98c281eb3 | 62 | drawSprite(lcd); |
S_Tingle | 16:37d98c281eb3 | 63 | if (collidePlayer(x,y,pad) == true) { |
S_Tingle | 16:37d98c281eb3 | 64 | x_coin = 100; |
S_Tingle | 16:37d98c281eb3 | 65 | y_coin = 100; |
S_Tingle | 16:37d98c281eb3 | 66 | } else { |
S_Tingle | 16:37d98c281eb3 | 67 | |
S_Tingle | 16:37d98c281eb3 | 68 | } |
S_Tingle | 13:c3b550fc2445 | 69 | } |