start on a tile render queue

This commit is contained in:
John Bintz 2024-02-20 08:20:35 -05:00
parent a30af87485
commit 8cebf1d3f2
1 changed files with 23 additions and 15 deletions

32
game.c
View File

@ -102,6 +102,7 @@ void buildArena() {
} }
int rabbitPosition[2] = { 60, 60 }; int rabbitPosition[2] = { 60, 60 };
int oldRabbitPosition[2] = { 60, 60 };
int rabbitLimits[2][2] = { int rabbitLimits[2][2] = {
{ 20, 20 }, { 20, 20 },
{ 180, 180 } { 180, 180 }
@ -115,6 +116,7 @@ signed char rabbitVelocity[2] = { 0, 0 };
struct MouseStatus mouseStatus; struct MouseStatus mouseStatus;
char mousePosition[2] = { 0, 0 }; char mousePosition[2] = { 0, 0 };
char oldMousePosition[2] = { 0, 0 };
void setupRabbitDrawing() { void setupRabbitDrawing() {
rabbit.x = rabbitPosition[0]; rabbit.x = rabbitPosition[0];
@ -163,6 +165,7 @@ void handleRabbitMovement() {
} }
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {
oldRabbitPosition[i] = rabbitPosition[i];
rabbitPosition[i] += (rabbitVelocity[i] / 5); rabbitPosition[i] += (rabbitVelocity[i] / 5);
if (rabbitPosition[i] < rabbitLimits[0][i]) { if (rabbitPosition[i] < rabbitLimits[0][i]) {
@ -187,36 +190,36 @@ void handleRabbitMovement() {
struct SpriteBounds bounds; struct SpriteBounds bounds;
char tileRenderQueue[400];
void drawOnlyArena() { void drawOnlyArena() {
int leftTileX, rightTileX, int leftTileX, rightTileX,
topTileY, bottomTileY; topTileY, bottomTileY;
char buffer[20];
leftTileX = bounds.left / TILE_SIZE; leftTileX = bounds.left / TILE_SIZE;
rightTileX = bounds.right / TILE_SIZE; rightTileX = bounds.right / TILE_SIZE;
topTileY = bounds.top / TILE_SIZE; topTileY = bounds.top / TILE_SIZE;
bottomTileY = bounds.bottom / TILE_SIZE; bottomTileY = bounds.bottom / TILE_SIZE;
renderArenaTile(leftTileX, topTileY); renderArenaTile(leftTileX, topTileY);
if (leftTileX != rightTileX) {
renderArenaTile(rightTileX, topTileY); renderArenaTile(rightTileX, topTileY);
if (topTileY != bottomTileY) {
renderArenaTile(rightTileX, bottomTileY); renderArenaTile(rightTileX, bottomTileY);
}
}
if (topTileY != bottomTileY) {
renderArenaTile(leftTileX, bottomTileY); renderArenaTile(leftTileX, bottomTileY);
}
} }
void drawOnlyMouseArena() { void drawOnlyMouseArena() {
mouse.x = oldMousePosition[0];
mouse.y = oldMousePosition[1];
getSpriteBounds(&mouse, &bounds); getSpriteBounds(&mouse, &bounds);
drawOnlyArena(); drawOnlyArena();
} }
void drawOnlyRabbitArena() { void drawOnlyRabbitArena() {
rabbit.x = oldRabbitPosition[0];
rabbit.y = oldRabbitPosition[1];
getSpriteBounds(&rabbit, &bounds); getSpriteBounds(&rabbit, &bounds);
drawOnlyArena(); drawOnlyArena();
} }
@ -237,6 +240,9 @@ void calculateTargetAngle() {
distanceX = sin(angle * DEG2RAD) * MOUSE_DISTANCE; distanceX = sin(angle * DEG2RAD) * MOUSE_DISTANCE;
distanceY = -cos(angle * DEG2RAD) * MOUSE_DISTANCE; distanceY = -cos(angle * DEG2RAD) * MOUSE_DISTANCE;
oldMousePosition[0] = mousePosition[0];
oldMousePosition[1] = mousePosition[1];
mousePosition[0] = rabbitPosition[0] + distanceX; mousePosition[0] = rabbitPosition[0] + distanceX;
mousePosition[1] = rabbitPosition[1] + distanceY; mousePosition[1] = rabbitPosition[1] + distanceY;
} }
@ -271,18 +277,20 @@ int main(void) {
handleRabbitMovement(); handleRabbitMovement();
calculateTargetAngle(); calculateTargetAngle();
waitStartVbl();
setupRabbitDrawing();
setupMouseDrawing();
drawOnlyRabbitArena(); drawOnlyRabbitArena();
drawOnlyMouseArena(); drawOnlyMouseArena();
setupRabbitDrawing();
setupMouseDrawing();
renderRabbit(); renderRabbit();
renderMouse(); renderMouse();
waitStartVbl();
copyDrawBufferToDisplay(); copyDrawBufferToDisplay();
waitEndVbl(); waitEndVbl();
if (mouseStatus.leftButtonDown) { keepRunning = 0; } if (mouseStatus.leftButtonDown) { keepRunning = 0; }
} }