Generating sprites while reading .txt files
Author |
Message |
Skilgannon
|
Posted: Tue Apr 25, 2006 5:25 pm Post subject: Generating sprites while reading .txt files |
|
|
I'm trying to make an rpg game, and I want to generate the world while keeping track of collision at the same time, using 2d arrays.
Basically I have a 2d of 18x25, in which values 0,1 or 2 are put, and depending on which, it outputs or rather SHOULD output a 16x16 sprite.
For some reason, it doesn't work.
Here's a program which randomly generates a 18 row x 25 collumn txt file with numbers 0,1,2
code: |
var fileName : string := "rand_level.txt"
var fileNo : int
var inputVariable : string (100)
open : fileNo, fileName, put
var k : int := 0
for i : 1 .. 18
for j : 1 .. 25
randint (k, 0, 2)
if j not= 25 then
put : fileNo, k ..
else
put : fileNo, k
end if
end for
end for
close : fileNo
|
Now here's the program which should read the .txt file and output the sprites :
code: |
var textfile : int
var text : string
var testing : array 1 .. 18, 1 .. 25 of string
procedure loadtextfile
open : textfile, "rand_level.txt", get
for q : 1 .. 18
for w : 1 .. 25
if textfile > 0 then
exit when eof (textfile)
get : textfile, text
testing (q, w) := text
end if
end for
end for
end loadtextfile
procedure drawlevel
for q : 1 .. 18
for w : 1 .. 25
put testing(q,w)
%Pic.ScreenLoad ( testing(q,w) + ".bmp", q * 16, w * 16, picMerge)
%Pic.ScreenLoad ( "World/2.bmp", w * 16, q * 16, picMerge)
end for
end for
Pic.ScreenSave (0, 0, maxx, maxy, "levelTest.bmp")
cls
end drawlevel
setscreen ("graphics:400;288")
setscreen ("nobuttonbar")
loadtextfile
drawlevel
|
For some reason it says "Variable has no value".
Can someone help ?
I've also attached the files in a .rar
Description: |
|
 Download |
Filename: |
read_and_display.rar |
Filesize: |
12.17 KB |
Downloaded: |
46 Time(s) |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Delos

|
Posted: Tue Apr 25, 2006 5:39 pm Post subject: (No subject) |
|
|
Try adding a space between each of your numbers as you write them to the file. Currently it looks like they'll all be written one after the other. You can test this buy puting the value of each element of the array ('testing') as it is being read in.
So, instead of:
code: |
put : fileNo, k ..
% Which by the way is an horribly named variable! "k"!? It tells
% you nothing...
|
Replace with:
code: |
put : fileNo, intstr (k) + " "..
% intstr () used since you are catenating two variables; must both be in string format.
|
Haven't tested the code, but that should work. Good luck on your RPG, and make sure you read the [Turing Walkthrough] for some important pointers and general info that will help you improve your coding hugely.
|
|
|
|
|
 |
Skilgannon
|
Posted: Tue Apr 25, 2006 8:08 pm Post subject: (No subject) |
|
|
Solved it, I figured out what I did wrong XD
Thanks
|
|
|
|
|
 |
|
|