Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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 1549 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 »

http://www.gamedev.net/reference/articles/article934.asp

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
GameLizard.com
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:
XX-
X--
---
2 - Terrain is used to TOP RIGHT. Draw diagonal:
-XX
--X
---
3 - Terrain is used TOP (we are a bottom edge)
XXX
XXX
----
4 - Terrain is used bottom left:
---
X--
XX-
5 - Terrain is used to our LEFT. Draw right edge of terrain
XX-
XX-
XX-
6 - Terrain used bottom left and top right. Draw wierd connector bit:
-XX
XXX
XX-
7 - terrain used All around (inside-L junction):
XXX
XXX
XX-
8 - terrain used bottom right:
---
--X
-XX

etc.
etc.

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:
XXX
X-X
XXX

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
etc.

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
AND:
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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!