This commit is contained in:
2026-08-03 21:11:00 +03:00
parent 8f596735e1
commit 06e41fc7da
33 changed files with 2180 additions and 356 deletions
+85
View File
@@ -0,0 +1,85 @@
package main
import hm "core:container/handle_map"
import rl "vendor:raylib"
Player :: struct {
using actor: Actor,
attack_range: f32,
attack_dmg: i32,
attack_cd: f32,
attack_timer: f32,
invuln_timer: f32,
}
PlayerInput :: struct {
move: rl.Vector2,
attack: bool,
}
make_player :: proc() -> Entity {
return Entity {
v = Player {
actor = Actor {
base = BaseEntity {
pos = {0, 0},
col_size = 16,
gfx = {0 = GfxCircle{pos = {}, radius = 14, color = {80, 220, 100, 255}}},
},
hp = 100,
max_hp = 100,
speed = 220,
},
attack_range = 75,
attack_dmg = 35,
attack_cd = 0.3,
},
}
}
sys_input :: proc(state: ^GameState, dt: f32) {
input: PlayerInput
if rl.IsKeyDown(.W) || rl.IsKeyDown(.UP) do input.move += {-1, -1}
if rl.IsKeyDown(.S) || rl.IsKeyDown(.DOWN) do input.move += {1, 1}
if rl.IsKeyDown(.A) || rl.IsKeyDown(.LEFT) do input.move += {-1, 1}
if rl.IsKeyDown(.D) || rl.IsKeyDown(.RIGHT) do input.move += {1, -1}
input.attack = rl.IsKeyPressed(.SPACE)
player_input(state, input, dt)
}
player_input :: proc(state: ^GameState, input: PlayerInput, dt: f32) {
_, p := get_player(state)
if p == nil do return
p.vel = rl.Vector2Normalize(input.move) * p.speed
if p.attack_timer > 0 do p.attack_timer -= dt
if input.attack && p.attack_timer <= 0 {
p.attack_timer = p.attack_cd
init_attack(
state,
Attack {
base = BaseEntity {
gfx = {
0 = GfxRing {
inner_radius = p.attack_range * 0.7,
outer_radius = p.attack_range,
color = {255, 255, 255, 40},
},
},
},
parent = state.player,
dmg = p.attack_dmg,
radius = p.attack_range,
lifetime = p.attack_cd,
},
)
}
}
player_update :: proc(state: ^GameState, p: ^Player, h: Handle, dt: f32) {
if p.invuln_timer > 0 do p.invuln_timer -= dt
}