_____ _ ___ _ _ _
|_ _| |__ ___ / _ \ _ _| |_ ___ _ __| | (_)_ __ _ ___ __
| | | '_ \ / _ \ | | | | | | __/ _ \ '__| | | | '_ \| | | \ \/ /
| | | | | | __/ |_| | |_| | || __/ | | |___| | | | | |_| |> <
|_| |_| |_|\___|\___/ \__,_|\__\___|_| |_____|_|_| |_|\__,_/_/\_\
Last updated: 2021/03/27
Using the img2qb Python script, you can convert an image into a QuickBASIC (QB45, QBX, and QB64) friendly DATA format. A preview file and a plain text *.QBD (QBASIC DATA) file are created in which you can either copy/paste the inside text to a QB project or use it some other way. However, this script is only meant to help with creating small sprites. QB45 and QBX will run the created array just fine as long as it's 160x100 or less but it will not compile to an EXE if the lines in the array are too long.
Run via 'python /path/to/img2qb.py' and follow the instructions from there.
DATA ... 'If you chose to already include DATA line-by-line in the script, DATA ... 'you can copy and paste the *.qbd file contents here. DATA ... SCREEN 12 'Use SCREEN number you picked in img2py script CLS SPRITEW = 56 'Sprite width SPRITEH = 55 'Sprite height SPRITEX = 170 'Initial x position of sprite SPRITEY = 100 'Initial y position of sprite SCREENW = 640 'Screen width SCREENH = 480 'Screen height FOR SPRITEPIXELY = 1 TO SPRITEH FOR SPRITEPIXELX = TO SPRITEW READ SPRITEPIXELCOLOR% PSET (SPRITEPIXELX, SPRITEPIXELY), SPRITEPIXELCOLOR% NEXT SPRITEPIXELX NEXT SPRITEPIXELY ' You can also do the following for transparent pixels. The Python ' script uses variables like "X" and "Y" instead of "SPRITE..." FOR SPRITEPIXELY = 1 TO SPRITEH ' For each row; image height SPRITEPIXELX = TO SPRITEW ' For each column; image width READ DotColor IF DotColor > 0 THEN 'We can then use this IF-THEN statement to PSET (SPRITEPIXELX, SPRITEPIXELY), DotColor 'make COLOR 00 as a transparent color. END IF NEXT SPRITEPIXELX NEXT SPRITEPIXELY 'Anything from here down is for sprite movement only and is not required 'if you just want to view the image, but anything over 160x100 will probably 'not load on anything older than QB64. DIM SPRITE%(SPRITEW * SPRITEH) GET (1, 1)-(SPRITEW, SPRITEH), SPRITE% CLS ONE: PUT (SPRITEX, SPRITEY), SPRITE% WAIT &H3DA, 8 PUT (SPRITEX, SPRITEY), SPRITE% 'Use classic WASD keys to move sprite and prevent out-of-bounds errors io$ = INKEY$ IF io$ = "w" THEN SPRITEY = SPRITEY - 5: IF SPRITEY < 0 THEN SPRITEY = 0 IF io$ = "a" THEN SPRITEX = SPRITEX - 5: IF SPRITEX < 0 THEN SPRITEX = 0 IF io$ = "s" THEN SPRITEY = SPRITEY + 5: IF SPRITEY > (SCREENH - SPRITEH) THEN SPRITEY = SCREENH - SPRITEH IF io$ = "d" THEN SPRITEX = SPRITEX + 5: IF SPRITEX > (SCREENW - SPRITEW) THEN SPRITEX = SCREENW - SPRITEW IF io$ = "q" THEN END GOTO ONE:
DATA... DATA... SCREEN 13 'Use SCREEN number you picked CLS DIM DotColor as byte DIM Pause as string FOR Y as integer = 1 TO 200 ' For each row; image height FOR X as integer = 1 TO 320 ' For each column; image width READ DotColor IF DotColor > 0 THEN 'We can then use this IF-THEN statement to PSET (X, Y), DotColor 'make COLOR 00 as a transparent color. END IF NEXT X NEXT Y LOCATE 20, 1 INPUT "Pause", Pause