Anim init
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
@@ -1,5 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "core:fmt"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
Graphics :: union {
|
Graphics :: union {
|
||||||
@@ -8,6 +9,7 @@ Graphics :: union {
|
|||||||
GfxRect,
|
GfxRect,
|
||||||
GfxRing,
|
GfxRing,
|
||||||
GfxCircleLines,
|
GfxCircleLines,
|
||||||
|
GfxAnimatedSprite,
|
||||||
GfxTexture,
|
GfxTexture,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,11 +40,53 @@ GfxCircleLines :: struct {
|
|||||||
color: rl.Color,
|
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) {
|
PlayerTexFiles :: enum {
|
||||||
#partial switch v in g {
|
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:
|
case GfxCircle:
|
||||||
rl.DrawCircleV(pos + v.pos, v.radius, v.color)
|
rl.DrawCircleV(pos + v.pos, v.radius, v.color)
|
||||||
case GfxRect:
|
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)
|
rl.DrawRing(pos + v.pos, v.inner_radius, v.outer_radius, 0, 360, 0, v.color)
|
||||||
case GfxCircleLines:
|
case GfxCircleLines:
|
||||||
rl.DrawCircleLinesV(pos + v.pos, v.radius, v.color)
|
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{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,14 @@ main :: proc() {
|
|||||||
rl.SetTargetFPS(TARGET_FPS)
|
rl.SetTargetFPS(TARGET_FPS)
|
||||||
defer rl.CloseWindow()
|
defer rl.CloseWindow()
|
||||||
|
|
||||||
camera := rl.Camera3D{
|
gfx := gfx_init()
|
||||||
|
defer gfx_free(gfx)
|
||||||
|
|
||||||
|
camera := rl.Camera3D {
|
||||||
position = {0, 80, 80},
|
position = {0, 80, 80},
|
||||||
target = {0, 0, 0},
|
target = {0, 0, 0},
|
||||||
up = {0, 1, 0},
|
up = {0, 1, 0},
|
||||||
fovy = 900,
|
fovy = 400,
|
||||||
projection = .ORTHOGRAPHIC,
|
projection = .ORTHOGRAPHIC,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,16 +27,16 @@ main :: proc() {
|
|||||||
state.collisions = make([dynamic]CollisionPair)
|
state.collisions = make([dynamic]CollisionPair)
|
||||||
defer delete(state.collisions)
|
defer delete(state.collisions)
|
||||||
|
|
||||||
state.player = spawn(state, make_player())
|
state.player = spawn(state, make_player(&gfx))
|
||||||
|
|
||||||
spawn(state, make_enemy({400, 300}, .Brute))
|
// spawn(state, make_enemy({400, 300}, .Brute))
|
||||||
spawn(state, make_enemy({-400, 200}, .Scout))
|
// spawn(state, make_enemy({-400, 200}, .Scout))
|
||||||
spawn(state, make_enemy({300, -350}, .Grunt))
|
// spawn(state, make_enemy({300, -350}, .Grunt))
|
||||||
spawn(state, make_enemy({-300, -300}, .Scout))
|
// spawn(state, make_enemy({-300, -300}, .Scout))
|
||||||
spawn(state, make_enemy({100, 400}, .Grunt))
|
// spawn(state, make_enemy({100, 400}, .Grunt))
|
||||||
spawn(state, make_enemy({-150, 350}, .Grunt))
|
// spawn(state, make_enemy({-150, 350}, .Grunt))
|
||||||
spawn(state, make_enemy({450, -150}, .Brute))
|
// spawn(state, make_enemy({450, -150}, .Brute))
|
||||||
spawn(state, make_enemy({-450, 100}, .Scout))
|
// spawn(state, make_enemy({-450, 100}, .Scout))
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
dt := rl.GetFrameTime()
|
dt := rl.GetFrameTime()
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ Player :: struct {
|
|||||||
dash_timer: f32,
|
dash_timer: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
make_player :: proc() -> Entity {
|
make_player :: proc(gfx: ^GraphicsAssetStore) -> Entity {
|
||||||
p := Player {
|
p := Player {
|
||||||
level = 1,
|
level = 1,
|
||||||
xp = 0,
|
xp = 0,
|
||||||
@@ -62,7 +62,16 @@ make_player :: proc() -> Entity {
|
|||||||
}
|
}
|
||||||
p.base.pos = {0, 0}
|
p.base.pos = {0, 0}
|
||||||
p.base.col_size = 16
|
p.base.col_size = 16
|
||||||
p.base.gfx = {0 = GfxCircle{pos = {}, radius = 14, color = {80, 220, 100, 255}}}
|
p.base.gfx = {
|
||||||
|
0 = GfxCircle{pos = {}, radius = 14, color = {80, 220, 100, 255}},
|
||||||
|
1 = GfxAnimatedSprite {
|
||||||
|
pos = {},
|
||||||
|
rect = {0, 0, 64, 64},
|
||||||
|
tex = gfx_get(gfx, .IDLE),
|
||||||
|
frame = 0,
|
||||||
|
speed = 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
p.hp = p.base_max_hp
|
p.hp = p.base_max_hp
|
||||||
p.max_hp = p.base_max_hp
|
p.max_hp = p.base_max_hp
|
||||||
p.speed = 220
|
p.speed = 220
|
||||||
@@ -195,7 +204,9 @@ sys_input :: proc(state: ^GameState, dt: f32) {
|
|||||||
if p.attack_timer > 0 do p.attack_timer -= dt
|
if p.attack_timer > 0 do p.attack_timer -= dt
|
||||||
if rl.IsMouseButtonPressed(.LEFT) && p.attack_timer <= 0 {
|
if rl.IsMouseButtonPressed(.LEFT) && p.attack_timer <= 0 {
|
||||||
p.attack_timer = player_atk_cd(p)
|
p.attack_timer = player_atk_cd(p)
|
||||||
init_attack(state, Attack{
|
init_attack(
|
||||||
|
state,
|
||||||
|
Attack {
|
||||||
parent = state.player,
|
parent = state.player,
|
||||||
dir = p.aim,
|
dir = p.aim,
|
||||||
dmg = player_total_dmg(p),
|
dmg = player_total_dmg(p),
|
||||||
@@ -204,7 +215,8 @@ sys_input :: proc(state: ^GameState, dt: f32) {
|
|||||||
arc = 1.3,
|
arc = 1.3,
|
||||||
lifetime = player_atk_cd(p),
|
lifetime = player_atk_cd(p),
|
||||||
color = {255, 255, 255, 60},
|
color = {255, 255, 255, 60},
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// навыки
|
// навыки
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import hm "core:container/handle_map"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import math "core:math"
|
import math "core:math"
|
||||||
import hm "core:container/handle_map"
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
SQRT2_INV :: 0.7071067811865476
|
SQRT2_INV :: 0.7071067811865476
|
||||||
@@ -120,11 +120,15 @@ entity_draw :: proc(state: ^GameState, e: ^Entity) {
|
|||||||
sp := rl.GetWorldToScreen({b.pos.x, 0, b.pos.y}, state.camera)
|
sp := rl.GetWorldToScreen({b.pos.x, 0, b.pos.y}, state.camera)
|
||||||
scale := SCREEN_H / state.camera.fovy
|
scale := SCREEN_H / state.camera.fovy
|
||||||
|
|
||||||
#partial switch v in b.gfx[0] {
|
for &g, _ in b.gfx {
|
||||||
case GfxCircle:
|
gfx_draw(sp, &g)
|
||||||
rl.DrawCircleV(sp, v.radius * scale, v.color)
|
|
||||||
case:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #partial switch v in b.gfx[0] {
|
||||||
|
// case GfxCircle:
|
||||||
|
// rl.DrawCircleV(sp, v.radius * scale, v.color)
|
||||||
|
// case:
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
ground_effect_draw :: proc(state: ^GameState, e: ^Entity) {
|
ground_effect_draw :: proc(state: ^GameState, e: ^Entity) {
|
||||||
@@ -149,12 +153,7 @@ draw_arc_sector :: proc(pos: rl.Vector2, dir: rl.Vector2, radius: f32, arc: f32,
|
|||||||
a2 := start + arc * f32(i + 1) / f32(SEGMENTS)
|
a2 := start + arc * f32(i + 1) / f32(SEGMENTS)
|
||||||
p1 := pos + rl.Vector2{math.cos_f32(a1), math.sin_f32(a1)} * radius
|
p1 := pos + rl.Vector2{math.cos_f32(a1), math.sin_f32(a1)} * radius
|
||||||
p2 := pos + rl.Vector2{math.cos_f32(a2), math.sin_f32(a2)} * radius
|
p2 := pos + rl.Vector2{math.cos_f32(a2), math.sin_f32(a2)} * radius
|
||||||
rl.DrawTriangle3D(
|
rl.DrawTriangle3D({pos.x, 0.03, pos.y}, {p1.x, 0.03, p1.y}, {p2.x, 0.03, p2.y}, color)
|
||||||
{pos.x, 0.03, pos.y},
|
|
||||||
{p1.x, 0.03, p1.y},
|
|
||||||
{p2.x, 0.03, p2.y},
|
|
||||||
color,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||