**I jsut need this so i can start designing levels...
Sponsor Sponsor
romantic_programmer
Posted: Wed Oct 04, 2006 12:45 pm Post subject: (No subject)
sry for the double repost.... i have 250 tiles... and i still cant figure how to go about drawing the tiles to produce a map...
NikG
Posted: Wed Oct 04, 2006 7:16 pm Post subject: (No subject)
Use the code /code tags when posting... er... code.
Not 100% sure what you're asking, but my guess is that you have a txt file (map) and you have the different tiles (250 of them), and the #s in the txt file correspond to the tile you want. Am I right?
-Load your map file into a 2d array
-Go through each row and column in the array and draw the tile depending on what the number is:
code:
for y:1..6
for x:1..10
Pic.Draw(Map(x,y),x*15,y*15,picCopy)
end for
end for
(UNTESTED)
Replace the *15 with however big your tiles are.
romantic_programmer
Posted: Thu Oct 05, 2006 9:53 am Post subject: (No subject)
The only problem with
code:
for y:1..6
for x:1..10
Pic.Draw(Map(x,y),x*15,y*15,picCopy)
end for
end for
is that it will repeat the same image. Which lets me have no control over my map... i somw how need to to read the txt files.
code:
for y:1..15
for x:1..25
Pic.Draw(Get it to read the txt file here,x*32,y*32,picCopy)
end for
end for
and like you said your code was untested... but then again so you know... it will only show one tile and display it repeatedly according to what the for statement is set to...
do_pete
Posted: Thu Oct 05, 2006 9:56 am Post subject: (No subject)
You should start your for loop from 0 so that the bottom left of the screen gets drawn. And this will not draw the same image on the screen because you have your pictures in a 2d array and are drawing the picture Map(x,y)[/code]
romantic_programmer
Posted: Thu Oct 05, 2006 10:15 am Post subject: (No subject)
code:
for y:0..20
for x:0..25
Pic.Draw (mapTile (1),x*32,y*32,picCopy)
end for
end for
That is what i have......
But it is still drawing the same image. OVer and over.... I tried to do it with and (x,y) but says their is too many subscripts. For mapTile
romantic_programmer
Posted: Thu Oct 05, 2006 10:20 am Post subject: (No subject)
can some one just dleate this topic... i will figure it out on my own... no point to keep the topic
Mazer
Posted: Thu Oct 05, 2006 10:37 am Post subject: (No subject)
I could easily delete it, but we generally prefer to not delete topic in the help sections. There's always something for someone (if not the original poster) to learn.
Are you sure you don't want our help? It seemed to me you were pretty close already.
(If not, don't read the rest of my post)
romantic_programmer wrote:
code:
for y:0..20
for x:0..25
Pic.Draw (mapTile (1),x*32,y*32,picCopy)
end for
end for
It's drawing just one tile repeatedly because that's all you're telling it to do. Ideally, mapTile would be a one dimensional array of integers in which you loaded your pictures. You should also have a two dimensional array (of integers) that represents the map just like the text file is doing. Then you could instead do this:
code:
for y : 0 .. 20
for x : 0 .. 25
Pic.Draw (mapTile(map(x, y), x * 32, y * 32, picCopy)
end for
end for
As for reading in the text file, sorry, but Turing file I/O is a bit fuzzy for me. I think you'd have something like the previous for loop (assuming all maps will be 21x26 tiles), but instead of the Pic.Draw you'd be getting an integer from the text file.
Sponsor Sponsor
Clayton
Posted: Thu Oct 05, 2006 11:57 am Post subject: (No subject)
things like this make my heart break, instead of doing that, have a loop read from the file instead eg.
code:
var mapTile : array 0..249 of int
for i : 0..249
mapTile(i) := Pic.FileNew ("resources/tilesets/land/land/main/"+intstr(i)+".bmp")
end for
This makes it much simpler to read, and takes and uber less amount of time to code
TokenHerbz
Posted: Thu Oct 05, 2006 2:53 pm Post subject: (No subject)
Try somthing along these lines:
[code]
var TileSize := 20 %%sets the tiles size
var TileRow : int := 30 %%the tiles column and row sizes
var TileColumn : int := 30
var file : int %%to call my maps
var TileLoc : flexible array 1 .. TileRow, 1 .. TileColumn of int %%to get the locations of the tiles
var ScreenShot : int %%used to make the picture more effective
var map_number: int := 1 %%can use to show you which map your on
proc draw_map
cls %%this is to clear the map that may be present befor
open : file, "Maps/Map" + intstr (map_number) + ".txt", get %%txt file
for x : 1 .. upper (TileLoc, 1)
for y : 1 .. upper (TileLoc, 2)
get : file, TileLoc (x, y)
TokenHerbz
Posted: Thu Oct 05, 2006 3:00 pm Post subject: (No subject)
Err i some how posted my message trying to write my code
Tabbing and all, note my fault:
The rest of it:
after you can draw certain tiles that you have in your txt:
code:
if TileLoc (x, y) = 1 then
drawfillbox (x * TileSize, y * TileSize, (x + 1) * TileSize, (y + 1) * TileSize, brightgreen) %%ground
end if
we should take a screen shot of our level, so we dont have to use the loops always:
code:
%%end of proc
ScreenShot := Pic.New (0, 0, 620, 620)
close : file
end draw_map
And to draw the map, simply have a proc like this:
code:
proc map
Pic.Draw (ScreenShot, 0, 0, picCopy) %%draws the map
end map
and call it:)
OverView, the first proc is to change the map, you change the file and vars needed: Ex:
code:
map_number := 2
%%OR
map_number := 3
%%will make this a different txt file, if you name them map1, map2, etc:
open : file, "Maps/Map" + intstr (map_number) + ".txt", get %%txt file
hahaha hows that better? i tend to over do things and the wrong way at that, but it works, so enjoy.
romantic_programmer
Posted: Thu Oct 05, 2006 7:07 pm Post subject: (No subject)
ok, right now i am at home... lol... I need to some how get turing here too... but tommorw will put this stuff to work and give ya a heads up....
romantic_programmer
Posted: Fri Oct 06, 2006 11:52 am Post subject: (No subject)
Ok i am making progress.. here is what i got so far...
code:
var tileID : int
var tileNM : string
var shrCut : string := "resources/tilesets"
var mapTile : array 1 .. 250 of string
var tileFile : string := "MapTile_Declarations.txt"
var mapId : array 1 .. 250 of int
open : tileID, tileFile, get
assert tileID > 0
var ctrLines : int := 0
loop
exit when eof (tileID)
get : tileID, tileNM : *
if tileNM not= "" then
ctrLines += 1
mapTile (ctrLines) := shrCut + tileNM + ".bmp"
mapId (ctrLines) := Pic.FileNew (mapTile (ctrLines))
put ctrLines : 3, " ", mapTile (ctrLines)
delay (10)
end if
end loop
I know this isn't much but it is a big breakthrough... Now i just need to get the actual maping system to work and i will be set.... i think...
NikG
Posted: Fri Oct 06, 2006 1:48 pm Post subject: (No subject)
I knew I'd made a mistake. What Mazer said was right: mapTile(map(x, y)), not just map(x,y) in the Pic.Draw.
Freakman, that big loop might not be possible because what are the chances that all 250 tiles are in the resources/tilesets/land/land/main folder? Most probably, they are in different folders.
However, romantic_programmer, the lesson is that if you do have many tiles in a certain folder, using several for loop is better that typing each line individually.
About your code, it didn't really make sense to me, so let me give you a step by step of what you need.
-Declare your tiles array (0 or 1..250) and populate it (as you did before)
-Declare a 2 dimensional array (check the Turing Walkthrough for a tutorial) and populate it with the map file
-Go through the 2d array element by element, and depending on what it contains (presumably a # between 0 and 250), draw it using Pic.Draw and your tiles array (something along the lines of: Pic.Draw(mapTile(map(x, y))...)
do you see what's happening? you loaded the map into an 2d array (hence the map(x,y)), and whatever value it contained is being used to decide which tile to draw in the mapTile array).
hope that helps.
SNIPERDUDE
Posted: Fri Oct 13, 2006 2:34 pm Post subject: (No subject)
related...
What if you want to load a larger map, but display only a portion of it. So when I move left or right the displayed portion of the map moves. How would you accomplish this?