ELEC2645 (2019/20)
/
ELEC2645_Project_el18jb
test 1 doc
Coin/Coin.cpp@15:9ea5269b4cd4, 2020-05-27 (annotated)
- Committer:
- joebarhouch
- Date:
- Wed May 27 07:52:55 2020 +0000
- Revision:
- 15:9ea5269b4cd4
- Parent:
- 14:58887d7e1072
el18jb; VOLATILE!
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 | 14:58887d7e1072 | 33 | pad.leds_off(); |
joebarhouch | 11:b3024ab59fa5 | 34 | pad.led(1, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 35 | } |
joebarhouch | 11:b3024ab59fa5 | 36 | |
joebarhouch | 14:58887d7e1072 | 37 | if(side ==1 && _y < HEIGHT *2/3 && _y >= HEIGHT/3) { |
joebarhouch | 14:58887d7e1072 | 38 | pad.leds_off(); |
joebarhouch | 11:b3024ab59fa5 | 39 | pad.led(2, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 40 | } |
joebarhouch | 11:b3024ab59fa5 | 41 | |
joebarhouch | 14:58887d7e1072 | 42 | if(side ==1 && _y >= HEIGHT*2/3) { |
joebarhouch | 14:58887d7e1072 | 43 | pad.leds_off(); |
joebarhouch | 11:b3024ab59fa5 | 44 | pad.led(3, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 45 | } |
joebarhouch | 11:b3024ab59fa5 | 46 | if(side ==0 && _y <= HEIGHT/3) { |
joebarhouch | 14:58887d7e1072 | 47 | pad.leds_off(); |
joebarhouch | 11:b3024ab59fa5 | 48 | pad.led(4, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 49 | } |
joebarhouch | 11:b3024ab59fa5 | 50 | |
joebarhouch | 14:58887d7e1072 | 51 | if(side ==0 && _y < HEIGHT* 2/3 && _y >= HEIGHT/3) { |
joebarhouch | 14:58887d7e1072 | 52 | pad.leds_off(); |
joebarhouch | 11:b3024ab59fa5 | 53 | pad.led(5, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 54 | } |
joebarhouch | 11:b3024ab59fa5 | 55 | |
joebarhouch | 14:58887d7e1072 | 56 | if(side ==0 && _y >= HEIGHT*2/3) { |
joebarhouch | 14:58887d7e1072 | 57 | pad.leds_off(); |
joebarhouch | 11:b3024ab59fa5 | 58 | pad.led(6, 0.5); |
joebarhouch | 11:b3024ab59fa5 | 59 | } |
joebarhouch | 13:cb5ed2f0cbd5 | 60 | } |
joebarhouch | 13:cb5ed2f0cbd5 | 61 | |
joebarhouch | 13:cb5ed2f0cbd5 | 62 | void Coin::set_pos(int X, int Y){ |
joebarhouch | 13:cb5ed2f0cbd5 | 63 | _x = X; |
joebarhouch | 13:cb5ed2f0cbd5 | 64 | _y = Y; |
joebarhouch | 13:cb5ed2f0cbd5 | 65 | } |
joebarhouch | 13:cb5ed2f0cbd5 | 66 | |
joebarhouch | 13:cb5ed2f0cbd5 | 67 | //accessor |
joebarhouch | 13:cb5ed2f0cbd5 | 68 | Vector2D Coin::get_pos() |
joebarhouch | 13:cb5ed2f0cbd5 | 69 | { |
joebarhouch | 13:cb5ed2f0cbd5 | 70 | Vector2D pos = {_x, _y}; |
joebarhouch | 13:cb5ed2f0cbd5 | 71 | return pos; |
joebarhouch | 13:cb5ed2f0cbd5 | 72 | } |