commit b99458bcc2e81750dc5242157ed953aeda2d8280
parent 1375e0c5d6bb70b1cd5239af620336cef98473dc
Author: brookjeynes <me@brookjeynes.dev>
Date: Fri, 31 Jul 2026 14:12:45 +1000
fix: enemy despawn when killed
Signed-off-by: brookjeynes <me@brookjeynes.dev>
Diffstat:
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/main.zig b/src/main.zig
@@ -177,14 +177,13 @@ pub fn main() !void {
switch (entity.*) {
.grunt => |*grunt| {
- for (0..grunt.bullet_pool.count) |bullet_idx| {
- const bullet = grunt.bullet_pool.bullets[bullet_idx];
+ var enemy_bullet_idx = grunt.bullet_pool.count;
+ while (enemy_bullet_idx > 0) {
+ enemy_bullet_idx -= 1;
+ const bullet = grunt.bullet_pool.bullets[enemy_bullet_idx];
const is_collision = raylib.CheckCollisionCircleRec(
- .{
- .x = bullet.position.x,
- .y = bullet.position.y,
- },
+ .{ .x = bullet.position.x, .y = bullet.position.y },
Bullet.radius,
.{
.x = player.position.x,
@@ -195,18 +194,19 @@ pub fn main() !void {
);
if (is_collision) {
- grunt.bullet_pool.despawn(bullet_idx);
+ grunt.bullet_pool.despawn(enemy_bullet_idx);
player.health -= Grunt.bullet_damage;
-
- if (player.health < 0) {
+ if (player.health <= 0) {
game_state.screen.current = .title;
}
}
}
- for (0..player.bullet_pool.count) |bullet_idx| {
- const bullet = player.bullet_pool.bullets[bullet_idx];
+ var player_bullet_idx = player.bullet_pool.count;
+ while (player_bullet_idx > 0) {
+ player_bullet_idx -= 1;
+ const bullet = player.bullet_pool.bullets[player_bullet_idx];
const is_collision = raylib.CheckCollisionCircleRec(
.{
.x = bullet.position.x,
@@ -222,10 +222,10 @@ pub fn main() !void {
);
if (is_collision) {
- player.bullet_pool.despawn(bullet_idx);
+ player.bullet_pool.despawn(player_bullet_idx);
game_state.despawn_enemy(enemy_idx);
- continue;
+ break;
}
}
},