From 8cebf1d3f261c83ecf804040d958aede2738bc77 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 20 Feb 2024 08:20:35 -0500 Subject: [PATCH] start on a tile render queue --- game.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/game.c b/game.c index 7c88567..18d0118 100644 --- a/game.c +++ b/game.c @@ -102,6 +102,7 @@ void buildArena() { } int rabbitPosition[2] = { 60, 60 }; +int oldRabbitPosition[2] = { 60, 60 }; int rabbitLimits[2][2] = { { 20, 20 }, { 180, 180 } @@ -115,6 +116,7 @@ signed char rabbitVelocity[2] = { 0, 0 }; struct MouseStatus mouseStatus; char mousePosition[2] = { 0, 0 }; +char oldMousePosition[2] = { 0, 0 }; void setupRabbitDrawing() { rabbit.x = rabbitPosition[0]; @@ -163,6 +165,7 @@ void handleRabbitMovement() { } for (i = 0; i < 2; ++i) { + oldRabbitPosition[i] = rabbitPosition[i]; rabbitPosition[i] += (rabbitVelocity[i] / 5); if (rabbitPosition[i] < rabbitLimits[0][i]) { @@ -187,36 +190,36 @@ void handleRabbitMovement() { struct SpriteBounds bounds; +char tileRenderQueue[400]; + void drawOnlyArena() { int leftTileX, rightTileX, topTileY, bottomTileY; + char buffer[20]; + leftTileX = bounds.left / TILE_SIZE; rightTileX = bounds.right / TILE_SIZE; topTileY = bounds.top / TILE_SIZE; bottomTileY = bounds.bottom / TILE_SIZE; renderArenaTile(leftTileX, topTileY); - if (leftTileX != rightTileX) { - renderArenaTile(rightTileX, topTileY); - if (topTileY != bottomTileY) { - renderArenaTile(rightTileX, bottomTileY); - } - } - if (topTileY != bottomTileY) { - renderArenaTile(leftTileX, bottomTileY); - } + renderArenaTile(rightTileX, topTileY); + renderArenaTile(rightTileX, bottomTileY); + renderArenaTile(leftTileX, bottomTileY); } void drawOnlyMouseArena() { + mouse.x = oldMousePosition[0]; + mouse.y = oldMousePosition[1]; getSpriteBounds(&mouse, &bounds); - drawOnlyArena(); } void drawOnlyRabbitArena() { + rabbit.x = oldRabbitPosition[0]; + rabbit.y = oldRabbitPosition[1]; getSpriteBounds(&rabbit, &bounds); - drawOnlyArena(); } @@ -237,6 +240,9 @@ void calculateTargetAngle() { distanceX = sin(angle * DEG2RAD) * MOUSE_DISTANCE; distanceY = -cos(angle * DEG2RAD) * MOUSE_DISTANCE; + oldMousePosition[0] = mousePosition[0]; + oldMousePosition[1] = mousePosition[1]; + mousePosition[0] = rabbitPosition[0] + distanceX; mousePosition[1] = rabbitPosition[1] + distanceY; } @@ -271,18 +277,20 @@ int main(void) { handleRabbitMovement(); calculateTargetAngle(); - waitStartVbl(); - - setupRabbitDrawing(); - setupMouseDrawing(); drawOnlyRabbitArena(); drawOnlyMouseArena(); + setupRabbitDrawing(); + setupMouseDrawing(); renderRabbit(); renderMouse(); + + waitStartVbl(); + copyDrawBufferToDisplay(); waitEndVbl(); + if (mouseStatus.leftButtonDown) { keepRunning = 0; } }