diff --git a/alyson/src/animation/sprite.c b/alyson/src/animation/sprite.c index 62f9a3c..27b1c1c 100644 --- a/alyson/src/animation/sprite.c +++ b/alyson/src/animation/sprite.c @@ -37,7 +37,24 @@ void UpdateSpriteAnimation(SpriteAnimation self, float dt) { } void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position) { - Vector2 drawpos = Vector2Add(position, Vector2Scale(spriteAnimation->size, 2.f)); +#ifdef _DEBUG + DrawCircleV(position, 5, DARKGREEN); +#endif + Rectangle destination = (Rectangle){ + 0, + 0, + spriteAnimation->size.x * spriteAnimation->scale, + spriteAnimation->size.y * spriteAnimation->scale + } ; + + Vector2 origin = (Vector2){ + .x = position.x + destination.width/2.f, + .y = position.y + destination.height/2.f + }; +#ifdef _DEBUG + DrawCircleV(origin, 5, RED); +#endif + DrawTexturePro( spriteAnimation->texture, (Rectangle){ @@ -46,16 +63,14 @@ void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position) { spriteAnimation->sourceRect.width, spriteAnimation->sourceRect.height }, - (Rectangle){ - position.x, - position.y, - spriteAnimation->size.x * spriteAnimation->scale, - spriteAnimation->size.y * spriteAnimation->scale - }, - position, + destination, + origin, spriteAnimation->rotation, WHITE ); +#ifdef _DEBUG + DrawRectangleLinesEx(destination, 2, BLACK); +#endif } void DestroySpriteAnimation(SpriteAnimation spriteAnimation) diff --git a/assets/karl-heinz_head.png b/assets/karl-heinz_head.png new file mode 100644 index 0000000..5e1a26c Binary files /dev/null and b/assets/karl-heinz_head.png differ diff --git a/src/main.c b/src/main.c index 892cbc8..839eee9 100644 --- a/src/main.c +++ b/src/main.c @@ -20,24 +20,39 @@ int main(int argc, char** argv) { InitWindow(900, 600, "Colysis"); - SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_UNDECORATED); - Texture2D gery = LoadTexture(ASSETS_PATH "/gery_hand.png"); + SetConfigFlags(FLAG_WINDOW_RESIZABLE); + Texture2D gery = LoadTexture(ASSETS_PATH "/karl-heinz_head.png"); - SpriteAnimation geryanim = CreateSpriteAnimation(gery, (Vector2){64*5,64}, (Vector2){64,64}, 0.f, 1.f, 5, 0.2f); + SpriteAnimation geryanim = CreateSpriteAnimation(gery, (Vector2){64*14,64}, (Vector2){64,64}, 0.f, 4.f, 5, 0.15f); + + Camera2D camera = { 0 }; + camera.target = (Vector2){0,0}; + camera.offset = (Vector2){GetScreenWidth()/2.f,GetScreenHeight()/2.f}; + camera.rotation = 0.f; + camera.zoom = 1.f; while (!WindowShouldClose()) { ClearBackground((Color){ 0x00, 0x6d, 0xfb }); float dt = GetFrameTime(); + UpdateSpriteAnimation(geryanim, dt); BeginDrawing(); { - DrawTextFull(GetFontDefault(), "Darling, I'm Home!", (Vector2){20,20}, TEXT_ORIENTATION_RIGHT, 0, 24, 5, 5, RAYWHITE); + BeginMode2D(camera); + { + DrawSpriteAnimation(geryanim, (Vector2){0,0}); - DrawSpriteAnimation(geryanim, (Vector2){GetScreenWidth()/2.f, GetScreenHeight()/2.f}); + } + EndMode2D(); + + { + DrawTextFull(GetFontDefault(), "Darling, I'm Home!", (Vector2){20,20}, TEXT_ORIENTATION_RIGHT, 0, 24, 5, 5, RAYWHITE); + + } } EndDrawing();