From 741d7c934df92f8bc779b2c4857b1e93f4e1384b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 22 Jun 2023 00:07:11 +1000 Subject: [PATCH] Updated and testing Box --- Box | 2 +- assets/scripts/airplane.toy | 59 ++++++++++++--------------------- assets/scripts/init.toy | 4 +-- assets/scripts/sorting_test.toy | 34 ------------------- 4 files changed, 24 insertions(+), 75 deletions(-) delete mode 100644 assets/scripts/sorting_test.toy diff --git a/Box b/Box index 94d9915..85bcf5f 160000 --- a/Box +++ b/Box @@ -1 +1 @@ -Subproject commit 94d991552011a389ee6e239fc5b4d469849f80b5 +Subproject commit 85bcf5f8f8eb02e10e7f8dacfdb4f1d553d1b0c8 diff --git a/assets/scripts/airplane.toy b/assets/scripts/airplane.toy index 3ddcb36..9c50c55 100644 --- a/assets/scripts/airplane.toy +++ b/assets/scripts/airplane.toy @@ -1,26 +1,11 @@ import node; //constants -var SPEED: int const = 5; - -//variables -var parent: opaque = null; //cache the parent for quick access -var posX: int = 50; -var posY: int = 50; +var SPEED: int const = 10; var WIDTH: int const = 143; var HEIGHT: int const = 75; -var xspeed: int = 0; -var yspeed: int = 0; -//accessors - variables are private, functions are public -fn getX(node: opaque) { - return posX; -} - -fn getY(node: opaque) { - return posY; -} //lifecycle functions fn onLoad(node: opaque) { @@ -30,15 +15,11 @@ fn onLoad(node: opaque) { fn onInit(node: opaque) { print "onInit() called"; - parent = node.getParentNode(); node.loadNodeTexture("sprites:/little_plane.png"); } fn onStep(node: opaque) { -// print "onStep() called"; - - posX += xspeed; - posY += yspeed; + //TODO: move } fn onFree(node: opaque) { @@ -49,59 +30,61 @@ fn onFree(node: opaque) { fn onDraw(node: opaque) { // print "onDraw() called"; + var parent: opaque = node.getParentNode(); var px = 0; var py = 0; + //TODO: get world position if (parent != null) { - px = parent.callNodeFn("getX"); - py = parent.callNodeFn("getY"); + px = parent.getNodePositionX(); + py = parent.getNodePositionY(); } - node.drawNode(posX + px, posY + py, WIDTH, HEIGHT); + node.drawNode(node.getNodePositionX() + px, node.getNodePositionY() + py, WIDTH, HEIGHT); } //event functions fn onKeyDown(node: opaque, event: string) { if (event == "character_up") { - yspeed -= SPEED; + node.setNodeMotionY(-SPEED); return; } if (event == "character_down") { - yspeed += SPEED; + node.setNodeMotionY(SPEED); return; } if (event == "character_left") { - xspeed -= SPEED; + node.setNodeMotionX(-SPEED); return; } if (event == "character_right") { - xspeed += SPEED; + node.setNodeMotionX(SPEED); return; } } fn onKeyUp(node: opaque, event: string) { - if (event == "character_up" && yspeed < 0) { - yspeed = 0; + if (event == "character_up" && node.getNodeMotionY() < 0) { + node.setNodeMotionY(0); return; } - if (event == "character_down" && yspeed > 0) { - yspeed = 0; + if (event == "character_down" && node.getNodeMotionY() > 0) { + node.setNodeMotionY(0); return; } - if (event == "character_left" && xspeed < 0) { - xspeed = 0; + if (event == "character_left" && node.getNodeMotionX() < 0) { + node.setNodeMotionX(0); return; } - if (event == "character_right" && xspeed > 0) { - xspeed = 0; + if (event == "character_right" && node.getNodeMotionX() > 0) { + node.setNodeMotionX(0); return; } } @@ -114,8 +97,8 @@ fn onMouseButtonDown(node: opaque, x: int, y: int, button: string) { // print "entity.toy:onMouseButtonDown(" + string x + ", " + string y + ", " + button + ")"; //jump to pos - posX = x - WIDTH / 2; - posY = y - HEIGHT / 2; + node.setNodePositionX(x - WIDTH / 2); + node.setNodePositionY(y - HEIGHT / 2); } fn onMouseButtonUp(node: opaque, x: int, y: int, button: string) { diff --git a/assets/scripts/init.toy b/assets/scripts/init.toy index 76db406..242f0e1 100644 --- a/assets/scripts/init.toy +++ b/assets/scripts/init.toy @@ -32,10 +32,10 @@ //this function must always be called, or the engine won't run - initWindow("Skyland", 32*16, 32*16 + 32, false); //TODO: custom FPS setting + initWindow("Airport", 800, 600, false); //TODO: custom FPS setting //kick off the logic of the scene graph - loadRootNode("scripts:/gameplay/scene.toy"); + loadRootNode("scripts:/airplane.toy"); } //Globals go here diff --git a/assets/scripts/sorting_test.toy b/assets/scripts/sorting_test.toy deleted file mode 100644 index b4bbdfd..0000000 --- a/assets/scripts/sorting_test.toy +++ /dev/null @@ -1,34 +0,0 @@ - -import node; - -//generate a number of child nodes -fn onInit(node: opaque) { - node.loadChild("scripts:/empty.toy", 3); - node.loadChild("scripts:/empty.toy", 2); - node.loadChild("scripts:/empty.toy", 1); - node.loadChild("scripts:/empty.toy", 4); - node.loadChild("scripts:/empty.toy", 5); - - node.freeChildNode(3); -} - -fn onStep(node) { - node.sortChildrenNode(lessThan); -} - -fn lessThan(lhs, rhs) { - var a = lhs.callNodeFn("getValue"); - var b = rhs.callNodeFn("getValue"); - - return a < b; -} - -//utils - polyfills -fn loadChild(parent: opaque, fname: string, value) { - var child: opaque = loadNode(fname); - - child.callNodeFn("setValue", value); - - parent.pushNode(child); - return child; -} \ No newline at end of file