ELEC2645 (2019/20)
/
ELEC2645_Project_el18jb
test 1 doc
Coin/Coin.cpp@13:cb5ed2f0cbd5, 2020-05-27 (annotated)
- Committer:
- joebarhouch
- Date:
- Wed May 27 04:36:22 2020 +0000
- Revision:
- 13:cb5ed2f0cbd5
- Parent:
- 12:eb8d30593e95
- Child:
- 14:58887d7e1072
Coin reset
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joebarhouch | 11:b3024ab59fa5 | 1 | #include "Coin.h" |
joebarhouch | 11:b3024ab59fa5 | 2 | |
joebarhouch | 12:eb8d30593e95 | 3 | Coin::Coin() |
joebarhouch | 11:b3024ab59fa5 | 4 | { |
joebarhouch | 11:b3024ab59fa5 | 5 | } |
joebarhouch | 11:b3024ab59fa5 | 6 | |
joebarhouch | 11:b3024ab59fa5 | 7 | Coin::~Coin() |
joebarhouch | 11:b3024ab59fa5 | 8 | { |
joebarhouch | 11:b3024ab59fa5 | 9 | |
joebarhouch | 11:b3024ab59fa5 | 10 | } |
joebarhouch | 11:b3024ab59fa5 | 11 | |
joebarhouch | 12:eb8d30593e95 | 12 | void Coin::init(){ |
joebarhouch | 12:eb8d30593e95 | 13 | _x = WIDTH /2; |
joebarhouch | 12:eb8d30593e95 | 14 | _y = HEIGHT /2 -5; |
joebarhouch | 12:eb8d30593e95 | 15 | } |
joebarhouch | 11:b3024ab59fa5 | 16 | |
joebarhouch | 11:b3024ab59fa5 | 17 | void Coin::draw(N5110 &lcd) |
joebarhouch | 11:b3024ab59fa5 | 18 | { |
joebarhouch | 12:eb8d30593e95 | 19 | lcd.drawCircle(_x, _y, 1, FILL_TRANSPARENT); |
joebarhouch | 12:eb8d30593e95 | 20 | lcd.drawCircle(_x, _y, 2, FILL_TRANSPARENT); |
joebarhouch | 12:eb8d30593e95 | 21 | |
joebarhouch | 11:b3024ab59fa5 | 22 | } |
joebarhouch | 11:b3024ab59fa5 | 23 | |
joebarhouch | 11:b3024ab59fa5 | 24 | void Coin::show(Gamepad &pad) |
joebarhouch | 11:b3024ab59fa5 | 25 | { |
joebarhouch | 11:b3024ab59fa5 | 26 | if(_x < WIDTH/2) { |
joebarhouch | 11:b3024ab59fa5 | 27 | side = 1; |
joebarhouch | 11:b3024ab59fa5 | 28 | } else { |
joebarhouch | 11:b3024ab59fa5 | 29 | side = 0; |
joebarhouch | 11:b3024ab59fa5 | 30 | } |
joebarhouch | 11:b3024ab59fa5 | 31 | |
joebarhouch | 11:b3024ab59fa5 | 32 | if(side ==1 && _y <= HEIGHT/3) { |
joebarhouch | 11:b3024ab59fa5 | 33 | pad.led(1, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 34 | } |
joebarhouch | 11:b3024ab59fa5 | 35 | |
joebarhouch | 11:b3024ab59fa5 | 36 | if(side ==1 && _y < HEIGHT /3 && _y >= HEIGHT/3) { |
joebarhouch | 11:b3024ab59fa5 | 37 | pad.led(2, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 38 | } |
joebarhouch | 11:b3024ab59fa5 | 39 | |
joebarhouch | 11:b3024ab59fa5 | 40 | if(side ==1 && _y >= HEIGHT/3) { |
joebarhouch | 11:b3024ab59fa5 | 41 | pad.led(3, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 42 | } |
joebarhouch | 11:b3024ab59fa5 | 43 | if(side ==0 && _y <= HEIGHT/3) { |
joebarhouch | 11:b3024ab59fa5 | 44 | pad.led(4, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 45 | } |
joebarhouch | 11:b3024ab59fa5 | 46 | |
joebarhouch | 11:b3024ab59fa5 | 47 | if(side ==0 && _y < HEIGHT /3 && _y >= HEIGHT/3) { |
joebarhouch | 11:b3024ab59fa5 | 48 | pad.led(5, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 49 | } |
joebarhouch | 11:b3024ab59fa5 | 50 | |
joebarhouch | 11:b3024ab59fa5 | 51 | if(side ==0 && _y >= HEIGHT/3) { |
joebarhouch | 11:b3024ab59fa5 | 52 | pad.led(6, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 53 | } |
joebarhouch | 13:cb5ed2f0cbd5 | 54 | } |
joebarhouch | 13:cb5ed2f0cbd5 | 55 | |
joebarhouch | 13:cb5ed2f0cbd5 | 56 | void Coin::set_pos(int X, int Y){ |
joebarhouch | 13:cb5ed2f0cbd5 | 57 | _x = X; |
joebarhouch | 13:cb5ed2f0cbd5 | 58 | _y = Y; |
joebarhouch | 13:cb5ed2f0cbd5 | 59 | } |
joebarhouch | 13:cb5ed2f0cbd5 | 60 | |
joebarhouch | 13:cb5ed2f0cbd5 | 61 | //accessor |
joebarhouch | 13:cb5ed2f0cbd5 | 62 | Vector2D Coin::get_pos() |
joebarhouch | 13:cb5ed2f0cbd5 | 63 | { |
joebarhouch | 13:cb5ed2f0cbd5 | 64 | Vector2D pos = {_x, _y}; |
joebarhouch | 13:cb5ed2f0cbd5 | 65 | return pos; |
joebarhouch | 13:cb5ed2f0cbd5 | 66 | } |