40 lines
957 B
Odin
40 lines
957 B
Odin
package main
|
|
|
|
import "core:fmt"
|
|
import rl "vendor:raylib"
|
|
|
|
move :: proc(t: ^Transform, x, y: f32) {
|
|
next_position := Transform {
|
|
position = {t.position.x + x, t.position.y + y},
|
|
}
|
|
if e, occupied := world.entities[next_position.position]; !occupied {
|
|
delete_key(&world.entities, t.position)
|
|
defer world.entities[t.position] = e
|
|
t.position = next_position.position
|
|
}
|
|
}
|
|
|
|
shoot :: proc(t: Transform, pos: rl.Vector2) {
|
|
pos_centered := center_to_grid(pos)
|
|
t_centered := center_to_grid(t.position)
|
|
line_particle := LineParticle {
|
|
pos1 = t.position * CELL_SIZE + 10,
|
|
pos2 = pos + 10,
|
|
tint = rl.WHITE,
|
|
lifetime = 0.2,
|
|
}
|
|
spawn_particle(line_particle)
|
|
start_timer(1, test_timer_callback)
|
|
}
|
|
|
|
test_timer_callback :: proc() {
|
|
fmt.println("timer finished")
|
|
}
|
|
|
|
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}
|
|
}
|