Reading .TXT RPG "Maps" and tiling them correctly.
Author |
Message |
MiX-MaztA-M8riX
|
Posted: Mon Sep 19, 2005 5:15 pm Post subject: Reading .TXT RPG "Maps" and tiling them correctly. |
|
|
I've got the proggy to identify the tiles and stuff.. like 1 = land, 3 = water, stuff like that....
but how can I get it to draw the pictures normally? instead of on top of eachother everytime? Im stumped, any help would be greatly appreciated |
|
|
|
|
|
Sponsor Sponsor
|
|
|
beard0
|
Posted: Mon Sep 19, 2005 5:33 pm Post subject: (No subject) |
|
|
Please be more specific and post some code, then we can help. |
|
|
|
|
|
MiX-MaztA-M8riX
|
Posted: Mon Sep 19, 2005 5:39 pm Post subject: (No subject) |
|
|
sorry aboot that
code: |
var Gotten : array 1 .. 140 of string
var fNum : int
open : fNum, "City.txt", get
var x : int := 1
var LocX, LocY : int := 1
var pic1, pic2, pic3, pic4 : int
pic1 := Pic.FileNew ("0.jpg")
pic2 := Pic.FileNew ("1.jpg")
pic3 := Pic.FileNew ("3.jpg")
pic4 := Pic.FileNew ("4.jpg")
for i : 1 .. 140
get : fNum, Gotten (i)
end for
loop
if Gotten (x) = "0"
then
Pic.Draw (pic1, LocX, LocY, picCopy)
elsif Gotten (x) = "1"
then
Pic.Draw (pic2, LocX, LocY, picCopy)
elsif Gotten (x) = "3"
then
Pic.Draw (pic3, LocX, LocY, picCopy)
elsif Gotten (x) = "4"
then
Pic.Draw (pic4, LocX, LocY, picCopy)
end if
Input.Pause
x += 1
end loop
|
I know the LocX and LocY are always the same.. but how would I make it so it draws ten tiles from left to right, and goes down a row, then does it again |
|
|
|
|
|
beard0
|
Posted: Mon Sep 19, 2005 5:51 pm Post subject: (No subject) |
|
|
Try playing around with this a bit, and figure out how it's doing it:
Turing: | const rows := 10 %Replace these with the right numbers
const cols := 14 %Replace these with the right numbers
const rowHeight := 40 %Replace these with the right numbers
const colWidth := 40 %Replace these with the right numbers
var Gotten : array 1 .. rows, 1 .. cols of int
var fNum : int
var pic : array 1 .. 4 of int
for i : 1 .. upper (pic )
pic (i ) := Pic.FileNew (intstr (i ) + ".jpg") % Rename your files to make this work
end for
open : fNum, "City.txt", get
for r : 1 .. rows
for c : 1 .. cols
get : fNum, Gotten (r, c )
end for
end for
close : fNum
for r : 1 .. rows
for c : 1 .. cols
Pic.Draw (pic (Gotten (r, c )), 0 + (c - 1) * colWidth, 0 + (r - 1) * rowHeight, picCopy)
Input.Pause
end for
end for |
|
|
|
|
|
|
MiX-MaztA-M8riX
|
Posted: Mon Sep 19, 2005 6:14 pm Post subject: (No subject) |
|
|
wow, confusing enough? I got something thats working well for me...
code: |
setscreen ("graphics:max;max,nobuttonbar")
var Gotten : array 1 .. 150 of string
var fNum : int
open : fNum, "City.txt", get
var x : int := 1
var LocX, LocY : int := 1
var pic1, pic2, pic3, pic4 : int
pic1 := Pic.FileNew ("0.jpg")
pic2 := Pic.FileNew ("1.jpg")
pic3 := Pic.FileNew ("3.jpg")
pic4 := Pic.FileNew ("4.jpg")
for i : 1 .. 150
get : fNum, Gotten (i)
end for
for a : 1 .. 10
for i : 1 .. 15
if Gotten (x) = "0"
then
Pic.Draw (pic1, LocX, LocY, picCopy)
elsif Gotten (x) = "1"
then
Pic.Draw (pic2, LocX, LocY, picCopy)
elsif Gotten (x) = "3"
then
Pic.Draw (pic3, LocX, LocY, picCopy)
elsif Gotten (x) = "4"
then
Pic.Draw (pic4, LocX, LocY, picCopy)
end if
x += 1
LocX += 50
end for
LocY += 50
LocX := 1
end for
|
it works pretty well ^_^ thx for the help.. but I'm not 1337 enough to fully understand your version |
|
|
|
|
|
Carino
|
Posted: Mon Sep 19, 2005 6:26 pm Post subject: (No subject) |
|
|
Its simple really if you understand 2D Arrays. All you do is load the map from the file say into an array called map[rows,columns] So from there all your coordinates are stored such as 1 = land, 2 = water, etc. Then you write a simple algorithm to draw the map such as:
code: |
for i : 1..numberOfRows
for o : 1..numberOfColumns
if map(o,i) = 1 then
drawfillbox (o * mapSize - mapSize, maxy - (i * mapSize), o * mapSize, maxy - (i * mapSize) + mapSize, green)%taken from my own so dont mind the variables
elsif map(o,i) = 2 then
drawfillbox (o * mapSize - mapSize, maxy - (i * mapSize), o * mapSize, maxy - (i * mapSize) + mapSize, blue)
end if
end for
end for
|
Its easy once you ge the hang of it. |
|
|
|
|
|
MiX-MaztA-M8riX
|
|
|
|
|
beard0
|
Posted: Mon Sep 19, 2005 6:56 pm Post subject: (No subject) |
|
|
Well, you're not using the number 2, so unless you're planning on adding it soon, you should really use either 0-3, or 1-4. You really shouldn't have that 2 in the middle doing nothing. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|