Fixed irritating ball redraw bug in part8-breakout-ble

This commit is contained in:
Adam Greenwood-Byrne 2021-02-23 22:17:13 +00:00
parent 1bd5a7da8b
commit 5ddc17a011

View file

@ -187,16 +187,26 @@ struct Object *objects = (struct Object *)SAFE_ADDRESS;
struct Object *ball; struct Object *ball;
struct Object *paddle; struct Object *paddle;
const int paddlewidth = 80; const int paddlewidth = 80;
const int ballradius = 15;
void removeObject(struct Object *object) void removeObject(struct Object *object)
{ {
drawRect(object->x, object->y, object->x + object->width, object->y + object->height, 0, 1); if (object->type == OBJ_BALL) {
drawCircle(object->x + ballradius, object->y + ballradius, ballradius, 0, 1);
} else {
drawRect(object->x, object->y, object->x + object->width, object->y + object->height, 0, 1);
}
object->alive = 0; object->alive = 0;
} }
void moveObjectAbs(struct Object *object, int x, int y) void moveObjectAbs(struct Object *object, int x, int y)
{ {
moveRectAbs(object->x, object->y, object->width, object->height, x, y, 0x00); if (object->type == OBJ_BALL) {
drawCircle(object->x + ballradius, object->y + ballradius, ballradius, 0, 1);
drawCircle(x + ballradius, y + ballradius, ballradius, 0x55, 1);
} else {
moveRectAbs(object->x, object->y, object->width, object->height, x, y, 0x00);
}
object->x = x; object->x = x;
object->y = y; object->y = y;
} }
@ -251,8 +261,6 @@ void initBricks()
void initBall() void initBall()
{ {
int ballradius = 15;
drawCircle(WIDTH/2, HEIGHT/2, ballradius, 0x55, 1); drawCircle(WIDTH/2, HEIGHT/2, ballradius, 0x55, 1);
objects[numobjs].type = OBJ_BALL; objects[numobjs].type = OBJ_BALL;