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-31
Revision:
6:2aec1ed2a75a
Parent:
5:32421eb42841
Child:
7:7b71dd93b2f8

File content as of revision 6:2aec1ed2a75a:

#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_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;
}

int Basket::get_x()
{
    return x_ref;
}

int Basket::get_y()
{
    return y_ref;
}