Let's Build a Roguelike

New to FreeBASIC? Post your questions here.
Post Reply
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

Looks like I missed the chapter 15 update here. Chapters 15 and 16 are up, see the first post.
Bluey
Posts: 2
Joined: Sep 14, 2010 3:28

Post by Bluey »

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.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

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.

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
Bluey
Posts: 2
Joined: Sep 14, 2010 3:28

Post by Bluey »

Ah, awesome. I'm brand new to FreeBasic (in hindsight, a Roguelike is probably not the best program to start out with), so I was worried that the whole "Point method" was something that I should've known before starting the tutorial.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

Added chapters 17-21. See first post.
Jocke The Beast
Posts: 272
Joined: May 28, 2005 10:21
Contact:

Post by Jocke The Beast »

Amazing work. Well documented. Really helpfull to learn from. One short word: GREAT :)

Ps. Have u all gone blind here?! This is some great material here guys, I suggest you all to check it out!
stan10785
Posts: 2
Joined: Nov 23, 2010 20:05
Location: KY USA

Post by stan10785 »

It is great stuff. It is the best that I have seen and something that I have wanted to see for a number of years in any language on any platform. It is straight forward and dang easy to follow along with.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

stan10785 wrote:It is great stuff. It is the best that I have seen and something that I have wanted to see for a number of years in any language on any platform. It is straight forward and dang easy to follow along with.
Sorry I missed this one. Thanks!
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

Chapter 22: Projectile Combat. See first post.

Reminder: These updates are accumulative, so you only need the latest chapter.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

Chapters 23, 24. See first post.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

Chapters 25-27 are up. See first post.
Jocke The Beast
Posts: 272
Joined: May 28, 2005 10:21
Contact:

Post by Jocke The Beast »

Better & better my friend. I'm quite amazed over the work you've done.
THANKS again.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

Thanks man.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

Chapter 28: Jewelry is up. See first post.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

Added chapter 29: Weapon Magic. See first post.
Post Reply