latebit / latebit-engine

Pixel based game engine integrated in your IDE
3 stars 0 forks source link

Support tile maps #70

Open shikaan opened 5 months ago

shikaan commented 5 months ago

We need some sort of support for tile maps and level editing. Might be something like we do for sprites and sounds with a text-based proprietary format.

Some ideas:

#v0.1#
8 // tile height in pixels
8 // tile width in pixels
32 // map height in tiles
32 // map width in tiles
flowers,sky1,sky2,soil //Comma separated list of sprite-tiles by their label
11111122221111122222111122211111
11111222211112222211111111111111
00000000000000000000000000000000
33333333333333333333333333333333
33333333333333333333333333333333
shikaan commented 1 week ago

Some options to implement tile maps.

1. Entirely declarative

In this case the format would define everything it needs. It would define map and tiles and tiles are expected to be dumb: they would only represent graphical elements, but they would not encode any behaviour (e.g., triggers) or any data (e.g., altitude, terrain type etc). Additional behaviour needs to be added ad additional game objects. It looks very much like the example in the beginning.

Pros:

Cons:

Questions:

2. With missing context

Another idea would be to make maps not declare entirely what they need, but reference a tile map which needs to be provided programmatically

#v0.1#
8 // tile height in pixels
8 // tile width in pixels
32 // map height in tiles
32 // map width in tiles
11111122221111122222111122211111
11111222211112222211111111111111
00000000000000000000000000000000
33333333333333333333333333333333
33333333333333333333333333333333

And this would be parsed like

class Tile : public Object {}

using TileFactory = function<Tile*()>;

MapParser::fromString(string map, vector<TileFactory> tiles);

Pro:

Cons:

3. Something in between

We could have something entirely declarative, data included. Similar to what tiled does.

#v0.1#
8 // tile height in pixels
8 // tile width in pixels
32 // map height in tiles
32 // map width in tiles
#tile definitions#
1: grass 1 # values that map to a struct, e.g. sprite=grass collide=1(=true)
4: bush  0  
#map#
11111122221111122222111122211111
11111222211112222211111111111111
00000000000000000000000000000000
33333333333333333333333333333333
33333333333333333333333333333333

Pros

Cons:

Questions:

shikaan commented 1 week ago

Current idea

#v0.1#
8   # tile height
8   # tile width
10  # width
10  # height
a   # background color
# map
----------
----------
----------
----------
----------
----------
--BBMBBM--
----------
--G-----G-
FFFFFFFFFF
# definitions
B:assets/tiles/block.lbsp;
M:assets/tiles/mystery.lbsp;
G:assets/tiles/goomba.lbsp;10,1;
F:assets/tiles/floor.lbsp;

Decisions:

Trade offs:

Open points:

shikaan commented 1 week ago
#v0.1#
8   # tile height
8   # tile width
10  # width
10  # height
2   # layers (1-4, maps altitude)
a   # background color
# altitude 0
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
----B0B0M0B0B0M1----
--------------------
--------------------
FlFlFlFlFlFlFlFlFlFl
# altitude 1
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
----G0-----G0-------
--------------------
# definitions
# Mystery Boxes
M0:10;
M1:100;
# Goombas
G0:10,1;

Further iteration:

Tradeoffs:

shikaan commented 3 days ago

We should probably also do something about using a tilemap. The current workaround is to have all the tiles on the same line (in the png case) and something like

  RM.loadImageSprite("assets/tileset.png", "tile", 92, STOP_ANIMATION_SLOWDOWN);

But there are a few things we don't need here: