Setting Window flags right; adding animation

This commit is contained in:
noffie 2025-03-16 15:24:31 +01:00
parent c0e3af64d6
commit 4536c62dad
2 changed files with 30 additions and 28 deletions

View file

@ -4,6 +4,11 @@
#include "raylib.h"
#include "raymath.h"
#ifdef _DEBUG
#include <stdio.h>
#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
position = Vector2Scale(position, .5f);
float yscale = (spriteAnimation->size.y * spriteAnimation->scale) / 2;
float xscale = (spriteAnimation->size.x * spriteAnimation->scale) / 2;
Rectangle destination = (Rectangle) {
0,
0,
spriteAnimation->size.x * spriteAnimation->scale,
spriteAnimation->size.y * spriteAnimation->scale
xscale - position.x,
yscale - position.y,
xscale + position.x,
yscale + position.y
};
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){
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
}

View file

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