Skip to content
Game 14 Unit 9 of 32 1 hr learning time

Explosion Animation

Two-frame explosions — starburst to fragments with timed UDG replacement.

28% of Blockstorm

A single frame of explosion is better than nothing, but it disappears too fast to feel satisfying. This unit adds a two-frame explosion animation: first the starburst (UDG F) in red, then the fragments (UDG K) in yellow, then the cell clears. The effect lasts long enough for the player to register the hit without slowing the game down.

The Program

5 REM === EXPLOSION ANIMATION ===
10 BORDER 0: PAPER 0: INK 7: CLS
15 GO SUB 800
20 LET sc = 0: LET hi = 0: LET li = 3
22 LET wv = 1
30 LET px = 15: LET py = 20
32 LET ba = 0: LET bx = 0: LET by = 0
34 LET ex = 15: LET ey = 5: LET ea = 1
40 GO SUB 600
50 PRINT AT py, px; INK 7; CHR$ 152
55 IF ea = 1 THEN PRINT AT ey, ex; INK 4; CHR$ 144
60 REM === game loop ===
70 LET k$ = INKEY$
80 IF k$ = "o" OR k$ = "O" THEN IF px > 1 THEN PRINT AT py, px; " ": LET px = px - 1: PRINT AT py, px; INK 7; CHR$ 152
90 IF k$ = "p" OR k$ = "P" THEN IF px < 30 THEN PRINT AT py, px; " ": LET px = px + 1: PRINT AT py, px; INK 7; CHR$ 152
100 IF k$ = " " THEN IF ba = 0 THEN LET bx = px: LET by = py - 1: LET ba = 1: PRINT AT by, bx; INK 7; CHR$ 148
110 IF ba = 0 THEN GO TO 60
120 PRINT AT by, bx; " "
130 LET by = by - 1
140 IF by < 1 THEN LET ba = 0: GO TO 60
150 REM check hit
160 IF ea = 1 AND bx = ex AND by = ey THEN GO TO 200
170 PRINT AT by, bx; INK 7; CHR$ 148
180 GO TO 60
200 REM === two-frame explosion ===
210 LET ea = 0: LET ba = 0
220 PRINT AT ey, ex; INK 2; CHR$ 149
230 BEEP 0.02, -5
240 PAUSE 8
250 PRINT AT ey, ex; INK 6; CHR$ 154
260 BEEP 0.02, -10
270 PAUSE 8
280 PRINT AT ey, ex; " "
290 LET sc = sc + 10
295 GO SUB 600
300 GO TO 60
600 REM === draw HUD ===
605 PRINT AT 0, 0; INK 7; BRIGHT 1; "SC:"; sc; "  HI:"; hi; "  LV:"; li; " W"; wv; "  "
610 RETURN
800 REM === define UDGs ===
805 FOR i = 0 TO 13
810 FOR j = 0 TO 7
815 READ a
820 POKE USR CHR$ (65 + i) + j, a
825 NEXT j
830 NEXT i
835 RETURN
840 REM UDG A: drone
842 DATA 36, 126, 219, 255, 255, 102, 66, 0
844 REM UDG B: scout
846 DATA 24, 60, 126, 255, 219, 24, 36, 0
848 REM UDG C: tank
850 DATA 126, 255, 255, 255, 255, 255, 126, 0
852 REM UDG D: bomber
854 DATA 66, 231, 255, 126, 60, 90, 36, 0
856 REM UDG E: bullet
858 DATA 16, 56, 16, 16, 0, 0, 0, 0
860 REM UDG F: explosion
862 DATA 36, 153, 66, 129, 66, 153, 36, 0
864 REM UDG G: double shot
866 DATA 84, 170, 84, 170, 84, 170, 84, 0
868 REM UDG H: shield
870 DATA 60, 126, 255, 255, 255, 126, 60, 0
872 REM UDG I: player ship
874 DATA 16, 56, 56, 124, 254, 254, 130, 0
876 REM UDG J: enemy bomb
878 DATA 16, 16, 56, 16, 0, 0, 0, 0
880 REM UDG K: explosion 2
882 DATA 129, 66, 36, 0, 36, 66, 129, 0
884 REM UDG L: shield icon
886 DATA 60, 126, 126, 126, 60, 24, 0, 0
888 REM UDG M: drone frame 2
890 DATA 66, 102, 255, 255, 219, 126, 36, 0
892 REM UDG N: scout frame 2
894 DATA 36, 24, 219, 255, 126, 60, 24, 0

How It Works

The explosion sequence runs when a drone is hit:

  1. Print UDG F (CHR$ 149) in red (INK 2) at the hit position — the starburst shape.
  2. Play a short descending BEEP.
  3. PAUSE 2 — hold the frame briefly.
  4. Print UDG K (CHR$ 154) in yellow (INK 6) at the same position — the expanding fragments.
  5. PAUSE 2 — hold again.
  6. Print a space to clear the cell.

Two UDGs, two colours, two pauses. The whole sequence takes a fraction of a second but it is enough to give explosions weight and presence.

Animation with UDG Swapping

This is the simplest form of animation: replace one character with another at the same position. No pixel movement, no smooth transitions — just a swap. Frame 1 is a starburst. Frame 2 is scattered fragments. The shapes are different enough that the player perceives motion even though both are static 8x8 images.

The same technique works for any animation in a character-based game. A walking character alternates between two leg positions. A flickering flame swaps between two fire shapes. A blinking cursor alternates between visible and invisible. Two frames are enough to create the illusion of life.

PAUSE and Timing

PAUSE 2 waits for approximately 2/50 of a second (0.04 seconds on a PAL Spectrum). That is barely perceptible, but enough to ensure each explosion frame is visible for at least one screen refresh. Longer pauses would make explosions more dramatic but would freeze the game loop — no input, no movement, no other processing during a PAUSE. Keep explosion pauses short.

Two UDGs for One Effect

UDG F and UDG K are both explosion graphics, used together for one visual effect. This is a common UDG allocation pattern — dedicating multiple characters to a single animation. With 21 UDGs available and 14 used in Blockstorm, there is room for these pairs. Games with more animations would need to reuse UDGs or swap their definitions at runtime.

Try This

Three frames. Add a third explosion frame between F and K. Design a UDG that is visually between the starburst and the fragments. Does the extra frame improve the animation or just slow it down?

Colour sweep. Instead of red then yellow, try white then red then yellow — three colours cycling through the same UDG. PAUSE 1 between each. The colour change alone creates a sense of cooling embers.