Class containing methods to draw a ball within the maze game with the specified position, size and fill style parameters.
Ball.cpp@1:ba8bb10ebd5a, 2017-04-07 (annotated)
- Committer:
- el15mh
- Date:
- Fri Apr 07 10:29:08 2017 +0000
- Revision:
- 1:ba8bb10ebd5a
- Parent:
- 0:4c58ed26b6ea
- Child:
- 2:bcb96ab2848b
whole program basic with menu interface
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15mh | 0:4c58ed26b6ea | 1 | // |
el15mh | 0:4c58ed26b6ea | 2 | // ball.cpp |
el15mh | 0:4c58ed26b6ea | 3 | // |
el15mh | 0:4c58ed26b6ea | 4 | // |
el15mh | 0:4c58ed26b6ea | 5 | // Created by Max Houghton on 19/03/2017. |
el15mh | 0:4c58ed26b6ea | 6 | // |
el15mh | 0:4c58ed26b6ea | 7 | // |
el15mh | 0:4c58ed26b6ea | 8 | |
el15mh | 0:4c58ed26b6ea | 9 | #include "Ball.h" |
el15mh | 0:4c58ed26b6ea | 10 | |
el15mh | 0:4c58ed26b6ea | 11 | Ball::Ball() |
el15mh | 0:4c58ed26b6ea | 12 | { |
el15mh | 0:4c58ed26b6ea | 13 | |
el15mh | 0:4c58ed26b6ea | 14 | } |
el15mh | 0:4c58ed26b6ea | 15 | |
el15mh | 0:4c58ed26b6ea | 16 | Ball::~Ball() |
el15mh | 0:4c58ed26b6ea | 17 | { |
el15mh | 0:4c58ed26b6ea | 18 | |
el15mh | 0:4c58ed26b6ea | 19 | } |
el15mh | 0:4c58ed26b6ea | 20 | |
el15mh | 1:ba8bb10ebd5a | 21 | void Ball::init(int x, int y, int radius) |
el15mh | 1:ba8bb10ebd5a | 22 | { |
el15mh | 1:ba8bb10ebd5a | 23 | // properties of ball are set with values passed down from engine |
el15mh | 1:ba8bb10ebd5a | 24 | _x = x; |
el15mh | 1:ba8bb10ebd5a | 25 | _y = y; |
el15mh | 1:ba8bb10ebd5a | 26 | _radius = radius; |
el15mh | 0:4c58ed26b6ea | 27 | |
el15mh | 1:ba8bb10ebd5a | 28 | velocity.x = SPEED; // arbitrary speed of moving 1 pixel per update |
el15mh | 1:ba8bb10ebd5a | 29 | velocity.y = SPEED; |
el15mh | 0:4c58ed26b6ea | 30 | |
el15mh | 1:ba8bb10ebd5a | 31 | // printf("INPUT: x = %i, y = %i, radius = %i \n", x, y, radius); |
el15mh | 1:ba8bb10ebd5a | 32 | // printf("DRAW FUNCTION: x = %f, y = %f, radius = %f \n", _x, _y, _radius); |
el15mh | 0:4c58ed26b6ea | 33 | } |
el15mh | 0:4c58ed26b6ea | 34 | |
el15mh | 1:ba8bb10ebd5a | 35 | void Ball::update() |
el15mh | 1:ba8bb10ebd5a | 36 | { |
el15mh | 1:ba8bb10ebd5a | 37 | // new coordinates for the centre of the ball |
el15mh | 1:ba8bb10ebd5a | 38 | _x += velocity.x; |
el15mh | 1:ba8bb10ebd5a | 39 | _y += velocity.y; |
el15mh | 1:ba8bb10ebd5a | 40 | |
el15mh | 1:ba8bb10ebd5a | 41 | } |
el15mh | 0:4c58ed26b6ea | 42 | |
el15mh | 1:ba8bb10ebd5a | 43 | void Ball::draw(N5110 &lcd) |
el15mh | 1:ba8bb10ebd5a | 44 | { |
el15mh | 1:ba8bb10ebd5a | 45 | lcd.drawCircle(_x, _y, _radius, FILL_BLACK); |
el15mh | 1:ba8bb10ebd5a | 46 | } |