aboutsummaryrefslogtreecommitdiff
path: root/main.wren
diff options
context:
space:
mode:
authorIndrajith K L2021-08-01 02:26:00 +0530
committerIndrajith K L2021-08-01 02:26:00 +0530
commitb73889da9f33b883894db6a989037030fee99f95 (patch)
treefde19617d41bd0cfd71224a3166aa3f38c53b54d /main.wren
parent4cd16130dcab278e3c1204eebcc04d47f2676007 (diff)
downloadrebirth-wren-b73889da9f33b883894db6a989037030fee99f95.tar.gz
rebirth-wren-b73889da9f33b883894db6a989037030fee99f95.tar.bz2
rebirth-wren-b73889da9f33b883894db6a989037030fee99f95.zip
Basic Renderer
* Adds Tiled map JSON rendering * TODO Cleanup & Organization
Diffstat (limited to 'main.wren')
-rw-r--r--main.wren72
1 files changed, 72 insertions, 0 deletions
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