-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
_modules/github.com/korlibs/korge-ext/korma-tile-matching/korma-tile-matching.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.