Moved the demo scripts into a directory

This commit is contained in:
2023-03-03 23:57:02 +11:00
parent 08ce7b5536
commit b89f73ac9e
11 changed files with 33 additions and 85 deletions

View File

@@ -22,15 +22,13 @@
<ClCompile Include="source\main.c" /> <ClCompile Include="source\main.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="assets\scripts\children_test.toy" /> <None Include="assets\scripts\demo\scene.toy" />
<None Include="assets\scripts\demo\tilemap\layer-background.toy" />
<None Include="assets\scripts\demo\tilemap\layer-walls.toy" />
<None Include="assets\scripts\demo\tilemap\tilemap.toy" />
<None Include="assets\scripts\empty.toy" /> <None Include="assets\scripts\empty.toy" />
<None Include="assets\scripts\entity.toy" /> <None Include="assets\scripts\airplane.toy" />
<None Include="assets\scripts\frames_test.toy" />
<None Include="assets\scripts\init.toy" /> <None Include="assets\scripts\init.toy" />
<None Include="assets\scripts\scene.toy" />
<None Include="assets\scripts\tilemap\layer-background.toy" />
<None Include="assets\scripts\tilemap\layer-walls.toy" />
<None Include="assets\scripts\tilemap\tilemap.toy" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion> <VCProjectVersion>17.0</VCProjectVersion>

View File

@@ -4,11 +4,11 @@ import node;
var SPEED: int const = 5; var SPEED: int const = 5;
//variables //variables
var parent: opaque = null; var parent: opaque = null; //cache the parent for quick access
var posX: int = 50; var posX: int = 50;
var posY: int = 50; var posY: int = 50;
var WIDTH: int const = 100; var WIDTH: int const = 143;
var HEIGHT: int const = 100; var HEIGHT: int const = 75;
var xspeed: int = 0; var xspeed: int = 0;
var yspeed: int = 0; var yspeed: int = 0;
@@ -23,36 +23,39 @@ fn getY(node: opaque) {
} }
//lifecycle functions //lifecycle functions
fn onInit(node: opaque) { fn onLoad(node: opaque) {
print "render.toy:onInit() called"; print "onLoad() called";
}
node.loadTexture("sprites:/character.png"); fn onInit(node: opaque) {
parent = node.getNodeParent(); print "onInit() called";
parent = node.getParentNode();
node.loadTexture("sprites:/little_plane.png");
} }
fn onStep(node: opaque) { fn onStep(node: opaque) {
// print "onStep() called";
posX += xspeed; posX += xspeed;
posY += yspeed; posY += yspeed;
} }
fn onFree(node: opaque) { fn onFree(node: opaque) {
print "render.toy:onFree() called"; print "onFree() called";
node.freeTexture(); node.freeTexture();
} }
fn onDraw(node: opaque) { fn onDraw(node: opaque) {
// print "render.toy:onDraw() called"; // print "onDraw() called";
var px = parent.callNode("getX"); var px = 0;
var py = parent.callNode("getY"); var py = 0;
if (px == null) { if (parent != null) {
px = 0; px = parent.callNodeFn("getX");
} py = parent.callNodeFn("getY");
if (py == null) {
py = 0;
} }
node.drawNode(posX + px, posY + py, WIDTH, HEIGHT); node.drawNode(posX + px, posY + py, WIDTH, HEIGHT);

View File

@@ -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;
}

View File

@@ -17,7 +17,7 @@ fn makeChild(parent: opaque, fname: string) {
//lifecycle functions //lifecycle functions
fn onLoad(node: opaque) { fn onLoad(node: opaque) {
//load the tile map node //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-background.toy");
tilemapNode.callNodeFn("loadLayer", "layer-walls.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) { fn onMouseButtonDown(node: opaque, x: int, y: int, button: string) {
//reload the scene on click //reload the scene on click
if (button == "left") { if (button == "left") {
loadRootNode("scripts:/scene.toy"); loadRootNode("scripts:/demo/scene.toy");
} }
} }

View File

@@ -15,7 +15,7 @@ fn loadChild(parent: opaque, fname: string) {
fn loadLayer(node: opaque, layerName: string) { fn loadLayer(node: opaque, layerName: string) {
//load the given layer as a child //load the given layer as a child
var layerNode = node.loadChild("scripts:/tilemap/" + layerName); var layerNode = node.loadChild("scripts:/demo/tilemap/" + layerName);
} }
//lifecycle functions //lifecycle functions

View File

@@ -1 +1 @@
//this file is a polyfill //this file is a polyfill TODO: fix this

View File

@@ -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);
}

View File

@@ -31,7 +31,7 @@
initWindow("Airport Game", 1080, 720, false); initWindow("Airport Game", 1080, 720, false);
//kick off the logic of the scene graph //kick off the logic of the scene graph
loadRootNode("scripts:/scene.toy"); loadRootNode("scripts:/demo/scene.toy");
} }
//Globals go here //Globals go here

View File

@@ -101,7 +101,7 @@ void Box_freeEngine() {
engine.window = NULL; engine.window = NULL;
} }
static void execLoadRootNode() { static inline void execLoadRootNode() {
//if a new root node is NOT needed, skip out //if a new root node is NOT needed, skip out
if (TOY_IS_NULL(engine.nextRootNodeFilename)) { if (TOY_IS_NULL(engine.nextRootNodeFilename)) {
return; return;
@@ -159,7 +159,7 @@ static void execLoadRootNode() {
Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onInit", NULL); 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_LiteralArray args; //save some allocation by reusing this
Toy_initLiteralArray(&args); Toy_initLiteralArray(&args);
@@ -394,7 +394,7 @@ static void execEvents() {
Toy_freeLiteralArray(&args); Toy_freeLiteralArray(&args);
} }
static void execStep() { static inline void execStep() {
if (engine.rootNode != NULL) { if (engine.rootNode != NULL) {
//steps //steps
Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onStep", NULL); Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onStep", NULL);