Library that draws a basket on a Nokia N5110 LCD display and allows it to be moved left/right on the display using buttons or a joystick.
Dependents: Game_Controller_Project
Diff: Basket.cpp
- Revision:
- 8:48c5adc809e1
- Parent:
- 7:7b71dd93b2f8
- Child:
- 9:05fd30d491f1
--- a/Basket.cpp Tue Apr 04 16:31:21 2017 +0000 +++ b/Basket.cpp Tue Apr 18 14:27:06 2017 +0000 @@ -29,9 +29,9 @@ lcd.drawRect(x_ref + 11, y_ref, 1, 2, 0); } -void Basket::move(Direction d, float mag, Gamepad &pad) +void Basket::move_stick(Direction d, float mag) { - stick_speed = int(mag*10.0f); + stick_speed = int(mag*6.0f); if (d == E) { x_ref += stick_speed; @@ -47,6 +47,22 @@ } } +void Basket::move_LR(Gamepad &pad) +{ + if (pad.check_event(Gamepad::R_PRESSED) == true) { + x_ref += 12.0f; + } else if (pad.check_event(Gamepad::L_PRESSED) == true) { + x_ref -= 12.0f; + } + + if (x_ref < 1) { + x_ref = 1; + } + if (x_ref > WIDTH - basket_width - 1) { + x_ref = WIDTH - basket_width - 1; + } +} + void Basket::add_score_1() { score++;