diff --git a/README.md b/README.md index ef20ff1..e9151f5 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,6 @@ Fantasy Welt oder Realistisch? ## TODO -- Bug with movement of sprite +- Bug with movement of sprite after spawning a few other sprites - Drawn Rectangle problems with negative width/height - Selecting Sprites for moving all selected to the same destination \ No newline at end of file diff --git a/inputHandling.h b/inputHandling.h index fdd3359..8642c82 100644 --- a/inputHandling.h +++ b/inputHandling.h @@ -1,7 +1,6 @@ struct InputHandler{ int pressed; Vector2 rectStart; - int clicked; Vector2 cursorPos; } InputHandler; @@ -41,14 +40,13 @@ void mouseInput(struct InputHandler *inputHandler, struct Sprite *sprites, int * float width = GetMousePosition().x - inputHandler->rectStart.x; float height = GetMousePosition().y - inputHandler->rectStart.y; if(width + height <= 1){ - printf("Klick\n"); + //printf("Klick\n"); addSprite(sprites, spriteAmount, texture, inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2, inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2); } } if(IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)){ - inputHandler->clicked = 1; - sprites->clicked = 1; + sprites->hasDestination = 1; sprites->destX = inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2; sprites->destY = inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2; } diff --git a/main.c b/main.c index 121e1d3..e7ba166 100644 --- a/main.c +++ b/main.c @@ -51,19 +51,22 @@ int main(){ // Sprites move towards their destination + float movementSpeed = 10.0f; for(i=0; i < spriteAmount; i++){ - if(sprites[i].clicked){ + if(sprites[i].hasDestination == 1){ Vector2 movement = {sprites[i].destX - sprites->x, sprites[i].destY - sprites->y}; - if(Vector2Length(movement) < 10.0f){ - inputHandler.clicked = false; - sprites->clicked = false; + if(Vector2Length(movement) < movementSpeed){ + sprites->hasDestination = 0; + sprites->x = sprites->destX; + sprites->y = sprites->destY; + } + else{ + movement = Vector2Normalize(movement); + movement = Vector2Scale(movement, movementSpeed); + sprites->x += movement.x; + sprites->y += movement.y; } - - movement = Vector2Normalize(movement); - movement = Vector2Scale(movement, 10); - sprites->x += movement.x; - sprites->y += movement.y; } } diff --git a/main.o b/main.o index 0fbeb87..3b35452 100644 Binary files a/main.o and b/main.o differ diff --git a/spiel b/spiel index a5f0a48..73ce6ab 100755 Binary files a/spiel and b/spiel differ diff --git a/sprite.h b/sprite.h index 48db6cf..280f887 100644 --- a/sprite.h +++ b/sprite.h @@ -4,7 +4,7 @@ struct Sprite{ float y; float destX; float destY; - int clicked; + int hasDestination; } Sprite; void addSprite(struct Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){ @@ -13,10 +13,10 @@ void addSprite(struct Sprite *sprites, int *spriteAmount, Texture2D *texture, in (sprites + *spriteAmount) -> x = x; (sprites + *spriteAmount) -> y = y; (*spriteAmount)++; - printf("SPRITE\n"); + //printf("SPRITE\n"); } else{ - printf("Voll\n"); + printf("Sprites Voll\n"); } }