From 3988412a6aa5aaa8253e18e4fd5a0ac670eeb27d Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Sun, 5 Mar 2023 13:11:06 +1100 Subject: [PATCH] Adjusted scale --- Toy | 2 +- assets/scripts/gameplay/lejana.toy | 17 ++++++----- assets/scripts/gameplay/scene.toy | 17 ++++++++++- assets/scripts/gameplay/tilemap.toy | 42 +++++++++++++++++++++++----- assets/sprites/drone.png | Bin 0 -> 1394 bytes 5 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 assets/sprites/drone.png diff --git a/Toy b/Toy index 76ddd57..f869c94 160000 --- a/Toy +++ b/Toy @@ -1 +1 @@ -Subproject commit 76ddd5703e73cc7435595f7b38c8d8a1c63a80d0 +Subproject commit f869c9425a9070e243d975f4fe7748662ce27f6b diff --git a/assets/scripts/gameplay/lejana.toy b/assets/scripts/gameplay/lejana.toy index 56887e7..3f430fc 100644 --- a/assets/scripts/gameplay/lejana.toy +++ b/assets/scripts/gameplay/lejana.toy @@ -2,11 +2,14 @@ import standard; import node; //constants -var SPEED: int const = 3; +var SPEED: int const = 2; var SPRITE_WIDTH: int const = 64; var SPRITE_HEIGHT: int const = 64; +var TILE_WIDTH: int const = 32; +var TILE_HEIGHT: int const = 32; + //variables var parent: opaque = null; //cache the parent for quick access @@ -71,13 +74,13 @@ fn onInit(node: opaque) { fn onStep(node: opaque) { //process input when aligned to a grid - if (realX / SPRITE_WIDTH == gridX && realY / SPRITE_HEIGHT == gridY && motionX == 0 && motionY == 0) { + if (realX / TILE_WIDTH == gridX && realY / TILE_HEIGHT == gridY && motionX == 0 && motionY == 0) { //disallow wall phasing - if (parent.callNodeFn("getCollisionAt", gridX + inputX, gridY) != true) { + if (inputX != 0 && parent.callNodeFn("getCollisionAt", gridX + inputX, gridY) != true) { inputX = 0; } - if (parent.callNodeFn("getCollisionAt", gridX, gridY + inputY) != true) { + if (inputY != 0 && parent.callNodeFn("getCollisionAt", gridX, gridY + inputY) != true) { inputY = 0; } @@ -119,8 +122,8 @@ fn onStep(node: opaque) { } //calc movement - var distX = gridX * SPRITE_WIDTH - realX; - var distY = gridY * SPRITE_HEIGHT - realY; + var distX = gridX * TILE_WIDTH - realX; + var distY = gridY * TILE_HEIGHT - realY; motionX = normalize(distX); motionY = normalize(distY); @@ -146,7 +149,7 @@ fn onDraw(node: opaque) { py = py != null ? py : 0; } - node.drawNode(realX + px, realY + py, SPRITE_WIDTH, SPRITE_HEIGHT); + node.drawNode(realX + px - SPRITE_WIDTH / 4, realY + py - SPRITE_HEIGHT / 2, SPRITE_WIDTH, SPRITE_HEIGHT); } //event functions diff --git a/assets/scripts/gameplay/scene.toy b/assets/scripts/gameplay/scene.toy index 6a9b7a5..3775741 100644 --- a/assets/scripts/gameplay/scene.toy +++ b/assets/scripts/gameplay/scene.toy @@ -6,6 +6,9 @@ var player: opaque = null; var collisionMap: [[bool]] = null; //cache this, since it won't change during a level +var stepCounter: int = 0; +var drawCounter: int = 0; + //lifecycle functions fn onLoad(node: opaque) { tilemap = node.loadChild("scripts:/gameplay/tilemap.toy"); @@ -13,10 +16,22 @@ fn onLoad(node: opaque) { } fn onInit(node: opaque) { - tilemap.callNodeFn("generateFromSeed", clock().hash(), 8, 8); + tilemap.callNodeFn("generateFromSeed", clock().hash(), 16, 16); collisionMap = tilemap.callNodeFn("getCollisionMap"); } +fn onStep(node: opaque) { + if (++stepCounter >= 60) { + print "FPS: " + string drawCounter + " / 60"; + stepCounter = 0; + drawCounter = 0; + } +} + +fn onDraw(node: opaque) { + drawCounter++; +} + //utils - polyfills fn loadChild(parent: opaque, fname: string) { var child: opaque = loadNode(fname); diff --git a/assets/scripts/gameplay/tilemap.toy b/assets/scripts/gameplay/tilemap.toy index e41ab50..7490a48 100644 --- a/assets/scripts/gameplay/tilemap.toy +++ b/assets/scripts/gameplay/tilemap.toy @@ -2,11 +2,13 @@ import standard; import node; //consts -var TILE_WIDTH: int const = 64; -var TILE_HEIGHT: int const = 64; +var TILE_WIDTH: int const = 32; +var TILE_HEIGHT: int const = 32; //map between the identity and position on the sprite sheet -var tilemap: [[string]] = null; +var rawmap: [[string]] = null; + +var tilemap: [[[int]]] = null; var collisions: [[bool]] = null; var tileset: [string : [int]] = [ @@ -77,7 +79,7 @@ fn onDraw(node: opaque) { //draw the tilemap for (var j = lowerY; j < upperY; j++) { for (var i = lowerX; i < upperX; i++) { - var pos = tileset[tilemap[i][j]]; + var pos = tileset[ rawmap[i][j] ]; node.setNodeRect(pos[0] * 16, pos[1] * 16, 16, 16); node.drawNode(i * TILE_WIDTH, j * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); @@ -88,14 +90,16 @@ fn onDraw(node: opaque) { //utils functions for map generation fn generateFromSeed(node: opaque, seed: int, width: int, height: int) { - tilemap = generateTilemap(seed, width, height); - collisions = bakeCollisionMap(tilemap, width, height); + rawmap = generateRawTilemap(seed, width, height); + + tilemap = bakeTilemap(rawmap, width, height); + collisions = bakeCollisionMap(rawmap, width, height); print tilemap; print collisions; } -fn generateTilemap(seed: int, width: int, height: int) { +fn generateRawTilemap(seed: int, width: int, height: int) { import random; var rng: opaque = createRandomGenerator(seed); @@ -165,6 +169,30 @@ fn bakeCollisionMap(tilemap: [[string]], width: int, height: int) { return result; } +fn bakeTilemap(tilemap: [[string]], width: int, height: int) { + //generate an empty grid + var result: [[[int]]] = []; + var row: [[int]] = []; + for (var j: int = 0; j < height; j++) { + row.push([0,0]); + } + + for (var i: int = 0; i < width; i++) { + result.push(row); + } + + //extract the collision map + for (var j: int = 0; j < height; j++) { + for (var i: int = 0; i < width; i++) { + //almost - you still need one pair of parentheses + result[i][j][0] = (tileset[ tilemap[i][j] ][0]); + result[i][j][1] = (tileset[ tilemap[i][j] ][1]); + } + } + + return result; +} + fn getCollisionMap(node: opaque) { return collisions; } \ No newline at end of file diff --git a/assets/sprites/drone.png b/assets/sprites/drone.png new file mode 100644 index 0000000000000000000000000000000000000000..b0796188a118bc4a5cffb693d6acd7badea29f46 GIT binary patch literal 1394 zcmV-&1&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