James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Ball/Ball.cpp

Committer:
JamesCummins
Date:
2019-04-11
Revision:
10:40c77d69e83c
Parent:
9:ce0a12fb205b
Child:
11:2cf0d4ce8677

File content as of revision 10:40c77d69e83c:

#include 'Ball.h'

Ball::Ball()
{}

Ball::~Ball()
{}

void Ball::init(int radius){
    _radius = radius;
    _x = 48;
    _y = 24;
}

void Ball::draw (N5110 &lcd){
    lcd.drawCircle(_x, _y, 4, FILL_BLACK);
}

void Ball::update(FXOS8700CQ &accelerometer){
    acc_values = accelerometer.get_values();
    _accel.x = acc_values.ax;
    _accel.y = acc_values.ay;
    
    _velocity.x += accel.x;
    _velocity.y += accel.y;
    
    _x += _velocity.x;
    _y += _velocity.y;
}

Vector2D Ball::get_position(){
    Vector2D pos = {_x, _y};
    return pos;
}

Vector2D Ball::get_velocity(){
    Vector2D vel = {_velocity.x, _velocity.y};
    return vel;
}

Vector2D Ball::get_accel(){
    Vector2D accel = {_accel.x, _accel.y};
    return accel;
}

int Ball::get_radius(){
    int radius = _radius;
    return radius;
}

void Ball::set_velocity(Vector2D vel){
    _velocity.x = vel.x;
    _velocity.y = vel.y;
}

void Ball::set_position(Vector2D pos){
    _x = pos.x;
    _y = pos.y;
}

void Ball::set_radius(int radius){
    _radius = radius;
}