Let's Build a Roguelike
I feel silly asking a question about the very first step of the tutorial, but what exactly did you have to do to get the huge array of hexadecimal values for each image?
I've been planning on going through the tutorial making my own changes to the code to reflect my own game, but I'm stuck at the very first step because I don't have an image or the color array for it.
Very nice tutorial otherwise! I can't wait to see what I'm able to make with it.
I've been planning on going through the tutorial making my own changes to the code to reflect my own game, but I'm stuck at the very first step because I don't have an image or the color array for it.
Very nice tutorial otherwise! I can't wait to see what I'm able to make with it.
Well, you really don't need those includes as they are just background images. You could simply substitute a bitmap for them since the program uses a graphic screen.
What I did was create a bitmap the size of the text screen, 80 by 60. I then pasted some graphics on it and saved it as a bitmap. I then loaded it up into a 640/480 graphic screen, iterated through the image using two For-Next loops and grabbed the screen color using the Point function. I then saved the colors into a file as you see them in the *.bi files.
To print just iterates through the text screen (0 to 79, 0 to 59) printing chr(219) in the color contained within the array. To grab a color from the array just use pixel = array(x + y * gr_width).
Here is my little convert program. There is a bug in this though that adds an extra 0 in the array that you will need to delete before using. I haven't bothered fixing the bug yet, since this is just a quick and dirty utility.
What I did was create a bitmap the size of the text screen, 80 by 60. I then pasted some graphics on it and saved it as a bitmap. I then loaded it up into a 640/480 graphic screen, iterated through the image using two For-Next loops and grabbed the screen color using the Point function. I then saved the colors into a file as you see them in the *.bi files.
To print just iterates through the text screen (0 to 79, 0 to 59) printing chr(219) in the color contained within the array. To grab a color from the array just use pixel = array(x + y * gr_width).
Here is my little convert program. There is a bug in this though that adds an extra 0 in the array that you will need to delete before using. I haven't bothered fixing the bug yet, since this is just a quick and dirty utility.
Code: Select all
'Convert.bas
'Richard Clark
'Extracts the color information from a 24/32 bit bitmap
'to an include file for use in an FB program.
'Using a graphic screen and the Point function.
'Do not compile with -s gui, as this uses the console screen
'for input.
'Public doman, use any way you like.
dim as integer iw, ih, sw, sh, dp = 32
dim as string iname, aname, oname
dim as integer x, y, i, fh, cnt, filenum, per
Input "Enter bitmap filename";iname
Input "Enter graphic screen width";sw
if sw = 0 then sw = 800
Input "Enter graphic screen height";sh
if sh = 0 then sh = 600
If Len(iname) > 0 Then
per = InStr(iname, ".")
If per > 0 Then
aname = Left(iname, per - 1)
oname = Left(iname, per - 1) & ".bi"
Else
aname = iname
oname = aname & ".bi"
iname = iname & ".bmp"
EndIf
End If
if len(iname) = 0 or len(aname) = 0 or len(oname) = 0 then
print "No values given for filename, array name or output file name."
sleep
end
end if
if sw <= 0 or sh <= 0 or dp <= 0 then
print "Screen dimensions and depth must be greater than zero."
sleep
end
end if
if len(dir(iname)) = 0 then
print "Cannot find " & iname &"."
sleep
end
end if
'' open BMP file
filenum = FreeFile()
If Open( iname For Binary Access Read As #filenum ) <> 0 Then
Print "Cannot find " & iname & "."
Sleep
End
EndIf
' retrieve BMP dimensions
Get #filenum, 19, iw
Get #filenum, 23, ih
Close #filenum
dim bmvals(iw * ih) as uinteger
fh = freefile
if open(oname for output as #fh) <> 0 then
print "Cannot open output file."
sleep
end
end if
screenres sw, sh, dp
if ScreenPtr = 0 then
print "Cannot set graphic screen."
sleep
close fh
end
end if
bload iname
'Print out header information
Print #fh, aname; ":"
for x = 0 to iw - 1
for y = 0 to ih - 1
bmvals(x + y * iw) = point(x, y)
next
next
Print #fh, "Data ";
for i = 0 to ubound(bmvals)
If i = UBound(bmvals) Then
print #fh, "&h" & hex(bmvals(i))
Else
cnt += 1
If cnt < 8 then
print #fh, "&h" & hex(bmvals(i)) & ",";
Else
print #fh, "&h" & Hex(bmvals(i))
Print #fh, "Data ";
cnt = 0
end If
End If
next
close fh
-
- Posts: 272
- Joined: May 28, 2005 10:21
- Contact:
-
- Posts: 272
- Joined: May 28, 2005 10:21
- Contact: