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:
- 5:32421eb42841
- Parent:
- 4:4ce558075c32
- Child:
- 6:2aec1ed2a75a
--- a/Basket.cpp Tue Mar 21 11:08:39 2017 +0000 +++ b/Basket.cpp Thu Mar 23 15:24:22 2017 +0000 @@ -10,60 +10,67 @@ } -void Basket::Basket_init(int y, int width) +void Basket::init(int y, int width) { - basket_y = y; - basket_x = WIDTH/2 - width/2; + y_ref = y; + x_ref = WIDTH/2 - width/2; basket_width = width; - basket_speed = 1; - basket_score = 0; + score = 0; +} + +void Basket::draw(N5110 &lcd) +{ + lcd.drawRect(x_ref,y_ref, 1, 2, 0); + lcd.drawRect(x_ref + 1, y_ref + 2,1,2,0); + lcd.setPixel(x_ref + 2, y_ref + 4); + lcd.drawRect(x_ref + 2, y_ref + 5, basket_width - 4, 1, 0); + lcd.setPixel(x_ref + 9, y_ref + 4); + lcd.drawRect(x_ref + 10, y_ref + 2, 1, 2, 0); + lcd.drawRect(x_ref + 11, y_ref, 1, 2, 0); } -void Basket::Basket_draw(N5110 &lcd) +void Basket::move(Direction d, float mag, Gamepad &pad) { - lcd.drawRect(basket_x,basket_y, 1, 2, 0); - lcd.drawRect(basket_x + 1, basket_y + 2,1,2,0); - lcd.setPixel(basket_x + 2, basket_y + 4); - lcd.drawRect(basket_x + 2, basket_y + 5, basket_width - 4, 1, 0); - lcd.setPixel(basket_x + 9, basket_y + 4); - lcd.drawRect(basket_x + 10, basket_y + 2, 1, 2, 0); - lcd.drawRect(basket_x + 11, basket_y, 1, 2, 0); -} - -void Basket::Basket_move(Direction d, float mag) -{ - basket_speed = int(mag*8.0f); + stick_speed = int(mag*8.0f); if (d == E) { - basket_x += basket_speed; + x_ref += stick_speed; } else if (d == W) { - basket_x -= basket_speed; + x_ref -= stick_speed; } - if (basket_x < 1) { - basket_x = 1; + bumper_speed = 5; + + if (pad.check_event(Gamepad::R_PRESSED)) { + x_ref += bumper_speed; + } else if (pad.check_event(Gamepad::L_PRESSED)) { + x_ref -= bumper_speed; } - if (basket_x > WIDTH - basket_width - 1) { - basket_x = WIDTH - basket_width - 1; + + if (x_ref < 1) { + x_ref = 1; + } + if (x_ref > WIDTH - basket_width - 1) { + x_ref = WIDTH - basket_width - 1; } } -void Basket::Basket_score() +void Basket::add_score() { - basket_score++; + score++; } -int Basket::get_Basket_score() +int Basket::get_score() { - return basket_score; + return score; } -int Basket::get_Basket_x() +int Basket::get_x() { - return basket_x; + return x_ref; } -int Basket::get_Basket_y() +int Basket::get_y() { - return basket_y; + return y_ref; } \ No newline at end of file