
-----------------------------------
Kingnoz
Sun Aug 03, 2003 7:55 pm

map tiles-drawing several small grass tiles etc
-----------------------------------
k what i am doing is making a rts style game with several different tiles to form the map kinda like how it is in warcraft and starcraft etc.

setscreen ( "graphics:1024;700,offscreenonly") 
%for a file that is in the same dir as your Turing code                                                                                                                    
var mypic :int := Pic.FileNew ("Grasstile.bmp") 
%to draw the picture in the center of the screen with no mode 
Pic.Draw (mypic, 10, 0, 0) 
Pic.Draw (mypic, 20, 0, 0)
Pic.Draw (mypic, 30, 0, 0)
Pic.Draw (mypic, 40, 0, 0)
Pic.Draw (mypic, 50, 0, 0)
Pic.Draw (mypic, 60, 0, 0)
Pic.Draw (mypic, 70, 0, 0)
Pic.Draw (mypic, 80, 0, 0)
Pic.Draw (mypic, 90, 0, 0)
Pic.Draw (mypic, 100, 0, 0)
Pic.Draw (mypic, 110, 0, 0)
Pic.Draw (mypic, 120, 0, 0)
Pic.Draw (mypic, 130, 0, 0)
Pic.Draw (mypic, 140, 0, 0)
Pic.Draw (mypic, 150, 0, 0)
Pic.Draw (mypic, 160, 0, 0)
Pic.Draw (mypic, 170, 0, 0)
Pic.Draw (mypic, 180, 0, 0)


i was wondering if there is a simpler way to write this instead of writing all that code, which i posted above,

-----------------------------------
Kingnoz
Sun Aug 03, 2003 8:15 pm


-----------------------------------
darkness maybe u could help cuz ur way of building a tile map worked great

-----------------------------------
SilverSprite
Sun Aug 03, 2003 9:35 pm


-----------------------------------
do something like this

var grid:array 1..10,1..10 of int  /*store the values according to your map*/

for i:1..10
   for j:1..10
     if grid(i,j) = 0 then
         draw picture at tileWidth*i, tileHeight*j, tileWidth*i + tileWidth, tileHeight*j + tileHeight
     elsif ................
..............
..........
   end for
end for


you get the picture

-----------------------------------
Kingnoz
Sun Aug 03, 2003 10:23 pm


-----------------------------------
could u plz do a small example of 5 tiles by 5 tiles...i don't quite fully understand

the dimensions of the tiles will be 10pixels by 10 pixels

-----------------------------------
PaddyLong
Sun Aug 03, 2003 11:14 pm


-----------------------------------
ok so some explanation ....
the grid array keeps track of what is in each tile ... so if it's set to 0 then we'll say that is empty.  if it is set to like 5 then let's say that means there's a guy in that square ... you can make up the key however you want

then the second set of for loops just go through and check each square and if it is set to 0 (meaning there is nothing in that square) then it draws the grassTile image ... you will need to add more to that if statement to check for each of the keys that you have (as explained above)


var grid : array 1 .. 5, 1 .. 5 of int
var grassTile : int := Pic.FileNew ("Grasstiles.JPG")

for i : 1 .. 5
    for j : 1 .. 5
        grid (i, j) := 0
    end for
end for

for i : 1 .. 5
    for j : 1 .. 5
        if grid (i, j) = 0 then
            Pic.Draw (grassTile, (i - 1) * 10, (j - 1) * 10, picCopy)
        end if
    end for
end for


-----------------------------------
SilverSprite
Sun Aug 03, 2003 11:36 pm


-----------------------------------

/*yep i was too lazy to do that.. it doesnt matter.. you just get it to be 10 pixels up and 10 pixels to the right*/

var mouseX, mouseY, mouseButton : int
var grassPic := Pic.FileNew ("grass.jpg")
var grid : array 1 .. 10, 1 .. 10 of int

procedure drawMap
    for i : 1 .. 10
        for j : 1 .. 10
            if grid (j, i) = 1 then
                Pic.Draw (grassPic, 10 * (j - 1), 10 * (i - 1), picMerge)
            end if
        end for
    end for
end drawMap

for i : 1 .. 10
    for j : 1 .. 10
        grid (j, i) := 0
    end for
end for

drawfillbox (0, 0, 100, 100, 7)
loop
    mousewhere (mouseX, mouseY, mouseButton)
    if mouseButton = 1 and mouseX = 0 and mouseY >= 0 and mouseY  0 and mouseY >0 and mouseY < 300 then
        grid (mouseX div 10 + 1, mouseY div 10 + 1) := 1
        drawfillbox (0, 0, 300, 300, 7)
        drawMap
    end if
    View.Update
end loop
View.Set ("nooffscreenonly")
better with view.update

-----------------------------------
SilverSprite
Mon Aug 04, 2003 12:17 am


-----------------------------------
+18 bits to bugz

-----------------------------------
Kingnoz
Mon Aug 04, 2003 12:33 am


-----------------------------------
+10 bits for ur map editor example
