47 lines
956 B
Odin
47 lines
956 B
Odin
|
package main
|
||
|
|
||
|
import rl "vendor:raylib"
|
||
|
import "core:slice"
|
||
|
import "core:math/ease"
|
||
|
|
||
|
Explosion :: struct{
|
||
|
position: Vec2,
|
||
|
radius: f32,
|
||
|
max_radius: f32,
|
||
|
time: f32,
|
||
|
duration: f32,
|
||
|
to_free: bool,
|
||
|
}
|
||
|
|
||
|
explosions_buf : [256]Explosion
|
||
|
explosions : [dynamic]Explosion
|
||
|
|
||
|
explosions_init :: proc() {
|
||
|
explosions = slice.into_dynamic(explosions_buf[:])
|
||
|
}
|
||
|
|
||
|
explode :: proc(position: Vec2, max_radius: f32, duration: f32) {
|
||
|
append(&explosions, Explosion {
|
||
|
position = position,
|
||
|
max_radius = max_radius,
|
||
|
duration = duration
|
||
|
})
|
||
|
}
|
||
|
|
||
|
explosions_process :: proc(delta: f32) {
|
||
|
#reverse for &e, i in explosions {
|
||
|
e.time += delta
|
||
|
e.radius = ease.back_out(e.time / e.duration) * e.max_radius
|
||
|
if e.time > e.duration {
|
||
|
unordered_remove(&explosions, i)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
explosions_draw :: proc() {
|
||
|
#reverse for &e, i in explosions {
|
||
|
color := rl.ColorAlpha(rl.YELLOW, 1 - ease.exponential_in(e.time / e.duration))
|
||
|
rl.DrawCircleV(e.position, e.radius, color)
|
||
|
}
|
||
|
}
|