diff options
author | davidovski <david@davidovski.xyz> | 2023-07-11 21:08:27 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-07-11 21:08:27 +0100 |
commit | ebbb6c8b0302589626a594399ec04e3c4555d5f6 (patch) | |
tree | 71a6c489352c58759433f6c1b814a3f3fa63e341 | |
parent | 625cb961a3b35afdaf6d5c1e8bf4966a522a022a (diff) |
do not allow editing tiles outside of the tilemap
-rw-r--r-- | makefile | 11 | ||||
-rw-r--r-- | src/editor.c | 16 | ||||
-rw-r--r-- | src/tiled.c | 4 |
3 files changed, 13 insertions, 18 deletions
@@ -1,17 +1,8 @@ CC=gcc FLAGS=-lm -lraylib -ggdb -.DEFAULT_GOAL := build - -install: tiled - cp tiled ${PREFIX}/bin/ - -build: src/*.c src/*.h - ${CC} src/*.c -o tiled ${FLAGS} +.DEFAULT_GOAL := editor editor: src/*.c src/editor.c ${CC} src/*.c -o editor ${FLAGS} -clean: tiled - rm tiled - diff --git a/src/editor.c b/src/editor.c index 2cf2f84..52e653f 100644 --- a/src/editor.c +++ b/src/editor.c @@ -24,12 +24,16 @@ void drawOverlay(Tiled tiled) { }, tiled.zoom/16, GREEN); } -void modifyTile(Tiled *tiled, int x) { - int tile = getTiledMapTile(tiled->tiledMap, selectedTile); - int tileCount = tiled->tiledMap.atlasSize[0] * tiled->tiledMap.atlasSize[1] + 1; - tile = (tile + x) % (tileCount); - setTiledMapTile(tiled->tiledMap, selectedTile, tile); - renderTilemapTexture(&tiled->tilemapTexture, tiled->tiledMap); +void modifyTile(Tiled *tiled, int i) { + if (selectedTile[0] >= 0 && selectedTile[0] < tiled->tiledMap.width + && selectedTile[1] >= 0 && selectedTile[1] < tiled->tiledMap.height) { + printf("%d,%d", selectedTile[0], selectedTile[1]); + int tile = getTiledMapTile(tiled->tiledMap, selectedTile); + int tileCount = tiled->tiledMap.atlasSize[0] * tiled->tiledMap.atlasSize[1] + 1; + tile = (tile + i) % (tileCount); + setTiledMapTile(tiled->tiledMap, selectedTile, tile); + renderTilemapTexture(&tiled->tilemapTexture, tiled->tiledMap); + } } int launchEditor(TiledMap tiledMap) { diff --git a/src/tiled.c b/src/tiled.c index 82b29e0..65b9d1d 100644 --- a/src/tiled.c +++ b/src/tiled.c @@ -50,8 +50,8 @@ Tiled initTiled(TiledMap tiledMap) { tiled.tiledMap = tiledMap; tiled.offset = (Vector2) {0, 0}; tiled.zoom = 64; - tiled.mapSize[0] = tiled.tilemapTexture.width; - tiled.mapSize[1] = tiled.tilemapTexture.height; + tiled.mapSize[0] = tiled.tiledMap.width; + tiled.mapSize[1] = tiled.tiledMap.height; tiled.targetTexture = LoadRenderTexture(1, 1); tiled.atlasSize[0] = tiledMap.atlasSize[0]; |