diff --git a/Airport.vcxproj b/Airport.vcxproj index 0d3ed90..ee0f36c 100644 --- a/Airport.vcxproj +++ b/Airport.vcxproj @@ -22,15 +22,13 @@ - + + + + - - + - - - - 17.0 diff --git a/assets/scripts/entity.toy b/assets/scripts/airplane.toy similarity index 80% rename from assets/scripts/entity.toy rename to assets/scripts/airplane.toy index b50f98d..efecfeb 100644 --- a/assets/scripts/entity.toy +++ b/assets/scripts/airplane.toy @@ -4,11 +4,11 @@ import node; var SPEED: int const = 5; //variables -var parent: opaque = null; +var parent: opaque = null; //cache the parent for quick access var posX: int = 50; var posY: int = 50; -var WIDTH: int const = 100; -var HEIGHT: int const = 100; +var WIDTH: int const = 143; +var HEIGHT: int const = 75; var xspeed: int = 0; var yspeed: int = 0; @@ -23,36 +23,39 @@ fn getY(node: opaque) { } //lifecycle functions -fn onInit(node: opaque) { - print "render.toy:onInit() called"; +fn onLoad(node: opaque) { + print "onLoad() called"; +} - node.loadTexture("sprites:/character.png"); - parent = node.getNodeParent(); +fn onInit(node: opaque) { + print "onInit() called"; + + parent = node.getParentNode(); + node.loadTexture("sprites:/little_plane.png"); } fn onStep(node: opaque) { +// print "onStep() called"; + posX += xspeed; posY += yspeed; } fn onFree(node: opaque) { - print "render.toy:onFree() called"; + print "onFree() called"; node.freeTexture(); } fn onDraw(node: opaque) { -// print "render.toy:onDraw() called"; +// print "onDraw() called"; - var px = parent.callNode("getX"); - var py = parent.callNode("getY"); + var px = 0; + var py = 0; - if (px == null) { - px = 0; - } - - if (py == null) { - py = 0; + if (parent != null) { + px = parent.callNodeFn("getX"); + py = parent.callNodeFn("getY"); } node.drawNode(posX + px, posY + py, WIDTH, HEIGHT); diff --git a/assets/scripts/children_test.toy b/assets/scripts/children_test.toy deleted file mode 100644 index bce6337..0000000 --- a/assets/scripts/children_test.toy +++ /dev/null @@ -1,28 +0,0 @@ -import node; - -//looks like a polyfill -fn loadChild(parent: opaque, fname: string) { - var child: opaque = loadNode(fname); - parent.pushNode(child); - return child; -} - -fn onLoad(node: opaque) { - for (var i = 0; i < 20; i++) { - node.loadChild("scripts:/empty.toy"); - } - - node.freeChildNode(10); - var n = node.getChildNode(10); - - for (var i = 0; i < 20; i++) { - node.loadChild("scripts:/empty.toy"); - } - - print node.getChildNodeCount(); - - var m = node.getChildNode(10); - - print n; - print m; -} \ No newline at end of file diff --git a/assets/scripts/scene.toy b/assets/scripts/demo/scene.toy similarity index 93% rename from assets/scripts/scene.toy rename to assets/scripts/demo/scene.toy index df334e7..5cdeab3 100644 --- a/assets/scripts/scene.toy +++ b/assets/scripts/demo/scene.toy @@ -17,7 +17,7 @@ fn makeChild(parent: opaque, fname: string) { //lifecycle functions fn onLoad(node: opaque) { //load the tile map node - var tilemapNode = node.makeChild("scripts:/tilemap/tilemap.toy"); + var tilemapNode = node.makeChild("scripts:/demo/tilemap/tilemap.toy"); tilemapNode.callNodeFn("loadLayer", "layer-background.toy"); tilemapNode.callNodeFn("loadLayer", "layer-walls.toy"); @@ -46,7 +46,7 @@ fn onDraw(node: opaque) { fn onMouseButtonDown(node: opaque, x: int, y: int, button: string) { //reload the scene on click if (button == "left") { - loadRootNode("scripts:/scene.toy"); + loadRootNode("scripts:/demo/scene.toy"); } } diff --git a/assets/scripts/tilemap/layer-background.toy b/assets/scripts/demo/tilemap/layer-background.toy similarity index 100% rename from assets/scripts/tilemap/layer-background.toy rename to assets/scripts/demo/tilemap/layer-background.toy diff --git a/assets/scripts/tilemap/layer-walls.toy b/assets/scripts/demo/tilemap/layer-walls.toy similarity index 100% rename from assets/scripts/tilemap/layer-walls.toy rename to assets/scripts/demo/tilemap/layer-walls.toy diff --git a/assets/scripts/tilemap/tilemap.toy b/assets/scripts/demo/tilemap/tilemap.toy similarity index 92% rename from assets/scripts/tilemap/tilemap.toy rename to assets/scripts/demo/tilemap/tilemap.toy index 3ab0708..2c47573 100644 --- a/assets/scripts/tilemap/tilemap.toy +++ b/assets/scripts/demo/tilemap/tilemap.toy @@ -15,7 +15,7 @@ fn loadChild(parent: opaque, fname: string) { fn loadLayer(node: opaque, layerName: string) { //load the given layer as a child - var layerNode = node.loadChild("scripts:/tilemap/" + layerName); + var layerNode = node.loadChild("scripts:/demo/tilemap/" + layerName); } //lifecycle functions diff --git a/assets/scripts/empty.toy b/assets/scripts/empty.toy index 60d8c7b..2b82815 100644 --- a/assets/scripts/empty.toy +++ b/assets/scripts/empty.toy @@ -1 +1 @@ -//this file is a polyfill \ No newline at end of file +//this file is a polyfill TODO: fix this \ No newline at end of file diff --git a/assets/scripts/frames_test.toy b/assets/scripts/frames_test.toy deleted file mode 100644 index a7b993c..0000000 --- a/assets/scripts/frames_test.toy +++ /dev/null @@ -1,25 +0,0 @@ -import node; - -fn onInit(node: opaque) { - node.loadTexture("sprites:/frametest.png"); - - //mapped to the given image - node.setNodeRect(0, 0, 32, 32); - node.setNodeFrames(3); -} - -var counter = 0; -fn onStep(node: opaque) { - counter++; - if (counter >= 60) { - counter = 0; - node.incrementCurrentNodeFrame(); - print "---"; - print node.getCurrentNodeFrame(); - print node.getNodeFrames(); - } -} - -fn onDraw(node: opaque) { - node.drawNode(0, 0); -} \ No newline at end of file diff --git a/assets/scripts/init.toy b/assets/scripts/init.toy index ca68d49..fc969ec 100644 --- a/assets/scripts/init.toy +++ b/assets/scripts/init.toy @@ -31,7 +31,7 @@ initWindow("Airport Game", 1080, 720, false); //kick off the logic of the scene graph - loadRootNode("scripts:/scene.toy"); + loadRootNode("scripts:/demo/scene.toy"); } //Globals go here diff --git a/box/box_engine.c b/box/box_engine.c index 9543309..0c456bf 100644 --- a/box/box_engine.c +++ b/box/box_engine.c @@ -101,7 +101,7 @@ void Box_freeEngine() { engine.window = NULL; } -static void execLoadRootNode() { +static inline void execLoadRootNode() { //if a new root node is NOT needed, skip out if (TOY_IS_NULL(engine.nextRootNodeFilename)) { return; @@ -159,7 +159,7 @@ static void execLoadRootNode() { Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onInit", NULL); } -static void execEvents() { +static inline void execEvents() { Toy_LiteralArray args; //save some allocation by reusing this Toy_initLiteralArray(&args); @@ -394,7 +394,7 @@ static void execEvents() { Toy_freeLiteralArray(&args); } -static void execStep() { +static inline void execStep() { if (engine.rootNode != NULL) { //steps Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onStep", NULL);