From 5ddc17a0118ad3c30b8d4997c49f7625bb5f8195 Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Tue, 23 Feb 2021 22:17:13 +0000 Subject: [PATCH] Fixed irritating ball redraw bug in part8-breakout-ble --- part8-breakout-ble/kernel.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/part8-breakout-ble/kernel.c b/part8-breakout-ble/kernel.c index a3f456d..14b82cc 100644 --- a/part8-breakout-ble/kernel.c +++ b/part8-breakout-ble/kernel.c @@ -187,16 +187,26 @@ struct Object *objects = (struct Object *)SAFE_ADDRESS; struct Object *ball; struct Object *paddle; const int paddlewidth = 80; +const int ballradius = 15; 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; } 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->y = y; } @@ -251,8 +261,6 @@ void initBricks() void initBall() { - int ballradius = 15; - drawCircle(WIDTH/2, HEIGHT/2, ballradius, 0x55, 1); objects[numobjs].type = OBJ_BALL;