diff --git a/Box b/Box index 888b7e2..ac7dd38 160000 --- a/Box +++ b/Box @@ -1 +1 @@ -Subproject commit 888b7e27baae8a54effb4ea4a97ef39a8441da40 +Subproject commit ac7dd38bdb29cff26c17815a0ed7e48763296bab diff --git a/assets/airport-demo/airplane.toy b/assets/airport-demo/airplane.toy index 9c50c55..32f50a2 100644 --- a/assets/airport-demo/airplane.toy +++ b/assets/airport-demo/airplane.toy @@ -15,12 +15,12 @@ fn onLoad(node: opaque) { fn onInit(node: opaque) { print "onInit() called"; - node.loadNodeTexture("sprites:/little_plane.png"); + node.loadNodeTexture("airport:/little_plane.png"); } -fn onStep(node: opaque) { - //TODO: move -} +// fn onStep(node: opaque) { +// // +// } fn onFree(node: opaque) { print "onFree() called"; @@ -30,18 +30,8 @@ fn onFree(node: opaque) { fn onDraw(node: opaque) { // print "onDraw() called"; - var parent: opaque = node.getParentNode(); - var px = 0; - var py = 0; - - //TODO: get world position - if (parent != null) { - px = parent.getNodePositionX(); - py = parent.getNodePositionY(); - } - - node.drawNode(node.getNodePositionX() + px, node.getNodePositionY() + py, WIDTH, HEIGHT); + node.drawNode(node.getNodeWorldPositionX(), node.getNodeWorldPositionY(), WIDTH, HEIGHT); } //event functions diff --git a/assets/airport-demo/init.toy b/assets/airport-demo/init.toy index 242f0e1..27c54fc 100644 --- a/assets/airport-demo/init.toy +++ b/assets/airport-demo/init.toy @@ -28,14 +28,11 @@ mapInputEventToKeyDown("character_attack", "space"); //event, keysym - //TODO: escape to kill the game - - //this function must always be called, or the engine won't run - initWindow("Airport", 800, 600, false); //TODO: custom FPS setting + initWindow("Airport", 800, 600, false); //kick off the logic of the scene graph - loadRootNode("scripts:/airplane.toy"); + loadRootNode("airport:/airplane.toy"); } //Globals go here diff --git a/assets/scripts/gameplay/drone.toy b/assets/scripts/gameplay/drone.toy index 5fbf047..5e85334 100644 --- a/assets/scripts/gameplay/drone.toy +++ b/assets/scripts/gameplay/drone.toy @@ -103,8 +103,8 @@ fn onDraw(node: opaque) { var originOffsetY: int = node.getNodeRectH() * int scaleY / 2; node.drawNode( - floor(posX * scaleX) - originOffsetX, - floor(posY * scaleY) - originOffsetY, + floor(posX * scaleX) - originOffsetX + globalCameraX, + floor(posY * scaleY) - originOffsetY + globalCameraY, floor(node.getNodeRectW() * scaleX), floor(node.getNodeRectH() * scaleY) ); diff --git a/assets/scripts/gameplay/lejana.toy b/assets/scripts/gameplay/lejana.toy index 26ffefc..f716ffd 100644 --- a/assets/scripts/gameplay/lejana.toy +++ b/assets/scripts/gameplay/lejana.toy @@ -169,12 +169,12 @@ fn onDraw(node: opaque) { var scaleY: float = node.getNodeWorldScaleY(); //this offset is because the sprite cell for lejana is twice as big as the sprite cell for the floor tiles - var originOffsetX: int = node.getNodeRectW() * int scaleX / 4; - var originOffsetY: int = node.getNodeRectH() * int scaleY / 2; + var originOffsetX: int = player.getNodeRectW() / 2; + var originOffsetY: int = player.getNodeRectH(); node.drawNode( - floor(posX * scaleX) - originOffsetX, - floor(posY * scaleY) - originOffsetY, + floor(posX * scaleX) - originOffsetX + globalCameraX, + floor(posY * scaleY) - originOffsetY + globalCameraY, floor(node.getNodeRectW() * scaleX), floor(node.getNodeRectH() * scaleY) ); diff --git a/assets/scripts/gameplay/scene.toy b/assets/scripts/gameplay/scene.toy index d3b85e8..6c8d7ab 100644 --- a/assets/scripts/gameplay/scene.toy +++ b/assets/scripts/gameplay/scene.toy @@ -21,13 +21,9 @@ fn onInit(node: opaque) { //load and initialize the UI (depends on map stuff) stepCounter = node.loadChild("scripts:/gameplay/step-counter.toy"); - stepCounter.setNodeRect( - 0, - 0, - floor(TILE_PIXEL_WIDTH * MAP_GRID_WIDTH * tilemap.getNodeWorldScaleX()), //width - stretches along the top of the tilemap - stepCounter.getNodeRectH() //default height - ); + stepCounter.setNodeRect(0, 0, CAMERA_SCREEN_W, 32); stepCounter.callNodeFn("setMaxSteps", 100); + stepCounter.setNodeLayer(100); //offset the scene node, so it shows the map outside separate from the UI node.setNodePositionY(16); @@ -47,6 +43,17 @@ fn onFree(node: opaque) { fn onDraw(node: opaque) { //use the onDraw to sort - skip too many steps node.sortChildrenNode(depthComparator); + + var scaleX: float = player.getNodeWorldScaleX(); + var scaleY: float = player.getNodeWorldScaleY(); + + //this offset is because the sprite cell for lejana is twice as big as the sprite cell for the floor tiles + var originOffsetX: int = player.getNodeRectW() / 2; + var originOffsetY: int = player.getNodeRectH() / 2; + + //use the room scene's onDraw to set the global camera position + globalCameraX = floor((CAMERA_SCREEN_W / 2) - (player.getNodeWorldPositionX() * scaleX)) - originOffsetX; + globalCameraY = floor((CAMERA_SCREEN_H / 2) - (player.getNodeWorldPositionY() * scaleY)) - originOffsetY; } //gameplay functions diff --git a/assets/scripts/gameplay/step-counter.toy b/assets/scripts/gameplay/step-counter.toy index 642388a..24c3312 100644 --- a/assets/scripts/gameplay/step-counter.toy +++ b/assets/scripts/gameplay/step-counter.toy @@ -41,6 +41,7 @@ fn alterRemainingSteps(node: opaque, increment: int) { fn loadChild(parent: opaque, fname: string) { var child: opaque = loadNode(fname); parent.pushNode(child); + child.setNodeLayer(parent.getNodeLayer()); return child; } diff --git a/assets/scripts/gameplay/tilemap.toy b/assets/scripts/gameplay/tilemap.toy index 9ee4372..8f92adb 100644 --- a/assets/scripts/gameplay/tilemap.toy +++ b/assets/scripts/gameplay/tilemap.toy @@ -76,8 +76,8 @@ fn onDraw(node: opaque) { //draw to the screen node.drawNode( - floor((i * TILE_PIXEL_WIDTH + posX) * scaleX), - floor((j * TILE_PIXEL_HEIGHT + posY) * scaleY), + floor((i * TILE_PIXEL_WIDTH + posX) * scaleX) + globalCameraX, + floor((j * TILE_PIXEL_HEIGHT + posY) * scaleY) + globalCameraY, floor(TILE_PIXEL_WIDTH * scaleX), floor(TILE_PIXEL_HEIGHT * scaleY) ); diff --git a/assets/scripts/init.toy b/assets/scripts/init.toy index 793ca11..69884eb 100644 --- a/assets/scripts/init.toy +++ b/assets/scripts/init.toy @@ -5,10 +5,15 @@ var TILE_PIXEL_HEIGHT: int const = 16; var MAP_GRID_WIDTH: int const = 16; var MAP_GRID_HEIGHT: int const = 16; +var CAMERA_SCREEN_W: int const = 800; +var CAMERA_SCREEN_H: int const = 600; + var CAMERA_SCALE_X: float const = 2.0; var CAMERA_SCALE_Y: float const = 2.0; - +//this is a very odd pattern... +var globalCameraX: int = 0; +var globalCameraY: int = 0; //A quirk of the setup is that anything defined in the root of `init.toy` becomes a global object //To resolve that, the configuration is inside a block scope @@ -45,12 +50,7 @@ var CAMERA_SCALE_Y: float const = 2.0; //this function must always be called, or the engine won't run - initWindow( - "Airport", - floor(TILE_PIXEL_WIDTH * MAP_GRID_WIDTH * CAMERA_SCALE_X), - floor(TILE_PIXEL_HEIGHT * MAP_GRID_HEIGHT * CAMERA_SCALE_Y) + 32, //32 is UI space - false); - //TODO: custom FPS setting + initWindow("Skylands", CAMERA_SCREEN_W, CAMERA_SCREEN_H, false); //TODO: custom FPS setting //kick off the logic of the scene graph loadRootNode("scripts:/gameplay/scene.toy"); diff --git a/source/main.c b/source/main.c index 00275bf..95341f9 100644 --- a/source/main.c +++ b/source/main.c @@ -1,5 +1,4 @@ #include "box_engine.h" -#include "toy_drive_system.h" int main(int argc, char* argv[]) { //debugging tools @@ -8,9 +7,10 @@ int main(int argc, char* argv[]) { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif//win32 && debug - //the drive system uses a LiteralDictionary, which must be initialized with this + //the drive system maps filepaths to "drives", which specifies which folders can be accessed by the scripts Toy_initDriveSystem(); + // Toy_setDrivePath("airport", "assets/airport-demo"); //DEBUG Toy_setDrivePath("scripts", "assets/scripts"); Toy_setDrivePath("sprites", "assets/sprites"); Toy_setDrivePath("fonts", "assets/fonts");