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:
- 10:2e441532206e
- Parent:
- 9:05fd30d491f1
- Child:
- 11:5ab36993ebc3
diff -r 05fd30d491f1 -r 2e441532206e Basket.cpp --- a/Basket.cpp Sat Apr 22 12:21:58 2017 +0000 +++ b/Basket.cpp Thu Apr 27 12:39:16 2017 +0000 @@ -10,50 +10,57 @@ } //INITILISATION FUNCTION// +//Sets x and y reference co-ordinates and sets the default score to 0 void Basket::init(int y, int width) { y_ref = y; - x_ref = WIDTH/2 - width/2; + x_ref = WIDTH/2 - width/2; //basket will be central on display basket_width = width; score = 0; } //UPDATE FUNCTIONS// +//Both move functions can be used simultaneously during a game + +//Move the basket with the joystick void Basket::move_stick(Direction d, float mag) { - stick_speed = int(mag*6.0f); + stick_speed = int(mag*6.0f); //for a full push (mag = 1) basket will move 6 pixels per loop - if (d == E) { + if (d == E) { //E = right x_ref += stick_speed; - } else if (d == W) { + } else if (d == W) { //W = left x_ref -= stick_speed; } - if (x_ref < 1) { + if (x_ref < 1) { //set boundary on the left of the display x_ref = 1; } - if (x_ref > WIDTH - basket_width - 1) { + if (x_ref > WIDTH - basket_width - 1) { //set boundary on the right of the display x_ref = WIDTH - basket_width - 1; } } +//Move the basket with the L and R buttons, this is supposed to be the easier option void Basket::move_LR(Gamepad &pad) { if (pad.check_event(Gamepad::R_PRESSED) == true) { - x_ref += 12.0f; + x_ref += 12.0f; //if R is pressed move 12 pixels right (one default basket width) } else if (pad.check_event(Gamepad::L_PRESSED) == true) { - x_ref -= 12.0f; + x_ref -= 12.0f; //if L is pressed move 12 pixels left (one default basket width) } - if (x_ref < 1) { + if (x_ref < 1) { //set boundary on the left of the display x_ref = 1; } - if (x_ref > WIDTH - basket_width - 1) { + if (x_ref > WIDTH - basket_width - 1) { //set boundary on the right of the display x_ref = WIDTH - basket_width - 1; } } //SCORE FUNCTIONS// +//Add different score for different objects (see Objects) + void Basket::add_score_1() { score++; @@ -80,6 +87,8 @@ } //DISPLAY FUNCTIONS// +//Draw the basket and make x and y reference coordinates accessible in other libraries + void Basket::draw(N5110 &lcd) { lcd.drawRect(x_ref,y_ref, 1, 2, 0);