|
Post by Enzo on Feb 16, 2021 21:36:21 GMT
Making money online with games for my friend is nothing new, I am not allowed into the UK (and was told so at the airport) because I've sold 'party hats' at 70$ USD a mill for 2000M worth approx 80k USD wholesale (game runescape; year 2006, check rsgold.com on waybackwhenmachine) which was illegal but my friend got all the money so it doesn't phase me.
|
|
|
Post by Rod on Feb 16, 2021 21:50:46 GMT
We should stick to coding. The .bmp idea was your own. You don’t need to use a .bmp file. It adds file format complication but it does allow painting the map with any paint program.
You could just use a simple file. But you would access it in a similar way, open for binary, read write data.
If you look at the functions getpixel reads three bytes of data and set pixel writes three bytes of data. I used global Red Green and Blue to return three bytes of info from the getpixel function because a function returns just one value. Set pixel is easier and we pass in three values.
You can’t expect every aspect of the programming task to be simple. You just need to study what’s offered and if you see any worth in it use it. If not keep exploring.
|
|
|
Post by Enzo on Feb 17, 2021 0:46:22 GMT
You're telling me
#bmp chr$(b);chr$(g);chr$(r); hides data from complier to be read as
Blue=asc(input$(#bmp,1)) Green=asc(input$(#bmp,1)) Red=asc(input$(#bmp,1))
from input #bmp handle
|
|
|
Post by Enzo on Feb 17, 2021 0:55:14 GMT
global file$,mapw,maph,padding,offset,bytes,Blue,Green,Red, pointer, set,_ x,y,r,b,g,file$ goto [loadbmp]
[return]
for x = 1 to mapw for y = 1 to maph
set = getpixel(x,y,r,g,b,pointer,offset,bytes,mapw,maph,padding,Blue,Red,Green) set = setpixel(x,y,b,g,r,pointer,offset,bytes,mapw,maph,padding)
print b, Blue
next y next x close #bmp end
[loadbmp] filedialog "", ".bmp", file$ 'now open the bmp file for binary read/write access open file$ for binary as #bmp
'analyse the file header bytes seek #bmp,10 'picture data offset, where the color data starts 4 bytes of data offset=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,18 'width 4 bytes of data mapw=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,22 'height 4 bytes of data maph=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,28 'bits per pixel, ie color depth 2 bytes of data bits=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256
'work out start of picture data and how to move through file pointer=offset
'work out how many bytes in the bits per pixel 24=3 bgr 32=4 abgr bytes=bits/8
'work out padding each raster line must be a 4byte multiple mult=bits/8*mapw/4 padding = 4*(1-(mult-int(mult))) mod 4 'close #bmp goto [return]
function setpixel(x,y,b,g,r,pointer,offset,bytes,mapw,maph,padding)
'raster lines are stored bottom up so we invert y y=(maph-1)-y pointer=offset+x*bytes+y*(mapw*bytes+padding) 'set pixel color seek #bmp, pointer #bmp chr$(b);chr$(g);chr$(r); end function
function getpixel(x,y,r,g,b,pointer,offset,bytes,mapw,maph,padding,Blue,Red,Green) 'reads 'raster lines are stored bottom up so we invert y y=(maph-1)-y pointer=offset+x*bytes+y*(mapw*bytes+padding) 'get pixel color stored as BGR Liberty needs RGB seek #bmp, pointer Blue=asc(input$(#bmp,1)) Green=asc(input$(#bmp,1)) Red=asc(input$(#bmp,1)) end function
Pointer = 54, Green Red and Blue all stay at 0, these functions do not work
|
|
|
Post by Enzo on Feb 17, 2021 1:06:00 GMT
Does anyone know of a working sprite creator you can Pay for? Not sure I trust Libertys built in one now for the $50 app purchase
|
|
|
Post by tsh73 on Feb 17, 2021 8:02:05 GMT
Wow you guys so fast - I am late for two days and it's already 2 more pages! Rod, 1) I did not find a sprite mask program, but I found an unnamed sprite masking program in Liberty Basic help on sprites. This is it? 2) Andy's program designed to work with 24-bit BMP It has a check inside but it doesn't work, I wrote in his thread on Fast JB Sprite Maker. justbasiccom.proboards.com/thread/548/fast-jb-sprite-maker
|
|
|
Post by Rod on Feb 17, 2021 9:44:11 GMT
Ok, this is the same routines built into a display program. I just show the first 10x10 pixels from the file as 64x64 sprite based tiles. While using Global values to return info is quirky it does work. The alternative is to have three functions for blue red and green. OH! you should read the first words you wrote on this thread, if it has stopped being fun, leave it for a while. That's what I do. To make this demo work you need a bmp of any size but the very top left is all I look at, those 10x10 pixels should have color values of 0,8,16,32,64 in the blue value. I will upload a demo .bmp The demo bmpopen "Pixel Map" for graphics_nsb as #1
global file$,mapw,maph,padding,offset,bytes,Blue,Green,Red
'create some terrain tiles to use #1 "down ; fill black ; color white ; trapclose [quit]" #1 "getbmp bak 0 0 640 640 ; background bak" #1 "backcolor white ; place 0 0 ;boxfilled 64 64" #1 "color blue ; backcolor blue ; place 0 64 ; boxfilled 64 128" #1 "getbmp sea 0 0 64 128" #1 "color yellow ; backcolor yellow ; place 0 64 ; boxfilled 64 128" #1 "getbmp sand 0 0 64 128" #1 "color brown ; backcolor brown ; place 0 64 ; boxfilled 64 128" #1 "getbmp dirt 0 0 64 128" #1 "color green ; backcolor green; place 0 64 ; boxfilled 64 128" #1 "getbmp grass 0 0 64 128" #1 "color darkgray ; backcolor darkgray ; place 0 64 ; boxfilled 64 128" #1 "getbmp rock 0 0 64 128"
'now open the bmp file for binary read/write access and leave it open file$="test.bmp" open file$ for binary as #bmp
'analyse the file header bytes seek #bmp,10 'picture data offset, where the color data starts 4 bytes of data offset=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,18 'width 4 bytes of data mapw=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,22 'height 4 bytes of data maph=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,28 'bits per pixel, ie color depth 2 bytes of data bits=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256
'work out start of picture data and how to move through file pointer=offset
'work out how many bytes in the bits per pixel 24=3 bgr 32=4 abgr bytes=bits/8
'work out padding each raster line must be a 4byte multiple mult=bits/8*mapw/4 padding = 4*(1-(mult-int(mult))) mod 4
'now read the map and place the sprites 'for demo I am just placing 10x10 tiles 'I have used 0,8,16,32 as the numbers to identify each tile 'you could equally use 1,2,3,4 for x=1 to 10 for y=1 to 10 nul=getpixel(x,y) 'Blue now contains the tile info select case Blue case 0 'sea sea=sea+1 #1 "addsprite sea";sea;" sea ; spritexy sea";sea;" ";64*x;" ";64*y case 8 sand=sand+1 #1 "addsprite sand";sand;" sand ; spritexy sand";sand;" ";64*x;" ";64*y case 16 dirt=dirt+1 #1 "addsprite dirt";dirt;" dirt ; spritexy dirt";dirt;" ";64*x;" ";64*y case 32 grass=grass+1 #1 "addsprite grass";grass;" grass ; spritexy grass";grass;" ";64*x;" ";64*y end select next next #1 "drawsprites"
wait [quit] close #1 close #bmp end
function setpixel(x,y,r,g,b) 'raster lines are stored bottom up so we invert y y=(maph-1)-y pointer=offset+x*bytes+y*(mapw*bytes+padding) 'set pixel color seek #bmp, pointer #bmp chr$(b);chr$(g);chr$(r); end function
function getpixel(x,y) 'raster lines are stored bottom up so we invert y y=(maph-1)-y pointer=offset+x*bytes+y*(mapw*bytes+padding) 'get pixel color stored as BGR Liberty needs RGB 'we fill globals to return three values seek #bmp, pointer Blue=asc(input$(#bmp,1)) Green=asc(input$(#bmp,1)) Red=asc(input$(#bmp,1)) end function
|
|
|
Post by Enzo on Feb 27, 2021 21:57:44 GMT
Hmmm, I might have to improvise with the sailing part of the game, I can't seem to get my previous file read and load properly I'm not sure if the array is being loaded correctly and read as well as i've debugged and everything looked okay.
Your snippet Rod just to let you know doesn't allow for a full use of width and height of bmp I ran into trouble trying to use.
Back to the drawing board, any suggestions?
|
|
|
Post by Rod on Feb 28, 2021 9:24:20 GMT
Code will get you a much better answer. The file debugging is best done by printing what you get and being sure it is what you expect. So just open the file and print the contents as a first step. After that it is just plain old debugging going a step at a time till you see the problem.
As for the snippet you will need to show the code that is not working for you. I just checked using a 2000x2000 bmp and it read it edge to edge without any problem. Perhaps you should go back to a simple file holding the tile info. then navigating the file will be a lot easier.
|
|
|
Post by Enzo on Feb 28, 2021 23:41:37 GMT
|
|
|
Post by Rod on Mar 1, 2021 19:49:27 GMT
I had a quick look. Not sure what you mean by off. But what I see is that your select$() function looses the first "w" that comes off the file. It comes in to s$ as "w" but select$() returns "" for that. The next one comes in as "w," and select$() returns correctly "w". So that might be where you are going off.
But what do you mean by "off"?
|
|
|
Post by Enzo on Mar 2, 2021 4:48:23 GMT
I found the real error besides some typos and some other small changes, there's a NEW LINE character, looks like two actually, I need to omit them with a if then statement and add 2, to var, to continue the next line input, otherwise I suppose the workaround was used by cundo as a new line being indicated by a space character could still be used.
|
|
|
Post by Enzo on Mar 2, 2021 5:36:28 GMT
I got it to work used a if then and modifier for mid$(var) Still looking for a sprite masker.
|
|
|
Post by Rod on Mar 2, 2021 9:33:21 GMT
This will take a sprite.bmp and create a masked sprite. It will save the file in the same location as maskedsprite.bmp You could use files command to get a list of .bmps and process that list automatically. I changed getpixel() to return one long value for the color.
[spritemask] global mapw,maph,offset,pointer,bytes,padding file$="sprite.bmp" 'now open the bmp file for binary read/write access open file$ for binary as #bmp
'analyse the file header bytes seek #bmp,10 'picture data offset, where the color data starts 4 bytes of data offset=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,18 'width 4 bytes of data mapw=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,22 'height 4 bytes of data maph=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,28 'bits per pixel, ie color depth 2 bytes of data bits=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256
'work out start of picture data and how to move through file pointer=offset
'work out how many bytes in the bits per pixel 24=3 bgr 32=4 abgr bytes=bits/8
'work out padding each raster line must be a 4byte multiple mult=bits/8*mapw/4 padding = 4*(1-(mult-int(mult))) mod 4
WindowWidth=400 WindowHeight=400 UpperLeftX=10 UpperLeftY=10 open "Spritemask" for graphics as #1 #1 "trapclose [quit]" loadbmp "s",file$ #1 "down ; color black ; fill white ; drawbmp s 0 ";maph for y=0 to maph-1 for x=0 to mapw-1 pixel=getpixel(x,y) if pixel >0 then #1 "set ";x;" ";y next next #1 "getbmp ms 0 0 ";mapw;" ";maph+maph bmpsave "ms","mask"+file$
[quit] close #bmp close #1 end
function setpixel(x,y,r,g,b) 'raster lines are stored bottom up so we invert y y=(maph-1)-y pointer=offset+x*bytes+y*(mapw*bytes+padding) 'set pixel color seek #bmp, pointer #bmp chr$(b);chr$(g);chr$(r); end function
function getpixel(x,y) 'raster lines are stored bottom up so we invert y y=(maph-1)-y pointer=offset+x*bytes+y*(mapw*bytes+padding) 'get pixel color stored as BGR Liberty needs RGB seek #bmp, pointer Blue=asc(input$(#bmp,1)) Green=asc(input$(#bmp,1)) Red=asc(input$(#bmp,1)) getpixel=Red+256*Green+256*256*Blue end function
|
|
|
Post by Enzo on Mar 2, 2021 22:42:19 GMT
I've been having to loop each sprites twice, once for a pixel change of 0 to 1 to omit all black pixels in final product, then filling white space with black using MSPaint and using libertys built in sprite masker on JB help file to finalize product; the latter was also a mod of libs sprite mask. I suppose theoretically you could have second parse to fill white squares with black, put them all in a series to load with fileinfo in folder and compile all at once.
Although most sprites needs to be resized, this will be the longest part of the build.
|
|