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
Basket.cpp
- Committer:
- Nathanj94
- Date:
- 2017-03-23
- Revision:
- 5:32421eb42841
- Parent:
- 4:4ce558075c32
- Child:
- 6:2aec1ed2a75a
File content as of revision 5:32421eb42841:
#include "Basket.h" Basket::Basket() { } Basket::~Basket() { } void Basket::init(int y, int width) { y_ref = y; x_ref = WIDTH/2 - width/2; basket_width = width; 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::move(Direction d, float mag, Gamepad &pad) { stick_speed = int(mag*8.0f); if (d == E) { x_ref += stick_speed; } else if (d == W) { x_ref -= stick_speed; } 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 (x_ref < 1) { x_ref = 1; } if (x_ref > WIDTH - basket_width - 1) { x_ref = WIDTH - basket_width - 1; } } void Basket::add_score() { score++; } int Basket::get_score() { return score; } int Basket::get_x() { return x_ref; } int Basket::get_y() { return y_ref; }