Although nothing particularly special, I felt like writing and showing this. 😀
I am probably not going to make this into much more than it already is, however any feedback is welcome! 😀
Also, any advice on calculating the proper array size to store graphical data is welcome. Assuming the integer data type, I know it involves four bytes for width and height and I need to calculate how many bytes all the pixels take up. It sounds easy in theory, but is harder than it appears in practice.
Due to the overwhelming lack of response this got, I doubt there is any point in starting yet another thread, so I am just going to recycle the one I made not too long ago. 😀
Hi, thanks! 😀 Personally, I do like QB45 and Basic programming, but I do know little about sprites. Hence I didn't reply when this thread was new. 🙁
I'm sure though that there are other QB fans, still.
Or fans of Turbo Basic or Power Basic, also. The latter was popular in the 90s.
There also are lots of users on the net who grew up with the simpler GW-Basic.
Then there are PDS 7.x and and VBDOS, which have lots of features and are good candidates for future retro development.
"Time, it seems, doesn't flow. For some it's fast, for some it's slow.
In what to one race is no time at all, another race can rise and fall..." - The Minstrel
Claculating the number of bytes of an int array is trivial, i guess thats why nobody responded. : )
DIM numBytes AS INTEGER : numBytes = (width * height) * 2 ' bytes per int (in qbasic)
Allow me to clarify, this thread's primary purpose is to just share a sprite demo written in QBasic for the sake of a bit of nostalgia and for anyone who's interested in learning about the topic of sprite programming in QBasic.
As to calculating array sizes for graphics in QBasic, here's another way:
1DEFINT A-Z 2CONST GETHEADERSIZE = &H4 3 4DECLARE FUNCTION GetArraySize& (WidthV AS INTEGER, Height AS INTEGER, BitsPerPixel AS INTEGER, Planes AS INTEGER) 5 6 7FUNCTION GetArraySize& (WidthV AS INTEGER, Height AS INTEGER, BitsPerPlane AS INTEGER, Planes AS INTEGER) 8 GetArraySize& = GETHEADERSIZE + (INT((WidthV * BitsPerPlane + 7) / 8) * Planes) * Height 9END FUNCTION
And since the primary goal of this thread was to share sprite related QBasic stuff:
1DEFINT A-Z 2CONST CHARACTERSIZE = 34 3CONST STEPX = 8 4CONST STEPY = 16 5 6DECLARE SUB DisplayText (Text AS STRING, x AS INTEGER, y AS INTEGER, Verb AS STRING) 7DECLARE SUB Initialize () 8DECLARE SUB LoadFontData () 9DECLARE SUB Main () 10DECLARE SUB Quit () 11 12DIM SHARED FontData(0 TO 8703) AS INTEGER 13 14Initialize 15LoadFontData 16CALL Main 17Quit 18 19SUB DisplayText (Text AS STRING, x AS INTEGER, y AS INTEGER, Verb AS STRING) 20DIM Index AS INTEGER 21DIM Length AS INTEGER 22 23 Length = LEN(Text) 24 25 SELECT CASE UCASE$(LTRIM$(RTRIM$(Verb))) 26 CASE "OR" 27 FOR Index = 1 TO Length 28 PUT (x, y), FontData(ASC(MID$(Text, Index, 1)) * CHARACTERSIZE), OR 29 30 IF x + STEPX > 632 THEN 31 x = 0 32 y = y + STEPY 33 ELSE 34 x = x + STEPX 35 END IF 36 NEXT Index 37 CASE "PRESET" 38 FOR Index = 1 TO Length 39 PUT (x, y), FontData(ASC(MID$(Text, Index, 1)) * CHARACTERSIZE), PRESET 40 41 IF x + STEPX > 632 THEN 42 x = 0 43 y = y + STEPY 44 ELSE 45 x = x + STEPX 46 END IF 47 NEXT Index 48 49 CASE "PSET" 50 FOR Index = 1 TO Length 51 PUT (x, y), FontData(ASC(MID$(Text, Index, 1)) * CHARACTERSIZE), PSET 52 53 IF x + STEPX > 632 THEN 54 x = 0 55 y = y + STEPY 56 ELSE 57 x = x + STEPX 58 END IF 59 NEXT Index 60 CASE ELSE
…Show last 35 lines
61 ERROR 5 62 END SELECT 63END SUB 64 65SUB Initialize () 66 SCREEN 12 67 PALETTE 68 CLS 69END SUB 70 71SUB LoadFontData () 72 DEF SEG = VARSEG(FontData(0)) 73 BLOAD "VGAFont.dat", VARPTR(FontData(0)) 74END SUB 75 76SUB Main () 77DIM Banner AS STRING 78 79 Banner = "V G A F O N T - B Y : P E T E R S W I N K E L S , - * * * 2 0 2 5 * * *" 80 DisplayText Banner, 8, 16, "PSET" 81 DisplayText Banner, 9, 17, "OR" 82 DisplayText " Press any key to exit. ", 18, 45, "PRESET" 83 84 DO 85 LOOP WHILE INKEY$ = "" 86END SUB 87 88SUB Quit () 89 SCREEN 0 90 WIDTH 80, 25 91 COLOR 7, 0 92 CLS 93 SYSTEM 94END SUB
While not animated and technically more about fonts than sprites this might also be of interest or amusing for anyone into QBasic sprite/graphics programming. 😀
Here's an excerpt from a graphics intense QuickBASIC (but should also work in QBasic) program demonstrating how to achieve a side ways scrolling image effect:
1SUB DisplayWorldMap 2DIM Map1(&H0 TO &H6400) 3DIM Map2(&H0 TO &H1D0) 4 5 DisplayImage 95, 60, "World.map", "", 0, 0 6 DO 7 GET (95, 60)-STEP(445, 225), Map1 8 GET (541, 60)-STEP(2, 225), Map2 9 PUT (95, 60), Map2, PSET 10 PUT (98, 60), Map1, PSET 11 LOOP WHILE INKEY$ = "" 12END SUB
And a final note for now:
While I am mostly talking about QBasic specifically, most of this code could probably be made to work in other MS-DOS based BASIC dialects with little to no effort. 😀