Moved polyfills into standard library

This commit is contained in:
2023-02-27 22:09:46 +11:00
parent 22ab705903
commit f9b154c12e
6 changed files with 352 additions and 152 deletions

View File

@@ -28,4 +28,4 @@ mapInputEventToKeyUp("character_right", "right"); //event, keysym
initWindow("Airport Game", 1080, 720, false);
//kick off the logic of the scene graph
loadRootNode("scripts:/frames.toy");
loadRootNode("scripts:/scene.toy");

View File

@@ -5,11 +5,11 @@ import node;
var childCounter: int = 0;
//TODO: reference these from a global source (root?)
var tileWidth: float const = 100;
var tileHeight: float const = 100;
var tileWidth: int const = 100;
var tileHeight: int const = 100;
var roomWidth: float const = 10;
var roomHeight: float const = 10;
var roomWidth: int const = 10;
var roomHeight: int const = 10;
var levelXCount: int const = 4;
var levelYCount: int const = 4;
@@ -40,16 +40,16 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
//calc the modifier ratio to offset things
var mod: float = float tileWidth / (tileWidth - depth);
var tileWidth_mod = round(tileWidth * mod);
var tileHeight_mod = round(tileHeight * mod);
var camX_mod = (camX - camW) * mod + camW / 2;
var camY_mod = (camY - camH) * mod + camH / 2;
var tileWidth_mod: int = round(tileWidth * mod);
var tileHeight_mod: int = round(tileHeight * mod);
var camX_mod: int = round((camX - camW) * mod + camW / 2);
var camY_mod: int = round((camY - camH) * mod + camH / 2);
//calc the region to render
var lowerX = round((camX - camW/2) / tileWidth);
var upperX = round((camX - camW*1.5) / tileWidth);
var lowerY = round((camY - camH/2) / tileHeight);
var upperY = round((camY - camH*1.5) / tileHeight);
var lowerX: int = round((camX - camW/2) / tileWidth);
var upperX: int = round((camX - camW*1.5) / tileWidth);
var lowerY: int = round((camY - camH/2) / tileHeight);
var upperY: int = round((camY - camH*1.5) / tileHeight);
//bounds check
lowerX = max(0, abs(lowerX));
@@ -64,26 +64,3 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
}
}
}
//math utils
fn round(x): int {
var f = floor(x);
return x - f >= 0.5 ? f + 1 : f;
}
fn floor(x): int {
return int x;
}
fn ceil(x): int {
var f = floor(x);
return x - f != 0 ? f + 1 : f;
}
fn min(a, b) {
return a < b ? a : b;
}
fn max(a, b) {
return a > b ? a : b;
}

View File

@@ -5,11 +5,11 @@ import node;
var childCounter: int = 0;
//TODO: reference these from a global source (root?)
var tileWidth: float const = 100;
var tileHeight: float const = 100;
var tileWidth: int const = 100;
var tileHeight: int const = 100;
var roomWidth: float const = 10;
var roomHeight: float const = 10;
var roomWidth: int const = 10;
var roomHeight: int const = 10;
var levelXCount: int const = 4;
var levelYCount: int const = 4;
@@ -40,16 +40,16 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
//calc the modifier ratio to offset things
var mod: float = float tileWidth / (tileWidth - depth);
var tileWidth_mod = round(tileWidth * mod);
var tileHeight_mod = round(tileHeight * mod);
var camX_mod = (camX - camW) * mod + camW / 2;
var camY_mod = (camY - camH) * mod + camH / 2;
var tileWidth_mod: int = round(tileWidth * mod);
var tileHeight_mod: int = round(tileHeight * mod);
var camX_mod: int = round((camX - camW) * mod + camW / 2);
var camY_mod: int = round((camY - camH) * mod + camH / 2);
//calc the region to render
var lowerX = round((camX - camW/2) / tileWidth);
var upperX = round((camX - camW*1.5) / tileWidth);
var lowerY = round((camY - camH/2) / tileHeight);
var upperY = round((camY - camH*1.5) / tileHeight);
var lowerX: int = round((camX - camW/2) / tileWidth);
var upperX: int = round((camX - camW*1.5) / tileWidth);
var lowerY: int = round((camY - camH/2) / tileHeight);
var upperY: int = round((camY - camH*1.5) / tileHeight);
//bounds check
lowerX = max(0, abs(lowerX));
@@ -68,27 +68,3 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
}
}
}
//math utils
fn round(x): int {
var f = floor(x);
return x - f >= 0.5 ? f + 1 : f;
}
fn floor(x): int {
return int x;
}
fn ceil(x): int {
var f = floor(x);
return x - f != 0 ? f + 1 : f;
}
fn min(a, b) {
return a < b ? a : b;
}
fn max(a, b) {
return a > b ? a : b;
}

View File

@@ -5,21 +5,21 @@ import node;
//TODO: get child count
var childCounter: int = 0;
var levelXCount: int const = 4;
var levelYCount: int const = 4;
var camX: float = 0;
var camY: float = 0;
//TODO: reference these from a global source (root?)
var tileWidth: float const = 100;
var tileHeight: float const = 100;
var tileWidth: int const = 100;
var tileHeight: int const = 100;
var roomWidth: float const = 10;
var roomHeight: float const = 10;
var roomWidth: int const = 10;
var roomHeight: int const = 10;
var screenWidth: float = 1080;
var screenHeight: float = 720;
var levelXCount: int const = 4;
var levelYCount: int const = 4;
var screenWidth: int const = 1080;
var screenHeight: int const = 720;
//util to generate and init a child node of a given parent
@@ -53,26 +53,3 @@ fn onDraw(node: opaque) {
node.getChildNode(c).callNodeFn("drawLayer", camX, camY, screenWidth, screenHeight, c * 2);
}
}
//math utils
fn round(x): int {
var f = floor(x);
return x - f >= 0.5 ? f + 1 : f;
}
fn floor(x): int {
return int x;
}
fn ceil(x): int {
var f = floor(x);
return x - f != 0 ? f + 1 : f;
}
fn min(a, b) {
return a < b ? a : b;
}
fn max(a, b) {
return a > b ? a : b;
}