Added water-based step counter
This commit is contained in:
@@ -31,6 +31,8 @@
|
|||||||
<None Include="assets\scripts\gameplay\drone.toy" />
|
<None Include="assets\scripts\gameplay\drone.toy" />
|
||||||
<None Include="assets\scripts\gameplay\lejana.toy" />
|
<None Include="assets\scripts\gameplay\lejana.toy" />
|
||||||
<None Include="assets\scripts\gameplay\scene.toy" />
|
<None Include="assets\scripts\gameplay\scene.toy" />
|
||||||
|
<None Include="assets\scripts\gameplay\step-counter.toy" />
|
||||||
|
<None Include="assets\scripts\gameplay\text.toy" />
|
||||||
<None Include="assets\scripts\gameplay\tilemap.toy" />
|
<None Include="assets\scripts\gameplay\tilemap.toy" />
|
||||||
<None Include="assets\scripts\init.toy" />
|
<None Include="assets\scripts\init.toy" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ fn onInit(node: opaque) {
|
|||||||
print "onInit() called";
|
print "onInit() called";
|
||||||
|
|
||||||
parent = node.getParentNode();
|
parent = node.getParentNode();
|
||||||
node.loadTexture("sprites:/little_plane.png");
|
node.loadNodeTexture("sprites:/little_plane.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onStep(node: opaque) {
|
fn onStep(node: opaque) {
|
||||||
@@ -44,7 +44,7 @@ fn onStep(node: opaque) {
|
|||||||
fn onFree(node: opaque) {
|
fn onFree(node: opaque) {
|
||||||
print "onFree() called";
|
print "onFree() called";
|
||||||
|
|
||||||
node.freeTexture();
|
node.freeNodeTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onDraw(node: opaque) {
|
fn onDraw(node: opaque) {
|
||||||
|
|||||||
@@ -1,6 +1 @@
|
|||||||
//this file is a polyfill TODO: fix this
|
//this file is a polyfill TODO: fix this
|
||||||
|
|
||||||
fn onDraw(node: opaque) {
|
|
||||||
//debug draw at the origin
|
|
||||||
node.drawNode(0, 0);
|
|
||||||
}
|
|
||||||
@@ -90,7 +90,7 @@ fn getRealPos(node: opaque) {
|
|||||||
|
|
||||||
//lifecycle functions
|
//lifecycle functions
|
||||||
fn onLoad(node: opaque) {
|
fn onLoad(node: opaque) {
|
||||||
node.loadTexture("sprites:/drone.png");
|
node.loadNodeTexture("sprites:/drone.png");
|
||||||
node.faceDown();
|
node.faceDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,22 +117,11 @@ fn onStep(node: opaque) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn onFree(node: opaque) {
|
fn onFree(node: opaque) {
|
||||||
node.freeTexture();
|
node.freeNodeTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn customOnDraw(node: opaque) {
|
fn customOnDraw(node: opaque, parentX: int, parentY: int) {
|
||||||
var px = 0;
|
node.drawNode(realX + parentX - SPRITE_WIDTH / 4, realY + parentY - SPRITE_HEIGHT / 2, SPRITE_WIDTH, SPRITE_HEIGHT);
|
||||||
var py = 0;
|
|
||||||
|
|
||||||
if (parent != null) {
|
|
||||||
px = parent.callNodeFn("getX");
|
|
||||||
py = parent.callNodeFn("getY");
|
|
||||||
|
|
||||||
px = px != null ? px : 0;
|
|
||||||
py = py != null ? py : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
node.drawNode(realX + px - SPRITE_WIDTH / 4, realY + py - SPRITE_HEIGHT / 2, SPRITE_WIDTH, SPRITE_HEIGHT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ fn getRealPos(node: opaque) {
|
|||||||
|
|
||||||
//lifecycle functions
|
//lifecycle functions
|
||||||
fn onLoad(node: opaque) {
|
fn onLoad(node: opaque) {
|
||||||
node.loadTexture("sprites:/lejana.png");
|
node.loadNodeTexture("sprites:/lejana.png");
|
||||||
node.faceDown();
|
node.faceDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,22 +173,11 @@ fn onStep(node: opaque) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn onFree(node: opaque) {
|
fn onFree(node: opaque) {
|
||||||
node.freeTexture();
|
node.freeNodeTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn customOnDraw(node: opaque) {
|
fn customOnDraw(node: opaque, parentX: int, parentY: int) {
|
||||||
var px = 0;
|
node.drawNode(realX + parentX - SPRITE_WIDTH / 4, realY + parentY - SPRITE_HEIGHT / 2, SPRITE_WIDTH, SPRITE_HEIGHT);
|
||||||
var py = 0;
|
|
||||||
|
|
||||||
if (parent != null) {
|
|
||||||
px = parent.callNodeFn("getX");
|
|
||||||
py = parent.callNodeFn("getY");
|
|
||||||
|
|
||||||
px = px != null ? px : 0;
|
|
||||||
py = py != null ? py : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
node.drawNode(realX + px - SPRITE_WIDTH / 4, realY + py - SPRITE_HEIGHT / 2, SPRITE_WIDTH, SPRITE_HEIGHT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ var MAP_HEIGHT: int const = 16;
|
|||||||
|
|
||||||
var tilemap: opaque = null;
|
var tilemap: opaque = null;
|
||||||
var player: opaque = null;
|
var player: opaque = null;
|
||||||
|
var stepCounter: opaque = null;
|
||||||
|
|
||||||
var enemies: [opaque] = [];
|
var enemies: [opaque] = [];
|
||||||
|
|
||||||
@@ -22,24 +23,19 @@ var collisionMap: [bool] = null; //cache this, since it won't change during a le
|
|||||||
var rng: opaque = null;
|
var rng: opaque = null;
|
||||||
|
|
||||||
//debugging tools
|
//debugging tools
|
||||||
var stepCounter: int = 0;
|
var debugStepCounter: int = 0;
|
||||||
var drawCounter: int = 0;
|
var debugDrawCounter: int = 0;
|
||||||
|
|
||||||
var textNode: opaque = null;
|
|
||||||
|
|
||||||
//lifecycle functions
|
//lifecycle functions
|
||||||
fn onLoad(node: opaque) {
|
fn onLoad(node: opaque) {
|
||||||
tilemap = node.loadChild("scripts:/gameplay/tilemap.toy");
|
tilemap = node.loadChild("scripts:/gameplay/tilemap.toy");
|
||||||
player = node.loadChild("scripts:/gameplay/lejana.toy");
|
player = node.loadChild("scripts:/gameplay/lejana.toy");
|
||||||
textNode = node.loadChild("scripts:/empty.toy");
|
stepCounter = node.loadChild("scripts:/gameplay/step-counter.toy");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onInit(node: opaque) {
|
fn onInit(node: opaque) {
|
||||||
node.generateLevel(clock().hash(), MAP_WIDTH, MAP_HEIGHT);
|
node.generateLevel(clock().hash(), MAP_WIDTH, MAP_HEIGHT);
|
||||||
|
stepCounter.callNodeFn("setMaxSteps", 100);
|
||||||
//debugging
|
|
||||||
// textNode.setNodeText("fonts:/alphbeta.ttf", 48, "Hello world", 128, 0, 0, 255);
|
|
||||||
textNode.setNodeText("fonts:/Ancient God.ttf", 48, "Hello world", 128, 0, 0, 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onFree(node: opaque) {
|
fn onFree(node: opaque) {
|
||||||
@@ -47,23 +43,25 @@ fn onFree(node: opaque) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn onStep(node: opaque) {
|
fn onStep(node: opaque) {
|
||||||
if (++stepCounter >= 30) {
|
if (++debugStepCounter >= 30) {
|
||||||
print "FPS: " + string drawCounter + " / 30";
|
print "FPS: " + string debugDrawCounter + " / 30";
|
||||||
stepCounter = 0;
|
debugStepCounter = 0;
|
||||||
drawCounter = 0;
|
debugDrawCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
entities = entities.sort(depthComparator);
|
entities = entities.sort(depthComparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onDraw(node: opaque) {
|
fn onDraw(node: opaque) {
|
||||||
drawCounter++;
|
debugDrawCounter++;
|
||||||
|
|
||||||
//call each child's custom draw fn
|
//call each child's custom draw fn (with parent shifting)
|
||||||
tilemap.callNodeFn("customOnDraw");
|
tilemap.callNodeFn("customOnDraw", 0, 32);
|
||||||
for (var i = 0; i < entities.length(); i++) {
|
for (var i = 0; i < entities.length(); i++) {
|
||||||
entities[i].callNodeFn("customOnDraw");
|
entities[i].callNodeFn("customOnDraw", 0, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stepCounter.callNodeFn("customOnDraw", 0, 0, TILE_WIDTH * MAP_WIDTH, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
//utils - polyfills
|
//utils - polyfills
|
||||||
@@ -138,11 +136,17 @@ fn runAI(node: opaque) {
|
|||||||
for (var i = 0; i < enemies.length(); i++) {
|
for (var i = 0; i < enemies.length(); i++) {
|
||||||
enemies[i].callNodeFn("runAI", rng);
|
enemies[i].callNodeFn("runAI", rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stepCounter.callNodeFn("alterRemainingSteps", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn depthComparator(lhs: opaque, rhs: opaque) { //for sorting by depth
|
fn depthComparator(lhs: opaque, rhs: opaque) { //for sorting by depth
|
||||||
var lhsPos = lhs.callNodeFn("getRealPos");
|
var lhsPos = lhs.callNodeFn("getRealPos");
|
||||||
var rhsPos = rhs.callNodeFn("getRealPos");
|
var rhsPos = rhs.callNodeFn("getRealPos");
|
||||||
|
|
||||||
|
if (lhsPos[1] == rhsPos[1]) { //BUGFIX: prevent z-fighting
|
||||||
|
return lhsPos[0] < rhsPos[0];
|
||||||
|
}
|
||||||
|
|
||||||
return lhsPos[1] < rhsPos[1];
|
return lhsPos[1] < rhsPos[1];
|
||||||
}
|
}
|
||||||
67
assets/scripts/gameplay/step-counter.toy
Normal file
67
assets/scripts/gameplay/step-counter.toy
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import node;
|
||||||
|
|
||||||
|
//utils
|
||||||
|
var maxSteps: int = 0;
|
||||||
|
var remainingSteps: int = 0;
|
||||||
|
|
||||||
|
fn setMaxSteps(node: opaque, steps: int) {
|
||||||
|
maxSteps = steps;
|
||||||
|
remainingSteps = steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setRemainingSteps(node: opaque, steps: int) {
|
||||||
|
remainingSteps = steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn getMaxSteps(node: opaque) {
|
||||||
|
return maxSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn getRemainingSteps(node: opaque) {
|
||||||
|
return remainingSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn alterRemainingSteps(node: opaque, increment: int) {
|
||||||
|
remainingSteps += increment;
|
||||||
|
if (remainingSteps > maxSteps) {
|
||||||
|
remainingSteps = maxSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remainingSteps < 0) {
|
||||||
|
remainingSteps = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return remainingSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
//utils - polyfills
|
||||||
|
fn loadChild(parent: opaque, fname: string) {
|
||||||
|
var child: opaque = loadNode(fname);
|
||||||
|
parent.pushNode(child);
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
//lifecycle functions
|
||||||
|
fn onLoad(node: opaque) {
|
||||||
|
node.loadNodeTexture("sprites:/stepcounter.png");
|
||||||
|
|
||||||
|
node
|
||||||
|
.loadChild("scripts:/gameplay/text.toy")
|
||||||
|
.setNodeText("fonts:/alphbeta.ttf", 32, "Water", 0, 60, 240, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn onFree(node: opaque) {
|
||||||
|
node.freeNodeTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn customOnDraw(node: opaque, x: int, y: int, w: int, h: int) {
|
||||||
|
if (remainingSteps > 0 && maxSteps > 0) {
|
||||||
|
var tmp = float remainingSteps / maxSteps * w;
|
||||||
|
|
||||||
|
node.drawNode(x, y, int tmp, h);
|
||||||
|
|
||||||
|
for (var i: int = 0; i < node.getChildNodeCount(); i++) {
|
||||||
|
node.getChildNode(i).callNodeFn("customOnDraw", x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
assets/scripts/gameplay/text.toy
Normal file
9
assets/scripts/gameplay/text.toy
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import node;
|
||||||
|
|
||||||
|
fn customOnDraw(node: opaque, parentX: int, parentY: int) {
|
||||||
|
node.drawNode(parentX, parentY);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn onFree(node: opaque) {
|
||||||
|
node.freeNodeTexture();
|
||||||
|
}
|
||||||
@@ -50,10 +50,10 @@ var camH = 720;
|
|||||||
|
|
||||||
//lifecycle functions
|
//lifecycle functions
|
||||||
fn onLoad(node: opaque) {
|
fn onLoad(node: opaque) {
|
||||||
node.loadTexture("sprites:/tileset.png");
|
node.loadNodeTexture("sprites:/tileset.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn customOnDraw(node: opaque) {
|
fn customOnDraw(node: opaque, parentX: int, parentY: int) {
|
||||||
if (tilemap == null) {
|
if (tilemap == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ fn customOnDraw(node: opaque) {
|
|||||||
for (var i = lowerX; i < upperX; i++) {
|
for (var i = lowerX; i < upperX; i++) {
|
||||||
node.setNodeRect(tilemap[j * mapWidth * 2 + i * 2] * 16, tilemap[j * mapWidth * 2 + i * 2 + 1] * 16, 16, 16);
|
node.setNodeRect(tilemap[j * mapWidth * 2 + i * 2] * 16, tilemap[j * mapWidth * 2 + i * 2 + 1] * 16, 16, 16);
|
||||||
|
|
||||||
node.drawNode(i * TILE_WIDTH, j * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
|
node.drawNode(i * TILE_WIDTH + parentX, j * TILE_HEIGHT + parentY, TILE_WIDTH, TILE_HEIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
|
|
||||||
//this function must always be called, or the engine won't run
|
//this function must always be called, or the engine won't run
|
||||||
initWindow("Skyland", 32*16, 32*16, false); //TODO: custom FPS setting
|
initWindow("Skyland", 32*16, 32*16 + 32, false); //TODO: custom FPS setting
|
||||||
|
|
||||||
//kick off the logic of the scene graph
|
//kick off the logic of the scene graph
|
||||||
loadRootNode("scripts:/gameplay/scene.toy");
|
loadRootNode("scripts:/gameplay/scene.toy");
|
||||||
|
|||||||
BIN
assets/sprites/stepcounter.png
Normal file
BIN
assets/sprites/stepcounter.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 160 B |
@@ -437,8 +437,8 @@ void Box_execEngine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//render the world
|
//render the world
|
||||||
//SDL_SetRenderDrawColor(engine.renderer, 128, 128, 128, 255); //NOTE: This line can be disabled later
|
SDL_SetRenderDrawColor(engine.renderer, 128, 128, 128, 255); //NOTE: This line can be disabled later
|
||||||
//SDL_RenderClear(engine.renderer); //NOTE: This line can be disabled later
|
SDL_RenderClear(engine.renderer); //NOTE: This line can be disabled later
|
||||||
|
|
||||||
Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onDraw", NULL);
|
Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onDraw", NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -330,9 +330,9 @@ static int nativeGetChildNodeCount(Toy_Interpreter* interpreter, Toy_LiteralArra
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nativeLoadTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
static int nativeLoadNodeTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
if (arguments->count != 2) {
|
if (arguments->count != 2) {
|
||||||
interpreter->errorOutput("Incorrect number of arguments passed to loadTexture\n");
|
interpreter->errorOutput("Incorrect number of arguments passed to loadNodeTexture\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,7 +352,7 @@ static int nativeLoadTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
|
|||||||
|
|
||||||
//check argument types
|
//check argument types
|
||||||
if (!TOY_IS_STRING(drivePathLiteral) || !TOY_IS_OPAQUE(nodeLiteral)) {
|
if (!TOY_IS_STRING(drivePathLiteral) || !TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
interpreter->errorOutput("Incorrect argument type passed to loadTexture\n");
|
interpreter->errorOutput("Incorrect argument type passed to loadNodeTexture\n");
|
||||||
Toy_freeLiteral(drivePathLiteral);
|
Toy_freeLiteral(drivePathLiteral);
|
||||||
Toy_freeLiteral(nodeLiteral);
|
Toy_freeLiteral(nodeLiteral);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -389,9 +389,9 @@ static int nativeLoadTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nativeFreeTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
static int nativeFreeNodeTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
if (arguments->count != 1) {
|
if (arguments->count != 1) {
|
||||||
interpreter->errorOutput("Incorrect number of arguments passed to freeTexture\n");
|
interpreter->errorOutput("Incorrect number of arguments passed to freeNodeTexture\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,7 +405,7 @@ static int nativeFreeTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
|
|||||||
|
|
||||||
//check argument types
|
//check argument types
|
||||||
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
interpreter->errorOutput("Incorrect argument type passed to freeTexture\n");
|
interpreter->errorOutput("Incorrect argument type passed to freeNodeTexture\n");
|
||||||
Toy_freeLiteral(nodeLiteral);
|
Toy_freeLiteral(nodeLiteral);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -970,8 +970,8 @@ int Box_hookNode(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Liter
|
|||||||
{"freeChildNode", nativeFreeChildNode},
|
{"freeChildNode", nativeFreeChildNode},
|
||||||
{"getParentNode", nativeGetParentNode},
|
{"getParentNode", nativeGetParentNode},
|
||||||
{"getChildNodeCount", nativeGetChildNodeCount},
|
{"getChildNodeCount", nativeGetChildNodeCount},
|
||||||
{"loadTexture", nativeLoadTexture},
|
{"loadNodeTexture", nativeLoadNodeTexture},
|
||||||
{"freeTexture", nativeFreeTexture},
|
{"freeNodeTexture", nativeFreeNodeTexture},
|
||||||
{"setNodeRect", nativeSetNodeRect},
|
{"setNodeRect", nativeSetNodeRect},
|
||||||
//get rect
|
//get rect
|
||||||
{"setNodeFrames", nativeSetNodeFrames},
|
{"setNodeFrames", nativeSetNodeFrames},
|
||||||
@@ -983,7 +983,7 @@ int Box_hookNode(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Liter
|
|||||||
{"setNodeText", nativeSetNodeText},
|
{"setNodeText", nativeSetNodeText},
|
||||||
{"callNodeFn", nativeCallNodeFn},
|
{"callNodeFn", nativeCallNodeFn},
|
||||||
|
|
||||||
//TODO: get rect, get node var, create empty node
|
//TODO: get rect, get node var, create empty node, set node color (tinting)
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user