Anim init
This commit is contained in:
+72
-3
@@ -1,5 +1,6 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
Graphics :: union {
|
||||
@@ -8,6 +9,7 @@ Graphics :: union {
|
||||
GfxRect,
|
||||
GfxRing,
|
||||
GfxCircleLines,
|
||||
GfxAnimatedSprite,
|
||||
GfxTexture,
|
||||
}
|
||||
|
||||
@@ -38,11 +40,53 @@ GfxCircleLines :: struct {
|
||||
color: rl.Color,
|
||||
}
|
||||
|
||||
GfxTexture :: struct {
|
||||
GfxTexture :: struct {}
|
||||
|
||||
GfxAnimatedSprite :: struct {
|
||||
pos: rl.Vector2,
|
||||
rect: rl.Rectangle,
|
||||
tex: ^rl.Texture2D,
|
||||
frame: u32,
|
||||
speed: f32,
|
||||
current_time: f32,
|
||||
}
|
||||
|
||||
gfx_draw :: proc(pos: rl.Vector2, g: Graphics) {
|
||||
#partial switch v in g {
|
||||
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:
|
||||
@@ -51,5 +95,30 @@ gfx_draw :: proc(pos: rl.Vector2, g: Graphics) {
|
||||
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{})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user