Orthogonal Map Issues

Hi Community,

this is my first post here and my first attempt to programm something in Java.

Okay straight to the problem. I develop a TileEditor and its working so far with drawing/erasing tiles, saving/loading them. But the structure is not enough for later.
At the moment i have an int[X][Y][L] map. (L = layer)

But i want to add later on status to the tiles like are they walkable or not. Are there any events on the tiles. Extra informations.

Any suggestion how to build up the class structures for that?
I thought about Map->Layer->Tile->Event. Map would be the biggest class which holds the layer. The layer holds the Tile and a tile has always an event. In the tile object i would save the status like walkable/blocking…
But how do i add objects to the map[][]?
Would you recommend saving the layer information in the tile object as well as the event object? Or should i seperate those?

Many questions so far, hope you can give me some hints.
Pls take it easy, iam new and english isnt my motherlanguage.

regards,
Freygeist

Hi Freygeist and welcome to JGO.

I would recommend storing all the information about a given tile in its own class. For example:


class Tile {
  boolean: walkable;
  char: glyph;
  Color: color;
  etc...
}

Then you instantiate all your tiles and store them in a 2D array. Note that this naive approach is somewhat wasteful in regards to memory but Java programs usually have lots to play with.

Thx for the fast reply.

But where would you store the layer information? I want flexible layer where i can draw my tiles on. So like: 1 layer = ground details, 2 layer = more ground details, 3 layer = environment.

regards,
Freygeist.

I’ll need more information in exactly what you want to store in a layer.

There are many ways to do this. For example if your tile was a base of dirt, with a corner patch of grass, and a shrubbery on top, you could store this in a List[dirt, grass-NE-corner, shrubbery].

What do you have explicit layers? Do you have a need to treat the entire layer in a special way i.e. Photoshop layers?

Okay i try to be more specific.

Maybe from scratch:

I need a map with x and y coordinates. Additional i want flexible layers on top of every tile. (no explicit layers) The user of the editor should define what is on the layer. Jeah like photoshop. Only the images should be on the layer.

Then i need informations like walkable/blockable and a possible place for events on every tile (not every tile has a event). Events should be stuff like triggers.(for example a chest which opens and changes its tile picture when i hit it).

Btw thank you for your patience! :slight_smile:

Freygeist

A layer almost by definition is going to be an entire grid of tiles, and all the map code I’ve seen just has a list of layers, making any 2d map more or less a 3d one. If you’re going to populate every cell with a value, you may as well just use explicit and separate layers.

If you want to arbitrarily stack things on certain tiles, then instead of having a list of layers that has a 2d grid of map cells that contain one tile each, you can have a single layer that contains a grid of map cells that contains a list of tiles each (or maybe a Map<Layer,Tile> depending on what you need).

And there’s no reason you couldn’t mix and match both approaches in a single map containing both single-tile layers and multi-tile layers. A method like TileMap.getTiles(Layer layers, int x, int y) would work no matter which you used, since it could delegate to the layer to decide how to get the list of tiles.

Okay thx now i got some ideas.
I want to stack “arbitrarily”(difficult word for me but LEO makes it understandable :D) images on cells.

I think i got 80% of your post but the rest is a bit to abstract for me. Would it be possible for you to show me some pseudocode and describe an approach?
I dont need “the only one” approach.

During your posts i try my own approach. If i get something solid i will post it here.