diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | assets/level1.json | 73 | ||||
-rw-r--r-- | assets/level1.tmx | 67 | ||||
-rw-r--r-- | assets/main_tileset.tsx | 4 | ||||
-rw-r--r-- | assets/tilemap_packed.png | bin | 0 -> 4501 bytes | |||
-rw-r--r-- | layerType.wren | 5 | ||||
-rw-r--r-- | main.wren | 72 | ||||
-rw-r--r-- | scratch.md | 22 |
8 files changed, 244 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf0824e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.log
\ No newline at end of file diff --git a/assets/level1.json b/assets/level1.json new file mode 100644 index 0000000..ea69794 --- /dev/null +++ b/assets/level1.json @@ -0,0 +1,73 @@ +{ "compressionlevel":-1, + "editorsettings": + { + "export": + { + "format":"json", + "target":"level1.json" + } + }, + "height":16, + "infinite":false, + "layers":[ + { + "data":[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":16, + "id":2, + "name":"buildings", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":16, + "x":0, + "y":0 + }, + { + "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":16, + "id":4, + "name":"Tile Layer 3", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":16, + "x":0, + "y":0 + }], + "nextlayerid":5, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.5.0", + "tileheight":16, + "tilesets":[ + { + "columns":17, + "firstgid":1, + "image":"tilemap_packed.png", + "imageheight":128, + "imagewidth":272, + "margin":0, + "name":"main_tileset", + "spacing":0, + "tilecount":136, + "tileheight":16, + "tilewidth":16 + }], + "tilewidth":16, + "type":"map", + "version":1.5, + "width":16 +}
\ No newline at end of file diff --git a/assets/level1.tmx b/assets/level1.tmx new file mode 100644 index 0000000..2fe128f --- /dev/null +++ b/assets/level1.tmx @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<map version="1.5" tiledversion="1.5.0" orientation="orthogonal" renderorder="right-down" width="16" height="16" tilewidth="16" tileheight="16" infinite="0" nextlayerid="5" nextobjectid="1"> + <editorsettings> + <export target="level1.json" format="json"/> + </editorsettings> + <tileset firstgid="1" source="main_tileset.tsx"/> + <layer id="1" name="ground" width="16" height="16"> + <data encoding="csv"> +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 +</data> + </layer> + <layer id="2" name="buildings" width="16" height="16"> + <data encoding="csv"> +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,81,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,97,98,99,0,0,0,0,0,0,0, +0,0,0,0,0,0,114,115,116,0,0,0,0,0,0,0, +0,0,0,0,0,0,131,132,133,0,0,0,0,0,0,0, +0,0,0,0,0,0,108,110,109,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +</data> + </layer> + <layer id="4" name="Tile Layer 3" width="16" height="16"> + <data encoding="csv"> +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,120,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +</data> + </layer> +</map> diff --git a/assets/main_tileset.tsx b/assets/main_tileset.tsx new file mode 100644 index 0000000..0b0b1d6 --- /dev/null +++ b/assets/main_tileset.tsx @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tileset version="1.5" tiledversion="1.5.0" name="main_tileset" tilewidth="16" tileheight="16" tilecount="136" columns="17"> + <image source="tilemap_packed.png" width="272" height="128"/> +</tileset> diff --git a/assets/tilemap_packed.png b/assets/tilemap_packed.png Binary files differnew file mode 100644 index 0000000..6f47609 --- /dev/null +++ b/assets/tilemap_packed.png diff --git a/layerType.wren b/layerType.wren new file mode 100644 index 0000000..cee6b82 --- /dev/null +++ b/layerType.wren @@ -0,0 +1,5 @@ +// ENUM lol +class LayerType { + static Tile { "tilelayer" } + static Object { "objectgroup" } +}
\ No newline at end of file diff --git a/main.wren b/main.wren new file mode 100644 index 0000000..1d472b0 --- /dev/null +++ b/main.wren @@ -0,0 +1,72 @@ +import "graphics" for ImageData +import "json" for Json +import "graphics" for Canvas, Color +import "./layerType" for LayerType +import "dome" for Window +import "math" for Math +class Main { + construct new() { + _tileSheet = ImageData.loadFromFile("assets/tilemap_packed.png") + _tileSheetH = 128 + _tileSheetW = 272 + _tileH = 16 + _tileW = 16 + _rows = _tileSheetW/_tileW + _cols = _tileSheetH/_tileH + _levelData = Json.load("assets/level1.json") + _levelHeight = _levelData["tileheight"] + _levelWidth = _levelData["tilewidth"] + _layers = _levelData["layers"] + Window.resize(256, 256) + Canvas.resize(256, 256) + + } + + init() { + + } + + update() { + + } + + drawTile(tileIndex, mapX, mapY) { + var spriteX = (tileIndex % _rows) + var spriteY = Math.floor ((tileIndex - spriteX) % _cols) + _tileSheet.transform({ + "srcX": spriteX * 16, + "srcY": spriteY * 16, + "srcW": _tileW, + "srcH": _tileH, + "scaleX": 1, + "scaleY": 1 + }).draw(mapX*16,mapY*16) + } + + drawLevel(x, y) { + for(layer in _layers) { + var index = 0 + for(levelY in 0...(_levelHeight)) { + for(levelX in 0...(_levelWidth)) { + if((layer["type"] == LayerType.Tile) && (layer["visible"] == true)) { + var tileIndex = layer["data"][index] + if (tileIndex > 0) { + drawTile(tileIndex-1, levelX, levelY) + } + } + index = index + 1 + } + } + } + } + + getTile() { + + } + + draw(alpha) { + drawLevel(0,0) + } +} + +var Game = Main.new()
\ No newline at end of file diff --git a/scratch.md b/scratch.md new file mode 100644 index 0000000..0eb82bf --- /dev/null +++ b/scratch.md @@ -0,0 +1,22 @@ + +## Wren Scratch +### Matrix +```wren +var matrix = [[1, 2, 3], [4, 5, 6]] +System.print(matrix[0][0]) +for(layer in _layerData) { + System.print(layer) +} +``` + +### Sprite Sheet Transform +```wren +_spriteSheet.transform({ + "srcX": 16*14, + "srcY": 0, + "srcW": 16, + "srcH": 16, + "scaleX": 2, + "scaleY": 2 + }).draw(0,0) +```
\ No newline at end of file |