Sign in to follow this  
Roflha

RTS Map Mechanics

Recommended Posts

Hello everybody, I just had a few quick questions, but nothing too specific.

Previously, I have coded a simple galaga-like game and a more in depth platformer. Now I am starting to make an RTS style game as my new project, but the structuring of an RTS already seems to be pretty different than things I have made in the past.

My basic game will be a 2D RTS, with the camera looking down on the battle field from above. You are able to place structure, and structures are the primary defense. You can also produce units, which can be used to attack enemy towers. Really the game is like a mix of an RTS and a versus tower defense game.

I just had a few quick questions about the basic setup for coding (from an object-oriented language).

Right now I have a World class, and the world contains a 2-Dimensional array of shorts that I am using to store the elevation of the terrain at the point represented by the x and y coordinates. Simple enough so far. With my World class, I do not really see what I should do to make units interact correctly with the terrain. I realized I will eventually need to work on path-finding, but I will learn that more when I get to that point.
Questions:
1.) What method would the community suggest for placing unit objects on the map, and having them be aware of the terrain ?
2.) How would I most efficiently have units check for other units? I think that calling some method in the World would get cumbersome with all of that method overhead.
3.) Any other tips from people that have made the game?

Thank you in advance.

Share this post


Link to post
Share on other sites
Shameless bump (since I basically changed the whole question (since nobody was answering before)).

Also, mods, would this topic be better suited for the Game Programming forum? I would make one their but after reading the newcomer rule pinned on here I would rather not. It discouraged "cross topics" or something like that.

Share this post


Link to post
Share on other sites
Well for my rts game I have a terrain class that I made static so I could in my object base class do something like this
Bool unit::addtoterrain()
{
Cell *cell = terrain:: getcell(unitpos);
The do what ever you need to do
}

It my not be the best way but it looks like it works

Share this post


Link to post
Share on other sites
Hmmm, making my World class static could also work I suppose. It isn't like I am going to need more than one of those too terribly often.

So in your case, I assume Cell is another class used to represent a spot on the Terrain? My only concern with that is it would cause a lot of allocation. See, I am making this for Android and iOS (primarily Android), and allocation of object and the ensuing garbage collection are things that I have been looking to avoid.

Ok so what if I did this. I made my World class static and put in a "load" method, or something to that effect. I could pass it the resource ID for the raw file I am using to describe the terrain, and then read that into my 2D array. Would it be awful if a made my array public? I realize that it is not proper encapsulation, but sacrifices must be made on occasion.

Share this post


Link to post
Share on other sites

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