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

38
game.c
View File

@ -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; }
}