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-04-22
- Revision:
- 9:05fd30d491f1
- Parent:
- 8:48c5adc809e1
- Child:
- 10:2e441532206e
File content as of revision 9:05fd30d491f1:
#include "Basket.h" Basket::Basket() { } Basket::~Basket() { } //INITILISATION FUNCTION// void Basket::init(int y, int width) { y_ref = y; x_ref = WIDTH/2 - width/2; basket_width = width; score = 0; } //UPDATE FUNCTIONS// void Basket::move_stick(Direction d, float mag) { stick_speed = int(mag*6.0f); if (d == E) { x_ref += stick_speed; } else if (d == W) { x_ref -= stick_speed; } if (x_ref < 1) { x_ref = 1; } if (x_ref > WIDTH - basket_width - 1) { x_ref = WIDTH - basket_width - 1; } } 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; } } //SCORE FUNCTIONS// void Basket::add_score_1() { score++; } void Basket::add_score_2() { score = score + 2; } void Basket::add_score_5() { score = score + 5; } void Basket::add_score_10() { score = score + 10; } int Basket::get_score() { return score; } //DISPLAY FUNCTIONS// 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); } int Basket::get_x() { return x_ref; } int Basket::get_y() { return y_ref; }