ELEC2645 (2019/20)
/
ELEC2645_Project_el18vgt
Game designed for project
Diff: MyClasses/PaddleControl/PaddleControl.cpp
- Revision:
- 3:5ede4ac61af1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyClasses/PaddleControl/PaddleControl.cpp Sun May 24 09:15:25 2020 +0000 @@ -0,0 +1,44 @@ + +#include "PaddleControl.h"\ + +void PaddleControl::init(int y,int length,int height) +{ + _y = y; + _x = WIDTH/2 - length/2; + _height = height; + _length = length; + _speed = 1; +} + +void PaddleControl::print_lcd(N5110 &lcd) +{ + lcd.drawRect(_x,_y,_length,_height,FILL_BLACK); +} + +void PaddleControl::update_direction(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; + } +} + +void PaddleControl::set_speed(int speed) +{ + _speed = speed; +} + + +Vector2D PaddleControl::get_position() +{ + Vector2D p = {_x,_y}; + return p; +} \ No newline at end of file