10 SCREEN 1
20 DEFINT A-Z
30 GFXSIZE = 33 ' This value is the size of an array containing one sprite.
31 ' The GFXSIZE value calculated from the bit-depth (4 colors = 2 bit) and
32 ' the dimensions of the graphics.
33 '
34 ' In this case the tile is 16x16x2 which results in the calculation
35 ' looking like this: ((4 + INT((16 * 2 + 7) / 8) * 16) + .5) \ 2
36 ' Let's not get into what all of that means right now.
37 '
38 ' Note: In GW-BASIC you have to store each sprite in separate arrays.
39 ' In QBASIC, on the other hand, you can store several sprites in a single
40 ' array and use an index to specify the one you want to draw when calling
41 ' the PUT command.
50 DIM PLAYERGFX(GFXSIZE)
60 DIM MONSTERGFX(GFXSIZE)
70 GOSUB 800 ' Call to subroutine that reads and draws pixels
80 GET (0, 0)-(15, 15), PLAYERGFX ' Grabs graphics and puts it in an array
90 CLS ' Clear the screen
100 GOSUB 800 ' Read and draw next sprite
110 GET (0, 0)-(15, 15), MONSTERGFX
120 CLS
150 PUT (32, 56), PLAYERGFX, PSET
160 PUT (128, 80), MONSTERGFX, PSET
170 PUT (192, 32), MONSTERGFX, PSET
180 LOCATE 17: PRINT "A simple program for demonstrating
190 PRINT "16x16 tiled graphics in GW-BASIC."
300 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.
901 ' 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,0,0,0
905 DATA 0,0,0,3,0,3,3,3,3,3,3,3,0,0,0,0
906 DATA 0,0,0,0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saturday, April 19, 2025
Sprites in GW-BASIC
Simple example that draws some 16x16 sprites in 4 color CGA mode to the screen.
Subscribe to:
Post Comments (Atom)
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, ...
-
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, ...
-
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 PLAYE...
-
Previously we've stored our graphics data in a very verbose manner. This is not ideal since GW-BASIC is an interpreted language and keep...
No comments:
Post a Comment