Replaced polyfills with real implementations
This commit is contained in:
2
Box
2
Box
Submodule Box updated: 9cd78b3637...4297e15959
@@ -1,39 +1,32 @@
|
|||||||
//A quirk of the setup is that anything defined in the root of `init.toy` becomes a global object
|
import engine;
|
||||||
//To resolve that, the configuration is inside a block scope
|
import input;
|
||||||
{
|
|
||||||
import engine;
|
|
||||||
import input;
|
|
||||||
|
|
||||||
|
|
||||||
//input settings, mapping SDL2's virtual keys to event names
|
//input settings, mapping SDL2's virtual keys to event names
|
||||||
mapInputEventToKeyDown("character_up", "w"); //event, keysym
|
mapInputEventToKeyDown("character_up", "w"); //event, keysym
|
||||||
mapInputEventToKeyDown("character_left", "a"); //event, keysym
|
mapInputEventToKeyDown("character_left", "a"); //event, keysym
|
||||||
mapInputEventToKeyDown("character_down", "s"); //event, keysym
|
mapInputEventToKeyDown("character_down", "s"); //event, keysym
|
||||||
mapInputEventToKeyDown("character_right", "d"); //event, keysym
|
mapInputEventToKeyDown("character_right", "d"); //event, keysym
|
||||||
|
|
||||||
mapInputEventToKeyUp("character_up", "w"); //event, keysym
|
mapInputEventToKeyUp("character_up", "w"); //event, keysym
|
||||||
mapInputEventToKeyUp("character_left", "a"); //event, keysym
|
mapInputEventToKeyUp("character_left", "a"); //event, keysym
|
||||||
mapInputEventToKeyUp("character_down", "s"); //event, keysym
|
mapInputEventToKeyUp("character_down", "s"); //event, keysym
|
||||||
mapInputEventToKeyUp("character_right", "d"); //event, keysym
|
mapInputEventToKeyUp("character_right", "d"); //event, keysym
|
||||||
|
|
||||||
mapInputEventToKeyDown("character_up", "up"); //event, keysym
|
mapInputEventToKeyDown("character_up", "up"); //event, keysym
|
||||||
mapInputEventToKeyDown("character_left", "left"); //event, keysym
|
mapInputEventToKeyDown("character_left", "left"); //event, keysym
|
||||||
mapInputEventToKeyDown("character_down", "down"); //event, keysym
|
mapInputEventToKeyDown("character_down", "down"); //event, keysym
|
||||||
mapInputEventToKeyDown("character_right", "right"); //event, keysym
|
mapInputEventToKeyDown("character_right", "right"); //event, keysym
|
||||||
|
|
||||||
mapInputEventToKeyUp("character_up", "up"); //event, keysym
|
mapInputEventToKeyUp("character_up", "up"); //event, keysym
|
||||||
mapInputEventToKeyUp("character_left", "left"); //event, keysym
|
mapInputEventToKeyUp("character_left", "left"); //event, keysym
|
||||||
mapInputEventToKeyUp("character_down", "down"); //event, keysym
|
mapInputEventToKeyUp("character_down", "down"); //event, keysym
|
||||||
mapInputEventToKeyUp("character_right", "right"); //event, keysym
|
mapInputEventToKeyUp("character_right", "right"); //event, keysym
|
||||||
|
|
||||||
mapInputEventToKeyDown("character_attack", "space"); //event, keysym
|
mapInputEventToKeyDown("character_attack", "space"); //event, keysym
|
||||||
|
|
||||||
//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("Airport", 800, 600, false);
|
initWindow("Airport", 800, 600, false);
|
||||||
|
|
||||||
//kick off the logic of the scene graph
|
|
||||||
loadRootNode("airport:/airplane.toy");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Globals go here
|
|
||||||
|
|
||||||
|
//kick off the logic of the scene graph
|
||||||
|
loadRootNode("airport:/airplane.toy");
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
//this file is a polyfill TODO: fix this
|
|
||||||
@@ -23,7 +23,7 @@ var stepAI: int = 0;
|
|||||||
var health: int = 2;
|
var health: int = 2;
|
||||||
var requestFree: bool = false;
|
var requestFree: bool = false;
|
||||||
|
|
||||||
//polyfills - animating different cycles on one image
|
//animating different cycles on one image
|
||||||
var walkAnimationCounter: int = 0;
|
var walkAnimationCounter: int = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ fn isRequestingFree(node: opaque) {
|
|||||||
if (requestFree) {
|
if (requestFree) {
|
||||||
var parent = node.getParentNode();
|
var parent = node.getParentNode();
|
||||||
|
|
||||||
var explosion: opaque = parent.loadChild("scripts:/entities/explosion.toy");
|
var explosion: opaque = parent.loadChildNode("scripts:/entities/explosion.toy");
|
||||||
explosion.callNodeFn("setGridPosition", gridPositionX, gridPositionY);
|
explosion.callNodeFn("setGridPosition", gridPositionX, gridPositionY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -161,22 +161,3 @@ fn faceDirection(node: opaque, dir: int) {
|
|||||||
node.setNodeFrames(2);
|
node.setNodeFrames(2);
|
||||||
walkAnimationCounter = 12;
|
walkAnimationCounter = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//polyfills - move these to standard
|
|
||||||
fn normalize(x): int {
|
|
||||||
if (x > 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (x < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn loadChild(parent: opaque, fname: string) {
|
|
||||||
//TODO: add this to the API proper
|
|
||||||
var child: opaque = loadNode(fname);
|
|
||||||
parent.pushNode(child);
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,7 @@ var TILE_PIXEL_HEIGHT: int const = 16;
|
|||||||
var gridPositionX: int = null;
|
var gridPositionX: int = null;
|
||||||
var gridPositionY: int = null;
|
var gridPositionY: int = null;
|
||||||
|
|
||||||
//polyfills - animating different cycles on one image
|
//animating different cycles on one image
|
||||||
var walkAnimationCounter: int = 0;
|
var walkAnimationCounter: int = 0;
|
||||||
var ticksToDeath: int = 4 * 8 - 1;
|
var ticksToDeath: int = 4 * 8 - 1;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ var direction: int = null; //BUGFIX: animation not looping properly
|
|||||||
var attackPositionX: int = null;
|
var attackPositionX: int = null;
|
||||||
var attackPositionY: int = null;
|
var attackPositionY: int = null;
|
||||||
|
|
||||||
//polyfills - animating different cycles on one image
|
//animating different cycles on one image
|
||||||
var walkAnimationCounter: int = 0;
|
var walkAnimationCounter: int = 0;
|
||||||
var attackAnimationCounter: int = 0;
|
var attackAnimationCounter: int = 0;
|
||||||
|
|
||||||
@@ -272,14 +272,3 @@ fn faceDirection(node: opaque, dir: int) {
|
|||||||
node.setNodeFrames(4);
|
node.setNodeFrames(4);
|
||||||
walkAnimationCounter = 12;
|
walkAnimationCounter = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
//polyfills - move these to standard
|
|
||||||
fn normalize(x): int {
|
|
||||||
if (x > 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (x < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -29,7 +29,7 @@ fn onInit(node: opaque) {
|
|||||||
node.generateLevel(rng);
|
node.generateLevel(rng);
|
||||||
|
|
||||||
//generate the child node to render the map
|
//generate the child node to render the map
|
||||||
var renderer: opaque = node.loadChild("scripts:/tilemap/renderer.toy");
|
var renderer: opaque = node.loadChildNode("scripts:/tilemap/renderer.toy");
|
||||||
renderer.callNodeFn("setTilemap", tilemap);
|
renderer.callNodeFn("setTilemap", tilemap);
|
||||||
|
|
||||||
//load the music
|
//load the music
|
||||||
@@ -102,7 +102,7 @@ fn generateLevel(node: opaque, rng: opaque) {
|
|||||||
|
|
||||||
|
|
||||||
//spawn && position the player
|
//spawn && position the player
|
||||||
player = node.loadChild("scripts:/entities/player.toy");
|
player = node.loadChildNode("scripts:/entities/player.toy");
|
||||||
|
|
||||||
var w: int const = metadata.length();
|
var w: int const = metadata.length();
|
||||||
var h: int const = metadata[0].length();
|
var h: int const = metadata[0].length();
|
||||||
@@ -124,7 +124,7 @@ fn generateLevel(node: opaque, rng: opaque) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var drone: opaque = node.loadChild("scripts:/entities/drone.toy");
|
var drone: opaque = node.loadChildNode("scripts:/entities/drone.toy");
|
||||||
drone.callNodeFn("setGridPosition", room["x"] + x, room["y"] + y);
|
drone.callNodeFn("setGridPosition", room["x"] + x, room["y"] + y);
|
||||||
|
|
||||||
//increment here
|
//increment here
|
||||||
@@ -201,12 +201,3 @@ fn depthComparator(lhs: opaque, rhs: opaque) {
|
|||||||
|
|
||||||
return lhsPositionY < rhsPositionY;
|
return lhsPositionY < rhsPositionY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//polyfills
|
|
||||||
fn loadChild(parent: opaque, fname: string) {
|
|
||||||
//TODO: add this to the API proper
|
|
||||||
var child: opaque = loadNode(fname);
|
|
||||||
parent.pushNode(child);
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
@@ -555,10 +555,4 @@ fn generateSnapshotAt(x: int, y: int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//polyfill
|
|
||||||
fn sign(x) {
|
|
||||||
if (x > 0) return 1;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
@@ -34,7 +34,7 @@ fn setTilemap(node: opaque, t: [int]) {
|
|||||||
tilemap = t;
|
tilemap = t;
|
||||||
|
|
||||||
//create a child as a render target
|
//create a child as a render target
|
||||||
var child = node.loadChild("scripts:/tilemap/renderer-child.toy");
|
var child = node.loadChildNode("scripts:/tilemap/renderer-child.toy");
|
||||||
child.createNodeTexture(CELL_WIDTH * CELL_COUNT_X * TILE_PIXEL_WIDTH, CELL_HEIGHT * CELL_COUNT_Y * TILE_PIXEL_HEIGHT);
|
child.createNodeTexture(CELL_WIDTH * CELL_COUNT_X * TILE_PIXEL_WIDTH, CELL_HEIGHT * CELL_COUNT_Y * TILE_PIXEL_HEIGHT);
|
||||||
setRenderTarget(child);
|
setRenderTarget(child);
|
||||||
|
|
||||||
@@ -66,11 +66,3 @@ fn setTilemap(node: opaque, t: [int]) {
|
|||||||
//reset the render target to the screen
|
//reset the render target to the screen
|
||||||
setRenderTarget(null);
|
setRenderTarget(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//polyfills
|
|
||||||
fn loadChild(parent: opaque, fname: string) {
|
|
||||||
//TODO: add this to the API proper
|
|
||||||
var child: opaque = loadNode(fname);
|
|
||||||
parent.pushNode(child);
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user