Saturday, April 19, 2025

Sprites in GW-BASIC 2

Let's add some grass and other terrain for the gnome and the snakes to stand on.
10 SCREEN 1
20 DEFINT A-Z
30 GFXSIZE = 33
50 DIM PLAYERGFX(GFXSIZE)
60 DIM MONSTERGFX(GFXSIZE)
70 DIM GRASSGFX(GFXSIZE): DIM ICEGFX(GFXSIZE)
80 GOSUB 800 ' Call to subroutine that reads and draws pixels
90 GET (0, 0)-(15, 15), PLAYERGFX ' Grabs graphics and puts it in an array
100 CLS ' Clear the screen
110 GOSUB 800 ' Read and draw next sprite
120 GET (0, 0)-(15, 15), MONSTERGFX
130 CLS
140 GOSUB 800: GET (0, 0)-(15, 15), GRASSGFX: CLS
150 GOSUB 800: GET (0, 0)-(15, 15), ICEGFX: CLS

200 FOR Y = 0 TO 7
205 GY = Y * 16
210 FOR X = 0 TO 19
215 GX = X * 16
220 IF X > 0 AND X < 19 AND Y > 2 AND Y < 7 THEN PUT (GX, GY), ICEGFX, PSET ELSE PUT (GX, GY), GRASSGFX, PSET
230 NEXT X
240 NEXT Y

300 PUT (32, 56), PLAYERGFX, PSET
310 PUT (128, 80), MONSTERGFX, PSET
320 PUT (192, 32), MONSTERGFX, PSET
330 LOCATE 17: PRINT "A simple program for demonstrating
340 PRINT "16x16 tiled graphics in GW-BASIC."

400 END

800 ' Subroutine that read the DATA statement values
801 ' and then draw pixels with PSET
810 FOR y = 0 TO 15
820 FOR x = 0 TO 15
830 READ c
840 PSET (x, y), c
850 NEXT x
860 NEXT y
870 RETURN

890 ' The sprite data follows below.
891 ' Each value represent the color of an individual pixel.
892 ' Since we're in CGA 320x200 we have four colors to work with.
893 ' They are: 0 = black, 1 = cyan, 2 = magenta, 3 = white

900 ' player gfx
901 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
902 DATA 0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0
903 DATA 0,0,0,0,2,0,2,2,2,2,2,0,0,0,0,0
904 DATA 0,0,0,2,0,2,2,2,2,2,2,2,0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,1,1,1
1019 DATA 1,3,1,1,1,1,1,1,1,3,1,1,1,3,1,1
1020 DATA 3,1,1,1,3,1,1,1,1,1,1,1,3,1,1,1
1021 DATA 1,1,1,3,1,1,1,3,1,1,1,3,1,1,1,3
1022 DATA 1,1,1,1,1,1,3,1,1,1,3,1,1,1,3,1
1023 DATA 1,3,1,1,1,3,1,1,1,3,1,1,1,3,1,1
1024 DATA 3,1,1,1,3,1,1,1,1,1,1,1,3,1,1,1
1025 DATA 1,1,1,3,1,1,1,3,1,1,1,1,1,1,1,3
Hmm. The PUT command draws over old graphics on the screen indiscriminately making black boxes around our little gnome and his snake friends. We'll tackle that next!

No comments:

Post a Comment

Maze generator in GW-BASIC

 A while back I was looking at maze making algorithms written in Basic. I was not very happy with any of the ones I could find at the time, ...