Map Concept

Started by
3 comments, last by MeEatCows 22 years, 10 months ago
I would like to start this post off by saying that this is the first time I’ve actually dealt with maps saved on a computer and also the first time I’ve attempted to do animated tiles in a game. I’m writing this post to try and find out if my ideas from how to handle these two things are all right or if they are stupid. I’d also like to know what you would recommend I do if these ideas wouldn’t work. My ideas for how to handle maps and animated tiles in a 2D tile based game are as follows. My idea on how to save my map information is to use a DLL. I’d have a global array in the DLL that holds the information about the section of the map that’s currently loaded. Before I say how I would fill this array I first need to say a little bit about the map editor. I’d have the map editor take the map then split it into section and naming them off with the letter x followed by the number of sections from the left side of the map that that section is and then that would be followed up by y and then the number of sections the section is down. For an example of this let’s say each section is 5 tiles wide by 5 tiles in height. 1111122222 1111122222 1111122222 1111122222 1111122222 2222233333 2222233333 2222233333 2222233333 2222233333 (This font that this web page uses by default doesn’t have a constant width for each character so the text came out looking longer than it is wide) Ok each character would be information about a tile. This would be one all one map made in the map editor. My map editor would take 5 by 5 sections of this and putting all the information in an array and then putting that array into a function. The function name would be as describe as above. In my map example all the ones would be in an array stored in a function called x0y0. The twos on the top row would be stored in an array in a function named x1y0. The twos in the second row would be saved in an array in a function named x0y1 and the threes would be in a function named x1y1. Each of these functions when called would copy their data into the global array that holds the information about the part of the map that is currently showing. The xXyX functions would be called from the game when the user moves around the map. When the game goes to draw the map out it will call a function in the DLL that gets the information for the tile in the X and Y position of the current part of the map that’s loaded up. Ok well the map editor would make all of these functions and stuff and then save them out to a .CPP file. Then the map editor will call a compiler and pass all of the correct information so that the map ends up being a DLL file with all the functions needed to access the information about the map. Why do I think that I want to do it this way? I had different ideas on how to do this and I ended up picking this one for a number of reasons. The main reason for me picking to use this idea is because of security. This makes it so that the average Joe couldn’t change the information about the map. This is still just my idea I didn’t begin to implement this idea or anything yet. I’m sure its deeply flawed but it’s just my idea and I wanted to see what other more experienced people would think about an idea like this. Next Idea Ok this is what I thought up for knowing when to change the tiles to draw so that my game changes the tiles on the screen when they need to be so that is becomes animated. My idea is all based upon time. With my idea my game’s main loop would call an update function every second or so. This function would check to see if there are any animated tiles that are stored on screen currently (this would be saved in a BOOL) and if there are animated tiles on the part of the screen that is currently showing then it will check to see the time of the clock, the last time it was changed and how often the thing should wait before changing the tile. If the current time – last time it was changed > tile to wait before changing then change the tile number to draw so that the render function renders the other tile. This would then set a BOOL to true saying that the map needs to be redrawn because it’s been changed. This function would loop and do the same for all the animated tiles in the part of the map that’s loaded up. All right well those are the ideas that I had to handle these two things. They may not be the best but this is my first game. Please give me feed back about them. I’d like to know if you think they would be to slow or if you see any flaws in them that I’m missing. If you know of any better ways to do it or if my ideas are just the worst ideas on how to do this that you’ve ever heard please tell me a URL or information about a better way. Well thanks for reading this post please give me feedback.
Advertisement
quote:Original post by MeEatCows
My idea on how to save my map information is to use a DLL.


Red flag: you''re thinking about the physical layout of your data structures before defining what the data structures are. You might be getting ahead of yourself.

quote:
My map editor would take 5 by 5 sections of this and putting all the information in an array and then putting that array into a function. The function name would be as describe as above. In my map example all the ones would be in an array stored in a function called x0y0.

I''m not totally sure about your setup, but it sounds like you''re saying that you''re going to have to write as many functions in your map routines as there are tiles visible on the screen? This is a really bad idea, and will make looping through your rendering code impossible.

Whatever data you have in each cell of your map, why don''t you return that data relative to the x and y index as arguments of a function? e.g.
const CellData * getCell (int x, int y);

quote:
Ok well the map editor would make all of these functions and stuff and then save them out to a .CPP file. Then the map editor will call a compiler and pass all of the correct information so that the map ends up being a DLL file with all the functions needed to access the information about the map.

You say you want to do this for security reasons, ok. First, you should know that having a "compiled image" of a map would probably get you the exact same thing as adding the map data as a resource into your executable. Furthermore, a dedicated hacker will still be able to change things just as easily. But most importantly: the ability to change/create maps for a game is one of the most attractive aspects for modern games (quake, starcraft, etc.)

As for your idea on animating, it''s a little too general to say if anything''s right or wrong with it. Having a switch that defines whether or not there are any animated tiles is probably a waste--it''d be as efficient or better to have a list of which tiles are animated and their positions, just iterate through that in your animation loop. But generally, yes you have a timer running at your animation frame period and update all your animations when that timer expires.

Careful not to bite off more than you can chew. I''d suggest get a good working game up before worrying about hiding information from hackers, and definitely get the map working before shooting for animation.
What I do when passing map info through files is just make it a load of numbers. Say, first number be the total number of certain squares, then all of the x co-ords for that type of square, then y co-ords, and repeat this process for different types of squares, with a marker at the start of each. This means that , although practically unreadable to you, you can have a load_map() function which loads the data into arrays in the exact same order as it was written, forturnately computers are hard to confuse (ok I guess Im really wrong here but never mind). So, say you have 10 rock tiles, at different parts of a map, first load the number 10, then load each of the rock x co-ords, then for the y co-ords. Then load the number of grass, 5, then all the x co-ords and y co-ords. On the other end, reading the file, you just have to make the code something like:

load_map
read first num, put in countrock
do a for loop countrock times, loading into an arrayx
" " " " " " arrayy
read num, put in countgrass
etc etc

its not really security proof, but I usually give my map editors away with any games I make anyway.
I got my ideas sorted out. In my map idea it was going to save a file holding all the information about each tile right... then when you converted it with another program so that you could use it with the game it would split the map up into sections of screen. so for example you have a 1000x1000 map right, it would split it up into sections of 500x500 (for example). The information in this 500x500 chunk would be saved as an array in a function named the x and y position of that chunk. All of that would be generated into C++ code and put into a CPP file. The thing would also include an array pointer that would have held the information of that section of the map. As you move it would load up the new Sections (not tiles) of map.

This is the first time I was going to actually make a game that even needs a map file so I''m sure the idea wasnt good. I talked it over on irc and decided to save the chunks of the map into each text file and load each file as needed. I have a better idea of what I''m doing now. I also talked about my animated tile way and it was ok. Thanks for the feedback
I''d like to also add that I''m not to new with making games. I know how to load files and I also know how to take things from an array and display stuff on them. Can have stuff move and all I''ve just always used static tiles... water that wouldnt move and so on. Now I am trying to move into making the games look a little bit better and also allowing to make maps. Those were just some ideas that I was writing down before I begin work on the game. I always like to have a nice outline of the game and how I''m planning on setting this written down before I begin.

This topic is closed to new replies.

Advertisement