Multiple UDGs
Define all UDGs in a setup routine — ship, bullet, explosion, enemies in one batch.
So far you have defined one or two UDGs at a time. Blockstorm uses fourteen custom characters — the ship, bullet, explosion, four enemy types, power-ups and more. Defining each one individually would mean fourteen separate POKE loops. Instead, this unit puts all the UDG data into a single block of DATA statements and loads them all with one loop at program start.
The Program
5 REM === MULTIPLE UDGs ===
10 BORDER 0: PAPER 0: INK 7: CLS
15 GO SUB 800
20 PRINT AT 3, 8; BRIGHT 1; "BLOCKSTORM"
30 PRINT AT 6, 2; INK 6; "All 14 UDGs defined!"
40 PRINT AT 8, 4; INK 4; CHR$ 144; INK 7; " Drone"
50 PRINT AT 9, 4; INK 5; CHR$ 145; INK 7; " Scout"
60 PRINT AT 10, 4; INK 6; CHR$ 146; INK 7; " Tank"
70 PRINT AT 11, 4; INK 3; CHR$ 147; INK 7; " Bomber"
80 PRINT AT 12, 4; INK 7; CHR$ 148; INK 7; " Bullet"
90 PRINT AT 13, 4; INK 2; CHR$ 149; INK 7; " Explosion"
100 PRINT AT 14, 4; INK 5; CHR$ 150; INK 7; " Double shot"
110 PRINT AT 15, 4; INK 6; CHR$ 151; INK 7; " Shield"
120 PRINT AT 16, 4; INK 7; CHR$ 152; INK 7; " Player ship"
130 PRINT AT 17, 4; INK 2; CHR$ 153; INK 7; " Bomb"
140 PRINT AT 20, 6; INK 7; "Press any key"
150 PAUSE 0
160 STOP
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
Lines 800-830 contain the setup routine. The outer loop runs from 0 to 13, covering UDGs A through N (fourteen characters). The inner loop runs from 0 to 7, reading eight bytes for each UDG. POKE USR CHR$ (65 + i) + j writes each byte to the correct memory address. CHR$ 65 is “A”, CHR$ 66 is “B”, and so on — the loop calculates the letter automatically.
Lines 840-894 hold the DATA for all fourteen UDGs. Each block of eight values defines one character:
| UDG | Character | Purpose |
|---|---|---|
| A | CHR$ 144 | Drone |
| B | CHR$ 145 | Scout |
| C | CHR$ 146 | Tank |
| D | CHR$ 147 | Bomber |
| E | CHR$ 148 | Player bullet |
| F | CHR$ 149 | Explosion frame 1 |
| G | CHR$ 150 | Double shot power-up |
| H | CHR$ 151 | Shield power-up |
| I | CHR$ 152 | Player ship |
| J | CHR$ 153 | Enemy bomb |
| K | CHR$ 154 | Explosion frame 2 |
| L | CHR$ 155 | Shield icon (HUD) |
| M | CHR$ 156 | Drone animation frame 2 |
| N | CHR$ 157 | Scout animation frame 2 |
Line 15 calls the setup routine with GO SUB 800 before anything else happens. By the time the game starts, all fourteen characters are ready.
The CHR$ Offset
UDG A maps to CHR$ 144. UDG B maps to CHR$ 145. The pattern is simple: CHR$ (143 + n) where n is the position (A=1, B=2, and so on). In the code, enemy type numbers map directly to UDGs: type 1 is a drone (CHR$ 144), type 2 is a scout (CHR$ 145), type 3 is a tank (CHR$ 146), type 4 is a bomber (CHR$ 147). The expression CHR$ (143 + t) converts any enemy type number to its UDG character.
GO SUB for Setup
The UDG definition routine lives at line 800 — well away from the main game code. GO SUB 800 jumps there, the routine runs, and RETURN brings execution back. This is the same structure you will use for every reusable section of the game: movement, collision, drawing, scoring. Each section lives at its own line number range and is called with GO SUB.
Try This
Display all fourteen. Write a loop that prints CHR$ 144 through CHR$ 157 across the screen, each in a different INK colour. See all your sprites at once.
Redesign an enemy. Change the eight DATA values for UDG A (the drone). Make it look more aggressive or more alien. Run the program again — the new design appears everywhere the drone is used, with no other code changes needed.