This is the part where the game actually starts doing things. Wraps up arena generation, then jumps into shooting, movement, input, the bot’s brain, powerups, and bullets.
begin_level and start_match are just glue, reset the tanks, build the level, flip the state to playing. start_match additionally zeroes out score and level since that only happens when a whole new match starts, not every round.
fire_from is where powerups actually change what comes out of the barrel. Big shells make the bullet bigger and slower but harder hitting. Lock-On just flags the bullet as homing. Twin Cannons is the odd one out since it fires two bullets at a slight angle instead of changing one bullet’s stats. Bullets spawn a little in front of the tank’s nose too, otherwise they’d spawn inside their own tank and immediately register a hit on the guy who just fired.
try_move_tank is the one function basically everything routes through, player and bot both. Clamp the position, check it against every obstacle, only actually move if nothing’s blocking, unless you’ve got the Dozer Blade and you’re hitting a crate specifically, then the crate just dies instead.
handle_player_input is the “instant facing” control scheme. Read whichever movement keys are held, build a direction, normalize it so diagonals aren’t faster than straight lines, then just snap the tank’s angle straight to that direction. No gradual turning for humans, you press a direction and you’re already facing it.
update_bot is the biggest one here and honestly the most fun to write. Every frame it loads its difficulty stats, decides whether to chase the player or detour for a nearby powerup, figures out how far off its aim is, probes a little bit ahead of itself to avoid walking into walls, turns gradually toward its goal since bots don’t get the instant snap the player gets, picks a speed based on distance to target, and only actually shoots if its aim is tight enough and the target’s in range.
maybe_spawn_powerup and check_powerup_pickup are pretty simple, try random spots until one doesn’t overlap anything or spawn too close to a tank, and check distance for pickup.
update_bullets is the long one. Homing bullets get nudged toward their target a little each frame instead of snapping straight at it, so they’re curveable and dodgeable, not laser guided. Then every bullet gets checked against the arena bounds, every obstacle, and both tanks, in that order, and whichever one it hits first is what actually happens to it.
update_particles is just the tiny cosmetic bit, dots that drift, slow down over time, and fade out. Purely for hit sparks and crate destruction, doesn’t affect gameplay at all.