← All posts

Pew pew, in eight directions

Aiming, weapons as data, bolts that never skip through walls and a script that finds the tip of the blaster in every frame.

Listen to this post

Read in Dodz's voice, cloned with AI

0:00 / 0:00
Pew firing the Blaster in the grey test room, next to a floating weapon capsule.

The game is called PewRun. The "pew" had to feel good.

Eight directions, and a few rules

Pew aims in eight directions. Which pose he uses depends on where he is:

  • On the ground, up + side or down + side makes him stop and aim diagonally. There's no "run while aiming diagonally" animation, and standing still reads better anyway.
  • Down alone on the ground is a crouch, still shooting forward.
  • Straight down only works in the air.
  • Ctrl (or the right mouse button) holds Pew in place, so you can aim without walking.

Try it here. Point inside the box to aim, click to shoot:

aim_forward
Point at the box to aim, click to shoot. Straight down only works in the air.

Weapons are files

Each weapon is a small resource file, a WeaponData: how often it fires, how fast the bolts go, how long they live, damage, how many bolts per shot, the spread, the color, the sound and the color of its capsule. A new weapon is a new file, not new code.

BlasterSpreader
Fire interval0.13 s0.24 s
Bolt speed1900 px/s1600 px/s
Bolt life0.9 s0.42 s
Bolts per shot15
Spread0°40°

Holding the button fires at the weapon's rate. The Blaster is the starting weapon with endless ammo; the Spreader trades reach for a fan of five shots.

Finding the barrel

Bolts should leave from the tip of the blaster, and the blaster is in a different place in every pose and every frame. Placing those points by hand for every frame sounded miserable.

So the sprite build script finds them. In each shooting frame, it looks for the blaster's glowing orange pixels and picks the one farthest along the aim direction. That's the muzzle. The positions go into a JSON next to the atlas, and the game reads them when firing. This website reads the same file: it's how the bolts in the demo above line up with the gun.

Bolts that don't cheat

A fast bolt can move further in one frame than a thin wall is wide, and skip right through it. So each bolt casts a ray from where it was to where it's going every frame, and stops at the first thing it hits. Whatever it hits gets a take_damage call with the amount, the hit position and the direction.

The shooting demo in the test room: aiming, bursts, a capsule pickup and targets breaking.

Things to shoot

Two props came out of this step: a soda can and a matchbox. When hit, they flash and shake; when their health runs out, they burst into debris and come back a few seconds later. They're also solid, so Pew can climb on them. And there's a floating weapon capsule that gives Pew a weapon when he touches it.

Each shot has a muzzle flash, a little recoil on the sprite, and a sound generated with ElevenLabs, played with a small random pitch change so a burst doesn't sound like a machine gun of copies.

Next: the first real stretch of Chapter 1, where all of this meets rain, lights and water. The gutter is wet.