![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Game designed for project
MyClasses/PaddleControl/PaddleControl.cpp@3:5ede4ac61af1, 2020-05-24 (annotated)
- Committer:
- vaib
- Date:
- Sun May 24 09:15:25 2020 +0000
- Revision:
- 3:5ede4ac61af1
Created a class for the balls's movement and am now working of the obstacles/blocks
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vaib | 3:5ede4ac61af1 | 1 | |
vaib | 3:5ede4ac61af1 | 2 | #include "PaddleControl.h"\ |
vaib | 3:5ede4ac61af1 | 3 | |
vaib | 3:5ede4ac61af1 | 4 | void PaddleControl::init(int y,int length,int height) |
vaib | 3:5ede4ac61af1 | 5 | { |
vaib | 3:5ede4ac61af1 | 6 | _y = y; |
vaib | 3:5ede4ac61af1 | 7 | _x = WIDTH/2 - length/2; |
vaib | 3:5ede4ac61af1 | 8 | _height = height; |
vaib | 3:5ede4ac61af1 | 9 | _length = length; |
vaib | 3:5ede4ac61af1 | 10 | _speed = 1; |
vaib | 3:5ede4ac61af1 | 11 | } |
vaib | 3:5ede4ac61af1 | 12 | |
vaib | 3:5ede4ac61af1 | 13 | void PaddleControl::print_lcd(N5110 &lcd) |
vaib | 3:5ede4ac61af1 | 14 | { |
vaib | 3:5ede4ac61af1 | 15 | lcd.drawRect(_x,_y,_length,_height,FILL_BLACK); |
vaib | 3:5ede4ac61af1 | 16 | } |
vaib | 3:5ede4ac61af1 | 17 | |
vaib | 3:5ede4ac61af1 | 18 | void PaddleControl::update_direction(char direction) |
vaib | 3:5ede4ac61af1 | 19 | { |
vaib | 3:5ede4ac61af1 | 20 | if (direction == 'R') { |
vaib | 3:5ede4ac61af1 | 21 | _x-=_speed; |
vaib | 3:5ede4ac61af1 | 22 | } else if (direction == 'L') { |
vaib | 3:5ede4ac61af1 | 23 | _x+=_speed; |
vaib | 3:5ede4ac61af1 | 24 | } |
vaib | 3:5ede4ac61af1 | 25 | |
vaib | 3:5ede4ac61af1 | 26 | if (_x < 1) { |
vaib | 3:5ede4ac61af1 | 27 | _x = 1; |
vaib | 3:5ede4ac61af1 | 28 | } |
vaib | 3:5ede4ac61af1 | 29 | if (_x > WIDTH - _length - 1) { |
vaib | 3:5ede4ac61af1 | 30 | _x = WIDTH - _length - 1; |
vaib | 3:5ede4ac61af1 | 31 | } |
vaib | 3:5ede4ac61af1 | 32 | } |
vaib | 3:5ede4ac61af1 | 33 | |
vaib | 3:5ede4ac61af1 | 34 | void PaddleControl::set_speed(int speed) |
vaib | 3:5ede4ac61af1 | 35 | { |
vaib | 3:5ede4ac61af1 | 36 | _speed = speed; |
vaib | 3:5ede4ac61af1 | 37 | } |
vaib | 3:5ede4ac61af1 | 38 | |
vaib | 3:5ede4ac61af1 | 39 | |
vaib | 3:5ede4ac61af1 | 40 | Vector2D PaddleControl::get_position() |
vaib | 3:5ede4ac61af1 | 41 | { |
vaib | 3:5ede4ac61af1 | 42 | Vector2D p = {_x,_y}; |
vaib | 3:5ede4ac61af1 | 43 | return p; |
vaib | 3:5ede4ac61af1 | 44 | } |