emerald icon indicating copy to clipboard operation
emerald copied to clipboard

Tilemap Component

Open Bombfuse opened this issue 3 years ago • 2 comments

Tilemaps are an essential feature for many engines, Emerald needs an easy to use Tilemap component.

This tilemap should be easy to use directly, and easy to wrap over it.

let mut tilemap = Tilemap::builder()
.with_size() // Default: Vector2(100, 100)
.with_tileset() // Default: Default texture
.with_tilesize() // Default: Vector2(32, 32)
.with_spacer() // Default: Vector2(0, 0)
.build();


// Set the tile at 0,0 to the tile of index 1 in the tileset
tilemap.set_tile(Vector2::new(0, 0), 1);

Bombfuse avatar Jan 02 '21 20:01 Bombfuse

i would do it something like this:

let mut Tilemap::new(
    tileset: Tileset, // textures
    chunk_size: u8, // size of each chunk
    tilesize: u8,
    spacer: Vector2:new(0, 0)
);

tilemap.set_tile(Vector2::new(100, 2), 1) / /set a tile

and internally storing the chunks in memory in a hash map of the chunks Vector2 and an struct with chunk data itself, and store additional data (such as contents of chest in that chunk) in that chunk struct as well.

Also making the tiles an enum with the options TileWithData (Tile with extra data such as chests, traps, etc) and Tile (tiles such as grass with no special properties), this would make it much nicer to add stuff like height and tiles the player can't walk over or has to swim thru.

Chunks can also be serialized quite easily, making multiplayer stuff much easier. Also storing chunk data like that is pretty easy.

Tile resources could also be loaded like this:

let tileset = TileSet::from_dir("./conf/tiles/");  // loads all the toml files in the dir which contain the general data and position of the images

maps themselves should also be loadable like this.

MilimTheTrueOne avatar Jan 07 '22 09:01 MilimTheTrueOne

Another good question to ask is whether or not Tilemaps should have physics bodies. In Godot, you can define whether or not a tile has a physical shape, and you can use it to build Ground/Walls/etc, and it's extremely useful.

A tilemaps physical body would be hidden behind the physics feature flag.

Bombfuse avatar Jan 07 '22 16:01 Bombfuse