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-17
Revision:
2:5d4f2c3f3c0a
Parent:
1:5e564d218751
Child:
3:d8deea6454df

File content as of revision 2:5d4f2c3f3c0a:

#include "Basket.h"

Basket::Basket()
{
    
}

Basket::~Basket()
{
    
}

void Basket::Basket_init(int y, int width)
{
    basket_y = y;
    basket_x = WIDTH/2 - width/2;
    basket_width = width;
    basket_speed = 1;
    basket_score = 0;
}

void Basket::Basket_draw(N5110 &lcd)
{
    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);
    
    if (d == E) {
        basket_x += basket_speed;
    } else if (d == W) {
        basket_x -= basket_speed;
    }
    
    if (basket_x < 1) {
        basket_x = 1;
    }
    if (basket_x > WIDTH - basket_width - 1) {
        basket_x = WIDTH - basket_width - 1;
    }
}

void Basket::Basket_score()
{
    basket_score++;
}

int Basket::get_Basket_score()
{
    return basket_score;
}