From b9bbec8154f64b3eec8cd33262187de77993d47a Mon Sep 17 00:00:00 2001 From: JanEhehalt Date: Tue, 29 Nov 2022 12:51:52 +0100 Subject: [PATCH] bug when setting sprite dest out of world bounds fixed --- Input/inputHandler.c | 21 ++++++--------------- game.c | 8 ++++++-- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Input/inputHandler.c b/Input/inputHandler.c index 958119e..9304ef2 100644 --- a/Input/inputHandler.c +++ b/Input/inputHandler.c @@ -135,18 +135,11 @@ void mouseInput(Game *game){ } } - // Berechnung, welche Sprites ausgewählt wurden, scuffed - // TODO: ist wirklich sehr scuffed wegen negativen koordinaten etc - // Problem: Theoretisch einfach nur schauen ob unprojected Sprite coords im Rect liegen - // Muss aber unterschieden werden ob width negativ oder so ist, aber einfach abs funktioniert nicht - // So wie es aktuell ist, funktioniert die Auswahl, aber nur solange die Kamera nicht bewegt wird + // Berechnung, welche Sprites ausgewählt wurden Vector2 rect = GetRectangle(inputHandler->rectStart); width = abs(width); height = abs(height); - //printf("Auswahl: x: %f, y: %f, w: %f, h: %f\n", rect.x, rect.y, width, height); - - // TODO: update to World Coordinates float deltaX; float deltaY; Node *current = sprites->head; @@ -157,8 +150,6 @@ void mouseInput(Game *game){ deltaX = currPos.x - camera->target.x - (rect.x + camera->target.x); deltaY = currPos.y - camera->target.y - (rect.y + camera->target.y); - //printf("deltaX: %f, deltaY: %f\n", deltaX, deltaY); - if(deltaX > 0 && deltaX < width && deltaY > 0 && deltaY < height){ current->data.selected = 1; } @@ -180,16 +171,16 @@ void mouseInput(Game *game){ float destY = inputHandler->cursorWorldPos.y; int maxWidth = (game->layers[0]->width-1) * game->layers[0]->textureWidth; int maxHeight = (game->layers[0]->height-1) * game->layers[0]->textureHeight; - if(destX < 0){ printf("OutOfBoundsDestination"); continue; } - if(destY < 0){ printf("OutOfBoundsDestination"); continue; } - if(destX > maxWidth){ printf("OutOfBoundsDestination"); continue; } - if(destY > maxHeight){ printf("OutOfBoundsDestination"); continue; } + if(destX < 0){ printf("OutOfBoundsDestination\n"); goto skip; } + if(destY < 0){ printf("OutOfBoundsDestination\n"); goto skip; } + if(destX > maxWidth){ printf("OutOfBoundsDestination\n"); goto skip; } + if(destY > maxHeight){ printf("OutOfBoundsDestination\n"); goto skip; } current->data.destX = destX; current->data.destY = destY; } - current = current->next; + skip: current = current->next; } } } diff --git a/game.c b/game.c index c7e2362..53a74d4 100644 --- a/game.c +++ b/game.c @@ -70,12 +70,16 @@ Game *GameInit() ((game->layers))[n] = IsometricMapInit(n); } - for (n = 0; n <= 10; n++) + for (n = 0; n < 10; n++) { for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { + if(i > 50 && i < 70 && j == 50){ + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); + } + switch (n) { case 0: @@ -110,7 +114,7 @@ Game *GameInit() } } - for (n = 0; n <= 10; n++) + for (n = 0; n < 10; n++) { for (i = 0; i < 20 - n * 2; i++) {