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-14
Revision:
1:5e564d218751
Parent:
0:7e132fca6044
Child:
2:5d4f2c3f3c0a

File content as of revision 1:5e564d218751:

#include "Basket.h"

Basket::Basket()
{
    
}

Basket::~Basket()
{
    
}
/** Basket_init
 *  
 *  initialise the basket with a y-coordinate and width
 *  by default the y-coordinate will be 41 and the width 
 *  is 12 pixels but this could be altered by 
 *  difficulty settings 
 *  
 *  @param y - column number (0 to 47)
 *  @param width - basket width (0 to 83)
 *
 */
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;
}

/** Basket_draw
 *
 *  draw the basket on the lcd using x and y parameters set in Basket_init
 *
 *  @param N5110 - lcd display
 *
 */
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);
}

/** Basket_move
 *
 *  move the basket left and right at a set y-coordinate
 *  using the joystick or L/R buttons
 *
 *  @param d - joystick direction (N,NE,E,SE,S,SW,W,NW)
 *  @param mag - joystick directional magnitude (0 to 1)
 *  @param pad - call the Gamepad class to interact w/ buttons
 *
 */
void Basket::Basket_move(Direction d, float mag, Gamepad &pad)
{
    basket_speed = int(mag*5.0f);
    
    if (d == E || pad.check_event(Gamepad::R_PRESSED)) {
        basket_x += basket_speed;
    } else if (d == W || pad.check_event(Gamepad::L_PRESSED)) {
        basket_x -= basket_speed;
    }
    
    if (basket_x < 1) {
        basket_x = 1;
    }
    if (basket_x > WIDTH - basket_width - 1) {
        basket_x = WIDTH - basket_width - 1;
    }
}

/** Basket_score
 * 
 *  set score
 *
 */
void Basket::Basket_score()
{
    basket_score++;
}

/** get_Basket_score
 *
 *  return score
 *
 */
int Basket::get_Basket_score()
{
    return basket_score;
}
/*
Vector2D Basket::Basket_position()
{
    Vector2D pos = (basket_x,basket_y);
    return pos;
}
*/