Game designed for project

Dependencies:   mbed Gamepad2

MyClasses/PaddleControl.cpp

Committer:
vaib
Date:
2020-05-19
Revision:
2:e67ca889c81b

File content as of revision 2:e67ca889c81b:


#include "PaddleControl.h"


void Paddle::init(int y,int length,int height)
{
    _y = y;  // x value on screen is fixed
    _x = WIDTH/2 - length/2;  // y depends on height of screen and height of paddle
    _height = height;
    _length = length;
    _speed = 1;  // default speed
}

void Paddle::print_lcd(N5110 &lcd)
{
    lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
}

void Paddle::update(char direction)
{
    if (direction == 'R') {
        _x-=_speed;
    } else if (direction == 'L') {
        _x+=_speed;
    }

    if (_x < 1) {
        _x = 1;
    }
    if (_x > WIDTH - _length - 1) {
        _x = WIDTH - _length - 1;
    }
}

Vector2D Paddle::get_pos() {
    Vector2D p = {_x,_y};
    return p;    
}