Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 map tiles-drawing several small grass tiles etc
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kingnoz




PostPosted: Sun Aug 03, 2003 7:55 pm   Post subject: 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.

code:
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,
Sponsor
Sponsor
Sponsor
sponsor
Kingnoz




PostPosted: Sun Aug 03, 2003 8:15 pm   Post subject: (No subject)

darkness maybe u could help cuz ur way of building a tile map worked great
SilverSprite




PostPosted: Sun Aug 03, 2003 9:35 pm   Post subject: (No subject)

do something like this
code:

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




PostPosted: Sun Aug 03, 2003 10:23 pm   Post subject: (No subject)

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



Grasstiles.JPG
 Description:
 Filesize:  678 Bytes
 Viewed:  4634 Time(s)

Grasstiles.JPG


PaddyLong




PostPosted: Sun Aug 03, 2003 11:14 pm   Post subject: (No subject)

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)

code:

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




PostPosted: Sun Aug 03, 2003 11:36 pm   Post subject: (No subject)

code:

/*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 <= 100 and mouseX >= 0 and mouseY >= 0 and mouseY <= 100 then
        grid (mouseX div 10+1, mouseY div 10+1) := 1
        drawfillbox (0, 0, 100, 100, 7)
        drawMap
    end if
end loop
[/code]
SilverSprite




PostPosted: Sun Aug 03, 2003 11:37 pm   Post subject: (No subject)

MINES NICE RazzRazz
Kingnoz




PostPosted: Sun Aug 03, 2003 11:39 pm   Post subject: (No subject)

thanks for ur help silversprite and paddylong

silversprite ur example would work really neat for a map editor Very Happy
Sponsor
Sponsor
Sponsor
sponsor
SilverSprite




PostPosted: Mon Aug 04, 2003 12:16 am   Post subject: (No subject)

code:

View.Set ("offscreenonly")
var mouseX, mouseY, mouseButton : int
var grassPic := Pic.FileNew ("grass.jpg")
var grid : array 1 .. 30, 1 .. 30 of int

procedure drawMap
    for i : 1 .. 30
        for j : 1 .. 30
            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 .. 30
    for j : 1 .. 30
        grid (j, i) := 0
    end for
end for

drawfillbox (0, 0, 300, 300, 7)
loop
    mousewhere (mouseX, mouseY, mouseButton)
    if mouseButton = 1 and mouseX < 300 and mouseX > 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




PostPosted: Mon Aug 04, 2003 12:17 am   Post subject: (No subject)

+18 bits to bugz
Kingnoz




PostPosted: Mon Aug 04, 2003 12:33 am   Post subject: (No subject)

+10 bits for ur map editor example
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: