aboutsummaryrefslogtreecommitdiff
path: root/src/bullet.odin
diff options
context:
space:
mode:
authoriamcheeseman <[hidden email]>2026-01-15 12:13:41 -0500
committeriamcheeseman <[hidden email]>2026-01-15 12:13:41 -0500
commit1ebeadbad7f7ee757096320d9c5daf3b55373f6a (patch)
treeffa9ce9d9df6f93970c488441f0a74c8bfcc9022 /src/bullet.odin
parentd6f276be6bc1214c88cfc5346ceb7a5bea610638 (diff)
Bullets! And buncha physics fixes! And more!
Diffstat (limited to 'src/bullet.odin')
-rw-r--r--src/bullet.odin47
1 files changed, 20 insertions, 27 deletions
diff --git a/src/bullet.odin b/src/bullet.odin
index b26cc14..eb8190b 100644
--- a/src/bullet.odin
+++ b/src/bullet.odin
@@ -7,7 +7,7 @@ import "phys"
Bullet :: struct {
handle: Entity_Handle,
- body_handle: phys.Body_Handle,
+ body: phys.Body_Handle,
sprite: Sprite,
lifetime: f32,
}
@@ -34,58 +34,51 @@ make_bullet :: proc(
start = {-3, -3},
size = {6, 6},
}
- body_handle, body := phys.make_body(body_rect, layers, mask)
+ body := phys.make_body(body_rect, layers, mask)
- body.vel = vel
-
- phys.set_body_position(body_handle, pos)
+ phys.set_velocity(body, vel)
+ phys.set_position(body, pos)
return make_entity(&state.bullet_list, Bullet{
- body_handle = body_handle,
+ body = body,
sprite = sprite,
lifetime = lifetime,
})
}
-delete_bullet :: proc(bullet_handle: Entity_Handle) {
- bullet := get_entity(state.bullet_list, bullet_handle)
-
- phys.remove_body(bullet.body_handle)
- delete_entity(&state.platform_list, bullet.handle)
+delete_bullet :: proc(h: Entity_Handle) {
+ b := get_entity(state.bullet_list, h)
+ phys.remove_body(b.body)
+ delete_entity(&state.bullet_list, h)
}
update_bullets :: proc(dt: f32) {
iter := iter_entity_list(state.bullet_list)
- for bullet in entity_list_iter(&iter) {
- bullet.lifetime -= dt
+ for b in entity_list_iter(&iter) {
+ b.lifetime -= dt
- phys.update_body(bullet.body_handle)
- body := phys.get_body(bullet.body_handle)
+ phys.update_body(b.body)
- if body.collisions != {} || bullet.lifetime < 0 {
- delete_entity(&state.bullet_list, bullet.handle)
+ if phys.get_collisions(b.body) != {} || b.lifetime < 0 {
+ delete_bullet(b.handle)
+ continue
}
- bullet.sprite.pos = body.pos
+ b.sprite.pos = phys.get_position(b.body)
}
}
draw_bullets :: proc() {
iter := iter_entity_list(state.bullet_list)
- for bullet in entity_list_iter(&iter) {
- draw_sprite(bullet.sprite)
-
- body := phys.get_body(bullet.body_handle)
- rect := body.rect
- rect.start += body.pos
- draw_rect(transmute(Rect)rect)
+ for b in entity_list_iter(&iter) {
+ draw_sprite(b.sprite)
}
}
clear_bullets :: proc() {
iter := iter_entity_list(state.bullet_list)
- for bullet in entity_list_iter(&iter) {
- delete_bullet(bullet.handle)
+ for b in entity_list_iter(&iter) {
+ delete_bullet(b.handle)
}
}