package main import "core:fmt" import rl "vendor:raylib" Graphics :: union { GfxNone, GfxCircle, GfxRect, GfxRing, GfxCircleLines, GfxAnimatedSprite, GfxTexture, } GfxNone :: struct {} GfxCircle :: struct { pos: rl.Vector2, radius: f32, color: rl.Color, } GfxRect :: struct { pos: rl.Vector2, size: rl.Vector2, color: rl.Color, } GfxRing :: struct { pos: rl.Vector2, inner_radius: f32, outer_radius: f32, color: rl.Color, } GfxCircleLines :: struct { pos: rl.Vector2, radius: f32, color: rl.Color, } GfxTexture :: struct {} GfxAnimatedSprite :: struct { pos: rl.Vector2, rect: rl.Rectangle, tex: ^rl.Texture2D, frame: u32, speed: f32, current_time: f32, } PlayerTexFiles :: enum { IDLE, RUN, RUN_ATTACK, WALK, WALK_ATTACK, ATTACK, } GraphicsAssetStore :: struct { playerTex: map[PlayerTexFiles]rl.Texture2D, } gfx_get :: proc(g: ^GraphicsAssetStore, f: PlayerTexFiles) -> ^rl.Texture2D { return &g.playerTex[f] } gfx_init :: proc() -> GraphicsAssetStore { st := GraphicsAssetStore{} st.playerTex = make(map[PlayerTexFiles]rl.Texture2D) st.playerTex[.IDLE] = rl.LoadTexture("assets/3rdparty/player_idle.png") return st } gfx_free :: proc(g: GraphicsAssetStore) { for _, tex in g.playerTex { rl.UnloadTexture(tex) } delete(g.playerTex) } gfx_draw :: proc(pos: rl.Vector2, g: ^Graphics) { #partial switch &v in g { case GfxCircle: rl.DrawCircleV(pos + v.pos, v.radius, v.color) case GfxRect: rl.DrawRectangleV(pos - v.size / 2 + v.pos, v.size, v.color) case GfxRing: rl.DrawRing(pos + v.pos, v.inner_radius, v.outer_radius, 0, 360, 0, v.color) case GfxCircleLines: rl.DrawCircleLinesV(pos + v.pos, v.radius, v.color) case GfxAnimatedSprite: fmt.println(pos.x, pos.y) //TODO: Count from L to R row-wize v.rect.x = v.rect.width * f32(v.frame) v.rect.y = v.rect.height * f32(v.frame) rl.DrawTexturePro( v.tex^, v.rect, rl.Rectangle { pos.x - v.rect.width * 3 / 2, pos.y - v.rect.height * 3 / 2, v.rect.width * 3, v.rect.height * 3, }, rl.Vector2{0, 0}, 0, rl.WHITE, ) v.current_time += rl.GetFrameTime() if v.current_time > v.speed { v.current_time = v.current_time - v.speed v.frame += 1 } // rl.DrawTextureRec(v.tex, v.rect, rl.Vector2{pos.x, pos.y}, rl.Color{}) } }