diff --git a/alyson/src/animation/sprite.c b/alyson/src/animation/sprite.c index 27b1c1c..6f305e9 100644 --- a/alyson/src/animation/sprite.c +++ b/alyson/src/animation/sprite.c @@ -4,6 +4,11 @@ #include "raylib.h" #include "raymath.h" +#ifdef _DEBUG +#include +#endif + + SpriteAnimation CreateSpriteAnimation(Texture2D texture, Vector2 sprite_texture_dimentions, Vector2 sprite_size, float rotation, float scale, int frameCount, float speed) { SpriteAnimation spriteAnimation = malloc(sizeof(sprite_animation_t)); @@ -37,38 +42,29 @@ void UpdateSpriteAnimation(SpriteAnimation self, float dt) { } void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position) { -#ifdef _DEBUG - DrawCircleV(position, 5, DARKGREEN); -#endif - Rectangle destination = (Rectangle){ - 0, - 0, - spriteAnimation->size.x * spriteAnimation->scale, - spriteAnimation->size.y * spriteAnimation->scale - } ; + position = Vector2Scale(position, .5f); + float yscale = (spriteAnimation->size.y * spriteAnimation->scale) / 2; + float xscale = (spriteAnimation->size.x * spriteAnimation->scale) / 2; - Vector2 origin = (Vector2){ - .x = position.x + destination.width/2.f, - .y = position.y + destination.height/2.f + Rectangle destination = (Rectangle) { + xscale - position.x, + yscale - position.y, + xscale + position.x, + yscale + position.y }; -#ifdef _DEBUG - DrawCircleV(origin, 5, RED); -#endif + DrawTexturePro( spriteAnimation->texture, - (Rectangle){ - spriteAnimation->sourceRect.x, - spriteAnimation->sourceRect.y, - spriteAnimation->sourceRect.width, - spriteAnimation->sourceRect.height - }, + spriteAnimation->sourceRect, destination, - origin, + (Vector2){0,0}, spriteAnimation->rotation, WHITE ); #ifdef _DEBUG + DrawCircleV(position, 5, DARKGREEN); + DrawRectangleLinesEx(destination, 2, BLACK); #endif } diff --git a/src/main.c b/src/main.c index 839eee9..cb0ce90 100644 --- a/src/main.c +++ b/src/main.c @@ -19,11 +19,15 @@ int main(int argc, char** argv) { InitWindow(900, 600, "Colysis"); + SetWindowState(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_MAXIMIZED); + - SetConfigFlags(FLAG_WINDOW_RESIZABLE); Texture2D gery = LoadTexture(ASSETS_PATH "/karl-heinz_head.png"); - SpriteAnimation geryanim = CreateSpriteAnimation(gery, (Vector2){64*14,64}, (Vector2){64,64}, 0.f, 4.f, 5, 0.15f); + 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}; @@ -34,7 +38,7 @@ int main(int argc, char** argv) while (!WindowShouldClose()) { ClearBackground((Color){ 0x00, 0x6d, 0xfb }); float dt = GetFrameTime(); - + camera.offset = (Vector2){GetScreenWidth()/2.f,GetScreenHeight()/2.f}; UpdateSpriteAnimation(geryanim, dt); @@ -45,13 +49,13 @@ int main(int argc, char** argv) BeginMode2D(camera); { DrawSpriteAnimation(geryanim, (Vector2){0,0}); - } EndMode2D(); { - DrawTextFull(GetFontDefault(), "Darling, I'm Home!", (Vector2){20,20}, TEXT_ORIENTATION_RIGHT, 0, 24, 5, 5, RAYWHITE); - + DrawTextFull(GetFontDefault(), "Darling, I'm Home!", + (Vector2){20,20}, TEXT_ORIENTATION_RIGHT, + 0, 24, 5, 5, RAYWHITE); } } @@ -61,5 +65,7 @@ int main(int argc, char** argv) DestroySpriteAnimation(geryanim); UnloadTexture(gery); + CloseWindow(); + return 0; }