Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (611)
Games in Android Showcase (172)
games submitted by our members
Games in WIP (658)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Help making my first tile-based game.  (Read 1675 times)
0 Members and 1 Guest are viewing this topic.
Offline jamdr

Senior Newbie

Java games rock!

« Posted 2004-11-01 23:32:40 »

I'm not exactly "newless" when it comes to creating Java games, but since I've never done this type of game, my techniques are probably not the best. The game I'm currently working on is tile-based--it will probably end up being a Rogue-like dungeon exploration game. But all I'm doing now is creating the map engine that loads the level data from a file and draws it to the screen. I have a few questions at this point:

1. What is the best way to store level data? There will probably be several thousand tiles in each level when they are done, so I don't want it take up a whole lot of space.

2. Terrain transitions. How do I deal with these? Right now I only have two terrain types--grass and water, but I expect to have 9-10 when I'm finished. I read some tutorial online that explained how to make the graphics (using transparent transitions and assigning each terrain a priority), but I still don't really understand how I'm supposed to draw them. There are 32 transitions tiles--how do I determine which one to draw?
Offline Malohkan

Senior Devvie

while (true) System.out.println("WOO!!!!");

« Reply #1 - Posted 2004-11-02 01:56:24 »

That article should answer most of your questions.  It's the best resource I've ever found for what you're asking for.  Good luck with it!

Admin and Game Developer at
Play Rimscape!    |    Play Conquer!
Offline crystalsquid

Junior Devvie

... Boing ...

« Reply #2 - Posted 2004-11-02 09:12:53 »

1) A 2D array is the standard way.
Each 'cell' of the array needs to hold the basic terrain texture, and maybe a reference to any contained objects in case something is in there.
Additional info may include connectivity info - i.e. whether ytou can move up/down/left/right from this cell.

2) For multiple terrain types that can overlay, you really need to have 'edge' tiles that cover half of a tile. You draw these up from the base.

There are several ways to order these, but the most effiecient I have found is this (only uses 16 transition tiles):

The terrain types are defined for THE TOP LEFT CORNER of a tile. A tile also has a base texture that is the terrain for the middle, but this is not used to draw edges. (There are many other methods but this way lets you use just 8 tiles easily)

To work out what overlay you need, you check if each terrain type  is being used on this tile corner and the tiles to your RIGHT, DOWN, and DOWN RIGHT.
then we build a 'tile index':
This tile is bit 0.
if RIGHT tile has same terrain overlay at ITS TL corner, set bit 1.
if DOWN tile uses same, set bit 2,
if DOWN RIGHT, set bit 3.

So the resulting number is:

0 - terrain not used. Draw nothing
1 - Terrain is used top left. Draw diagonal over TL:
2 - Terrain is used to TOP RIGHT. Draw diagonal:
3 - Terrain is used TOP (we are a bottom edge)
4 - Terrain is used bottom left:
5 - Terrain is used to our LEFT. Draw right edge of terrain
6 - Terrain used bottom left and top right. Draw wierd connector bit:
7 - terrain used All around (inside-L junction):
8 - terrain used bottom right:


There are 16 cases culminating in '15' - terrain used all around. Assuming these flags determine edges only if the terrain type is NOT the same as the base terrain, then case 15 is a small 'hole' of the base:

When you build the data for the game, you should use this algorithm to work out what edge pieces you need and store the values in the data. i.e:

Tile x:
Base tile - mud;
Grass Edge: Use grass_edge[12]
Concrete edge - none

This is the same method as used by Warcraft and others for their terrain edges Smiley

This makes determining how to build edges more efficient but the complexity comes in editing the levels. When you want to set a tile to grass (for eaxmple) you actually have to set:

tile base = grass, tile top left.grass = true
neighbour(RIGHT) top_left.grass = true
neighbour(BOTTOM) top_left.grass = true
neighbour(BOTTOM_RIGHT) top_left.grass = true

You must make sure you set the bits on the neighbour tl points too. It is a small amount of eztra complexity but this should only be in the editing phase. The game should only be told what base/layers to draw which you work out from this.

I hope you managed to follow all that!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Roquen (13 views)
2015-08-29 11:30:54

GamerC4 (23 views)
2015-08-22 20:38:50

GamerC4 (22 views)
2015-08-22 20:37:18

GamerC4 (26 views)
2015-08-22 20:37:01

Kefwar (30 views)
2015-08-22 18:07:24

GamerC4 (24 views)
2015-08-22 01:00:24

GamerC4 (37 views)
2015-08-22 01:00:17

GamerC4 (24 views)
2015-08-22 00:57:35

GamerC4 (25 views)
2015-08-22 00:56:59

BurntPizza (30 views)
2015-08-21 01:38:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!