4
Diff: Ball1.cpp
- Revision:
- 5:381cd0ea08aa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ball1.cpp Thu May 04 06:38:59 2017 +0000 @@ -0,0 +1,93 @@ +#include "Ball1.h" + +Ball1::Ball1() +{ + +} + +Ball1::~Ball1() +{ + +} + +void Ball1::init(int size,int speed) +{ + + _size = size; + + _x = WIDTH/2 - _size/2; + _y = HEIGHT/2 - _size/2; + + + + _velocity.x = speed; + _velocity.y = speed; } + + +void Ball1::draw(N5110 &lcd) +{ + lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); +} + + + +void Ball1::update(Direction d,float mag) +{ + + + + + _velocity.x = int(mag*1.0f); + _velocity.y = int(mag*1.0f); // scale is arbitrary, could be changed in future + + // update y value depending on direction of movement + // North is decrement as origin is at the top-left so decreasing moves up + if (d == N) { + _y+=_velocity.y; + } else if (d == S) { + _y+=_velocity.y; + } + + if (d == W) { + _x+=_velocity.x; + } else if (d == E) { + _x+=_velocity.x; + } + + + + +} + + + +void Ball1::set_velocity(Vector2D v) +{ + _velocity.x = v.x; + _velocity.y = v.y; +} + +Vector2D Ball1::get_velocity() +{ + Vector2D v = {_velocity.x,_velocity.y}; + return v; +} + +Vector2D Ball1::get_pos() +{ + Vector2D p = {_x,_y}; + return p; +} + +void Ball1::set_pos(Vector2D p) +{ + _x = p.x; + _y = p.y; +} + + +void Ball1::set_size(int size) +{ + _size = size; +} +