Hi,
does someone has a good tutorial or example of how to make a tile based game.
(rts kinda way like red alert).
I have been searching for more then a hour but didn’t found any good.
I don’t want to use any library.
plz help
Hi,
does someone has a good tutorial or example of how to make a tile based game.
(rts kinda way like red alert).
I have been searching for more then a hour but didn’t found any good.
I don’t want to use any library.
plz help
well its a broad topic
you basically have an 2-dimensional array of fields/images/textures/tiles/whatever (per layer) used in an Orthographic or isometric fashion.
I don’t know of any tutorial in particular but I liked the section in “Developing Games in Java” by David Brackeen in which this is covered.
Although it requires a little more knowledge and work. Sometimes if you really cant find a “java tutorial” look for a tutorial in similar languages, like C# has a similar syntax to Java. Aside from the rendering and audio aspect, a lot of the game logic will be extremely similar between many different languages.
Though a tile based game, like Cero said can be a broad topic.
Depending on how complicated your system or game is to be. Id personally recommend a simple 2D array containing the terrain, with identification of whats buildable terrain or not. Then simply have an arraylist of all your buildings locations, and 1 more list(or could be combined with the buildings one) to contain all your units. Depending on how you want to handle it.
Also, you may not find a good tutorial, try just look for source code and examine how other people have done similiar things.
Terrain is probably the least complicated part. Many start with that, because well, it’s an obvious thing to start with. But without units moving on that terrain you don’t have much of a game. Unit movement is probably more important, because it’s difficult to implement. Jeeps, tanks, soldiers, etc. how are you going to add that so it’s convincing like Red Alert?
Unit behavior, movement, AI, physics, pathfinding, etc. is very important.
As other posters suggested, start with a simple 2D array for your terrain and show a character moving about in a ‘roguelike’ style.
I would forget the ‘rts’ portion for now. Creating the interface, drawing the graphics, and moving the camera about is a much more complicated task and even if you know what you’re doing, it will likely take months to create something that even rudimentary (think boxes and rectangles instead of any graphics) resembles a RTS.
I like to use a 3D array, where the 3rd dimension is different rendering/logic layers. Alternatively, you can represent this in multiple 2D arrays, which I’ll lay out here because that’s probably a little simpler to understand.
//Contains pathing data, information about doors, switches, etc.
private int[][] logicGrid;
//Contains sprites that get rendered beneath the player. Might have null spaces.
private Sprite[][] backgroundSprites;
//Contains sprites that get rendered on top of the player. Might have null spaces.
private Sprite[][] foregroundSprites;
//Contains all the active entities that move around. Units, land mines, etc.
private ArrayList entities;
public static final int GRID_EMPTY = 0;
public static final int GRID_WALL = 1;
public static final int GRID_LAVA = 2;
public static final int GRID_SWITCH = 3;
//etc.
public boolean canMoveTo(int x, int y)
{
return (logicGrid[x][y] == GRID_EMPTY);
}
Well, Somnium has two articles covering a simple tile based game, Felix. You can find it here: somnium.dk/blog
While it doesn’t go in depth with how the low-level code works, it’s commented nicely so it should be easy to figure out. It comes with different tiles, animation and collisions (as far as I remember).