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" />
</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\entity.toy" />
<None Include="assets\scripts\frames_test.toy" />
<None Include="assets\scripts\airplane.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>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>

View File

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

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

View File

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

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);
//kick off the logic of the scene graph
loadRootNode("scripts:/scene.toy");
loadRootNode("scripts:/demo/scene.toy");
}
//Globals go here

View File

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