70 lines
1.6 KiB
Odin
70 lines
1.6 KiB
Odin
package main
|
|
|
|
import "core:fmt"
|
|
import "core:math"
|
|
import "core:math/rand"
|
|
import ecs "shoal/src"
|
|
import rl "vendor:raylib"
|
|
|
|
can_move_signal := ecs.Signal {
|
|
callbacks = {reset_grid_actor_can_move},
|
|
}
|
|
|
|
move :: proc(t: ^GridActorComponent, x, y: f32) {
|
|
next_position := GridActorComponent {
|
|
position = {t.position.x + x, t.position.y + y},
|
|
}
|
|
|
|
for i, v in ecs.slice(&GridActor) {
|
|
if v.position != next_position.position {
|
|
t.position = next_position.position
|
|
}
|
|
}
|
|
}
|
|
|
|
reset_grid_actor_can_move :: proc(args: ..any) {
|
|
t.can_move = true
|
|
}
|
|
|
|
update_grid_actor :: proc() {
|
|
for e, grid_actor in ecs.slice(&GridActor) {
|
|
transform := ecs.get_component(e, &ecs.Transform)
|
|
transform.translation = grid_actor.position * CELL_SIZE
|
|
}
|
|
|
|
}
|
|
|
|
shoot :: proc(t: ecs.TransformComponent, weapon: ^WeaponComponent, pos: rl.Vector2) {
|
|
pos_centered := center_to_grid(pos)
|
|
t_centered := center_to_grid(t.translation)
|
|
spray: rl.Vector2 = {
|
|
pos.x + rand.float32_range(0, CELL_SIZE),
|
|
pos.y + rand.float32_range(0, CELL_SIZE),
|
|
}
|
|
line_particle := LineParticle {
|
|
pos1 = t.translation * CELL_SIZE + 10,
|
|
pos2 = spray,
|
|
tint = rl.WHITE,
|
|
lifetime = 0.2,
|
|
}
|
|
|
|
if weapon.cooldown == true {return}
|
|
weapon.cooldown = true
|
|
start_timer(60 / weapon.rpm, reset_weapon_cooldown)
|
|
spawn_particle(line_particle)
|
|
}
|
|
|
|
reset_weapon_cooldown :: proc() {
|
|
for i, v in ecs.slice(&Player) {
|
|
weapon := ecs.get_component(i, &Weapon)
|
|
weapon.cooldown = false
|
|
}
|
|
}
|
|
|
|
center_to_grid :: proc(pos: rl.Vector2) -> rl.Vector2 {
|
|
pos_x, pos_y: f32
|
|
pos_x = pos.x + CELL_SIZE / 2
|
|
pos_y = pos.y + CELL_SIZE / 2
|
|
return rl.Vector2{pos_x, pos_y}
|
|
}
|