Sign in to follow this  

Help with RTS/Tile Map questions:

This topic is 2851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, I'm working on an RTS and have the selection box class written so far. What I want to do is start working on the Map class, because it is so important in determining what pieces of the map already have structures/environment on them to prevent building, traversing, etc. What I need help with is coming up with a good node (or map cell) size to use. EDIT -- Never specified, but I want traditional overhead view, no isometric or layered isometric. I have so many questions, which is why my notebook is just being filled with crossed-out scrap and I'm making no progress: 1) How big should I make a single map cell (or node)? Am I forced to make each building and unit equal size to a single map cell? I'd rather not have the map look "grid-like" (see question 3) 2) If I want extra big or extra small objects to occupy the map, how can I do this? -- I may want a building that is so big it takes up 2 (vert or horiz) nodes or maybe a square 4-node piece of the map. 3) How can I handle unit movement over nodes? -- I want to try my best to "eliminate the grid", meaning I don't want the game to look so blocky. If a unit is smaller than a map node, I'd obviously want to be able to get 2 or more units in that area. I'd rather allow building creation anywhere within available nodes, not just starting from the top-left corner of a node and completely filling the nodes. If you can help me with this stuff it would at least bring me to the point where I can create some sensible pseudo-code, because right now I'm lost completely in how this is done. P.S- I'm working with pygame, but it shouldn't make much of a difference regardless. Thanks!

Share this post


Link to post
Share on other sites
1). No you are not limited to making tiles a specific size. Though the technological design might get a little harder. As for size, it really depends on the scale of things in your world. You could use an approach of multiple sized tiles that can be put together to form a map if you wanted, or stick with a specific size; 32x32 or whatever you choose. I would recommend making your units/tiles a bit bigger, to allow zooming and still looking good - obviously don't get carried away.

2). Like stated above, you can make different sized tiles, I don't know the algorithm off the top of my head and would need to do some research/designing of an algorithm to do so; but basically if 32x32 is your tile size, then you could place multiple tiles as a single tile. Same goes with buildings. You don't need to place buildings on the tiles directly either, you may have to check multiple ground tiles to be sure the building is place-able though. So for a building the size of 1 tile, at worst case you would have to check 4 tiles to be able to place it.

Also you can do this with an L shaped building (two down, one to the right), just need to check all the building tiles against all the ground tiles they overlap. Using some form of bit field can allow you to have more precise positioning, since 1 tile that is half/half allowing something to be built on will by default fail - by checking some collision map for the tile could allow less tile like placement.

3). This would have everything to do with your AI system, and as I said above having some sort of collision system that allows tiles to be broken up into smaller pieces; by using a greyscale image for each tile you can control directly where collisions happen and where they don't allowing higher precision, less grid-like feel. As for getting 2 units into the same area that would be based again on your AI system as it handles moving/positioning of units. Flocking/Formations may be of interest, since these can allow a group of units to stay together.

I hope this helps, happy programming.

Share this post


Link to post
Share on other sites
Just because you're using a tilemap for the visual aspects of the map doesn't mean you also need to use a grid for your logic. The same goes the other way around.

Now, working with tiles and cells does make a lot of things easier, with the trade-off that everything is more blocky (visuals, movement, building placement). It's up to you to decide if the added complexity of free-form movement and building placement is worth the extra effort, but if you're already having trouble figuring things out at this stage, I would advice sticking to tiles and grids. It's going to be more blocky, but you'll have an easier time getting it to work.


You could pick a small tile-size and have every unit and building occupy multiple tiles. Or you could pick a tile-size that suits most units, and make every unit occupy one tile at a time. That'll probably make unit movement easier to handle.

Now, underneath all that, you'll want to keep track of what tile is walkable. A grid of booleans could do: buildings and units would then mark the tiles they occupies as unwalkable. You could also make that a grid of references: None would indicate walkable tiles, while a reference to a unit or building would indicate an occupied tile, and would quickly tell you what units and buildings occupy those tiles too. When selecting units, just check what tiles your selection rectangle covers, and check those references. Filter out the double references (for units/buildings that occupy multiple tiles) and you've got your list of selected units and buildings.

As for small units, the way Command & Conquer did it was to allow 5 soldiers on a single tile. You could do the same by giving a tile multiple slots for smaller units.

Share this post


Link to post
Share on other sites

This topic is 2851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this