Computer Science Canada Tile Mapping Question |
Author: | romantic_programmer [ Wed Oct 04, 2006 12:44 pm ] |
Post subject: | Tile Mapping Question |
OK, I have 260 tiles... var mapTile : array 0 .. 249 of int %% Null Tile mapTile (0) := Pic.FileNew ("resources/tilesets/null.bmp") %%Main Tiles mapTile (1) := Pic.FileNew ("resources/tilesets/land/land/main/1.bmp") mapTile (2) := Pic.FileNew ("resources/tilesets/land/land/main/2.bmp") Etc.. Now How would i Go about getting this to be displayed. so it will show the mapTiles... here is an ex of my .txt file 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 **I jsut need this so i can start designing levels... |
Author: | romantic_programmer [ Wed Oct 04, 2006 12:45 pm ] |
Post 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... |
Author: | NikG [ Wed Oct 04, 2006 7:16 pm ] | ||
Post 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:
Replace the *15 with however big your tiles are. |
Author: | romantic_programmer [ Thu Oct 05, 2006 9:53 am ] | ||||
Post subject: | |||||
The only problem with
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.
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... |
Author: | do_pete [ Thu Oct 05, 2006 9:56 am ] |
Post 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] |
Author: | romantic_programmer [ Thu Oct 05, 2006 10:15 am ] | ||
Post subject: | |||
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 |
Author: | romantic_programmer [ Thu Oct 05, 2006 10:20 am ] |
Post subject: | |
can some one just dleate this topic... i will figure it out on my own... no point to keep the topic |
Author: | Mazer [ Thu Oct 05, 2006 10:37 am ] | ||||
Post 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:
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:
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. |
Author: | Clayton [ Thu Oct 05, 2006 11:57 am ] | ||||
Post subject: | |||||
things like this make my heart break, instead of doing that, have a loop read from the file instead eg.
This makes it much simpler to read, and takes and uber less amount of time to code ![]() |
Author: | TokenHerbz [ Thu Oct 05, 2006 2:53 pm ] |
Post 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) |
Author: | TokenHerbz [ Thu Oct 05, 2006 3:00 pm ] | ||||||||
Post 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:
we should take a screen shot of our level, so we dont have to use the loops always:
And to draw the map, simply have a proc like this:
and call it:) OverView, the first proc is to change the map, you change the file and vars needed: Ex:
hahaha hows that better? i tend to over do things and the wrong way at that, but it works, so enjoy. |
Author: | romantic_programmer [ Thu Oct 05, 2006 7:07 pm ] |
Post 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.... |
Author: | romantic_programmer [ Fri Oct 06, 2006 11:52 am ] | ||
Post subject: | |||
Ok i am making progress.. here is what i got so far...
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... |
Author: | NikG [ Fri Oct 06, 2006 1:48 pm ] |
Post 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. |
Author: | SNIPERDUDE [ Fri Oct 13, 2006 2:34 pm ] |
Post 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? I hope this made sense. |
Author: | TheOneTrueGod [ Sat Oct 14, 2006 12:44 pm ] |
Post subject: | |
omg... quad post... allright, basically, you just draw what is on-screen. I.E. if SquareX > (x - maxx div 2) and SquareX < (x + maxx div 2) and SquareY ...Etc... then DrawThisSquare end if of course, it all depends on how your co-ordinate system works... so you'll have to adjust accordingly. |
Author: | NikG [ Sun Oct 15, 2006 10:59 pm ] |
Post subject: | |
Well how I handled it in my rts game was to have ViewX and ViewY variables that kept track of where you're looking. Then all I did was check which of my objects were between ViewX +/- 250 and ViewY +/- 200 and drew those only. Let me know if you want an example. |
Author: | SNIPERDUDE [ Mon Oct 16, 2006 6:46 am ] |
Post subject: | |
An example would be great, thanks. |
Author: | NikG [ Mon Feb 05, 2007 8:54 pm ] | ||||
Post subject: | Re: Tile Mapping Question | ||||
Well I had two people asking for a demo of this, so I finally prepared one. (Sorry for the delay guys, I haven't been on CompSci for a while)
That's pretty much it! All you need is absolute positions of your objects and you draw them based on what ViewX and ViewY are. For example, in this case our map size is 1000 by 800 and the view size is 500 (ViewX-250 to ViewX+250) by 400 (ViewY-200 to ViewY+200). So if we want to show an object at location Obj1.x,Obj1.y just check if it's within the ViewX and ViewY ranges:
As I mentioned before I used pretty much this exact code for my RTS Engine, so if you wanna how much you can expand on this, take a look at my game: http://www.compsci.ca/v3/viewtopic.php?t=13063 (Note: I didn't see the download link... pm me if you can't see it either) |
Author: | NikG [ Wed Feb 07, 2007 11:15 pm ] |
Post subject: | Re: Tile Mapping Question |
Hmmm... seems like the downloads for the FPs have been removed. I've attached it here. (Note: no source code is included) |
Author: | SNIPERDUDE [ Thu Feb 08, 2007 10:14 am ] |
Post subject: | Re: Tile Mapping Question |
could you please email it to me? the link seems to be removed... again ![]() |
Author: | romantic_programmer [ Thu Feb 08, 2007 8:37 pm ] |
Post subject: | RE:Tile Mapping Question |
the link isn't removed again lol, and thank you again for the help. |
Author: | SNIPERDUDE [ Fri Feb 09, 2007 9:39 am ] |
Post subject: | Re: Tile Mapping Question |
hmmmm... thats weird, the link only showed up when I logged in. When CompSci emails me about watched topics it doesn't log me in, I clicked on the link from there. |
Author: | CodeMonkey2000 [ Sat Feb 10, 2007 10:36 pm ] |
Post subject: | RE:Tile Mapping Question |
What would be the best way for collision with 2d tiling be for something like mario? |
Author: | ericfourfour [ Sun Feb 11, 2007 1:54 am ] |
Post subject: | RE:Tile Mapping Question |
I personally prefer this algorithm: if nothing is in the way, allow the character to pass. |
Author: | CodeMonkey2000 [ Sun Feb 11, 2007 12:45 pm ] |
Post subject: | RE:Tile Mapping Question |
What would be the best way to detect if something is in the way? Comparing x&y coordinates for you and all the tiles seems like a lot of work. |
Author: | ericfourfour [ Sun Feb 11, 2007 1:05 pm ] |
Post subject: | RE:Tile Mapping Question |
If you want to move left, check if something is blocking the left tile. If you want to move right, check if something is blocking the right tile. I think you get the idea. Every tile has a property that says it is either blocked or not (boolean). You only need to do this for Mario and about three other goombas every frame so it really isn't that much work for the cpu. |
Author: | CodeMonkey2000 [ Sun Feb 11, 2007 3:35 pm ] |
Post subject: | RE:Tile Mapping Question |
So i take my x/y and figure out what tile i'm going to be in and check if it is open? |
Author: | Clayton [ Sun Feb 11, 2007 9:13 pm ] |
Post subject: | Re: Tile Mapping Question |
no. just have a variable or something that keeps track of your current tile position. from there you can check in tiles around you (or even better, in tiles in the direction you are headed) and see if there's a collision. |
Author: | ericfourfour [ Sun Feb 11, 2007 9:50 pm ] |
Post subject: | Re: Tile Mapping Question |
Freakman you said the exact same thing spearmonkey suggested. spearmonkey2000 wrote: i take my x/y
== Freakman wrote: have a variable... ...that keeps track of your current tile position
spearmonkey2000 wrote: figure out what tile i'm going to be in
== Freakman wrote: check... ...[the tile] in the direction you are headed
spearmonkey2000 wrote: check if it is open
== Freakman wrote: see if there's a collision |
Author: | Clayton [ Mon Feb 12, 2007 8:17 am ] |
Post subject: | Re: Tile Mapping Question |
ericfourfour @ Sun Feb 11, 2007 9:50 pm wrote: Freakman you said the exact same thing spearmonkey suggested.
spearmonkey2000 wrote: i take my x/y
== Freakman wrote: have a variable... ...that keeps track of your current tile position
actually no, I didn't. by a variable to keep track of tile position, I mean something other than an x and y variable. Have tiles have values (ie Tile 1, Tile 2 etc) This will make collision much easier because you don't have to deal with all the multiplication and such when you do your collision, instead, it's already been done for you when you created your tiles. I suggest you keep your comments to yourself next time ericfourfour, as your post added nothing to the thread, and I'm going to tell you I took it negatively. |