3d
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package main
|
||||
|
||||
import hm "core:container/handle_map"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
MAX_ATTACK_HITS :: 32
|
||||
|
||||
Attack :: struct {
|
||||
using base: BaseEntity,
|
||||
parent: Handle,
|
||||
dmg: i32,
|
||||
radius: f32,
|
||||
lifetime: f32,
|
||||
hit: [MAX_ATTACK_HITS]Handle,
|
||||
hit_count: u8,
|
||||
}
|
||||
|
||||
init_attack :: proc(state: ^GameState, a: Attack) -> Handle {
|
||||
return spawn(state, Entity{v = a})
|
||||
}
|
||||
|
||||
attack_update :: proc(state: ^GameState, a: ^Attack, h: Handle, dt: f32) {
|
||||
if a.parent != {} {
|
||||
if pe := get_entity(state, a.parent); pe != nil {
|
||||
a.pos = get_base(pe).pos
|
||||
} else {
|
||||
a.marked = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
it := hm.iterator_make(&state.entities)
|
||||
for e, eh in hm.iterate(&it) {
|
||||
#partial switch &v in e.v {
|
||||
case Enemy:
|
||||
if v.hp <= 0 || v.marked do continue
|
||||
if rl.Vector2Distance(a.pos, v.pos) <= a.radius && !attack_has_hit(a, eh) {
|
||||
v.hp -= a.dmg
|
||||
attack_add_hit(a, eh)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if a.lifetime > 0 {
|
||||
a.lifetime -= dt
|
||||
} else {
|
||||
a.marked = true
|
||||
}
|
||||
}
|
||||
|
||||
attack_has_hit :: proc(a: ^Attack, h: Handle) -> bool {
|
||||
for i in 0 ..< a.hit_count {
|
||||
if a.hit[i] == h do return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
attack_add_hit :: proc(a: ^Attack, h: Handle) {
|
||||
if a.hit_count >= MAX_ATTACK_HITS do return
|
||||
a.hit[a.hit_count] = h
|
||||
a.hit_count += 1
|
||||
}
|
||||
Reference in New Issue
Block a user