Drones working
This commit is contained in:
@@ -17,8 +17,8 @@ var parent: opaque = null; //cache the parent for quick access
|
||||
var gridX: int = 1; //position on the game grid
|
||||
var gridY: int = 1;
|
||||
|
||||
var realX: int = 0; //will change until realX = gridX * SPRITE_WIDTH
|
||||
var realY: int = 0;
|
||||
var realX: int = null; //will change until realX = gridX * SPRITE_WIDTH
|
||||
var realY: int = null;
|
||||
|
||||
var motionX: int = 0; //normalized movement direction
|
||||
var motionY: int = 0;
|
||||
@@ -27,6 +27,7 @@ var inputX: int = 0; //cache the keyboard input
|
||||
var inputY: int = 0;
|
||||
|
||||
var direction: int = null; //BUGFIX: animation not looping properly
|
||||
var enableMovementCounter: int = 60 * 4; //BUGFIX: freeze while drones reach their starting spot
|
||||
|
||||
|
||||
//polyfills - animating different cycles on one image
|
||||
@@ -46,13 +47,6 @@ fn faceUp(node: opaque) {
|
||||
node.setNodeFrames(4);
|
||||
}
|
||||
|
||||
fn faceLeft(node: opaque) {
|
||||
if (direction == 3) return;
|
||||
direction = 3;
|
||||
node.setNodeRect(32 * 12, 0, 32, 32);
|
||||
node.setNodeFrames(4);
|
||||
}
|
||||
|
||||
fn faceRight(node: opaque) {
|
||||
if (direction == 2) return;
|
||||
direction = 2;
|
||||
@@ -60,15 +54,39 @@ fn faceRight(node: opaque) {
|
||||
node.setNodeFrames(4);
|
||||
}
|
||||
|
||||
//polyfills - move these to standard
|
||||
fn normalize(x): int {
|
||||
if (x > 0) {
|
||||
return 1;
|
||||
fn faceLeft(node: opaque) {
|
||||
if (direction == 3) return;
|
||||
direction = 3;
|
||||
node.setNodeRect(32 * 12, 0, 32, 32);
|
||||
node.setNodeFrames(4);
|
||||
}
|
||||
|
||||
|
||||
//accessors & mutators
|
||||
fn setGridPos(node: opaque, x: int, y: int) {
|
||||
gridX = x;
|
||||
gridY = y;
|
||||
|
||||
if (realX == null) {
|
||||
realX = gridX * TILE_WIDTH;
|
||||
}
|
||||
if (x < 0) {
|
||||
return -1;
|
||||
|
||||
if (realY == null) {
|
||||
realY = gridY * TILE_HEIGHT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn setRealPos(node: opaque, x: int, y: int) {
|
||||
realX = x;
|
||||
realY = y;
|
||||
}
|
||||
|
||||
fn getGridPos(node: opaque) {
|
||||
return [gridX, gridY];
|
||||
}
|
||||
|
||||
fn getRealPos(node: opaque) {
|
||||
return [realX, realY];
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +101,12 @@ fn onInit(node: opaque) {
|
||||
}
|
||||
|
||||
fn onStep(node: opaque) {
|
||||
//initial freeze
|
||||
if (enableMovementCounter > 0) {
|
||||
enableMovementCounter--;
|
||||
return;
|
||||
}
|
||||
|
||||
//process input when aligned to a grid
|
||||
if (realX / TILE_WIDTH == gridX && realY / TILE_HEIGHT == gridY && motionX == 0 && motionY == 0) {
|
||||
//disallow wall phasing
|
||||
@@ -118,6 +142,11 @@ fn onStep(node: opaque) {
|
||||
if (inputX < 0) {
|
||||
node.faceLeft();
|
||||
}
|
||||
|
||||
//trigger the world
|
||||
if (inputX != 0 || inputY != 0) {
|
||||
parent.callNodeFn("runAI");
|
||||
}
|
||||
}
|
||||
|
||||
//animation
|
||||
@@ -147,7 +176,7 @@ fn onFree(node: opaque) {
|
||||
node.freeTexture();
|
||||
}
|
||||
|
||||
fn onDraw(node: opaque) {
|
||||
fn customOnDraw(node: opaque) {
|
||||
var px = 0;
|
||||
var py = 0;
|
||||
|
||||
@@ -162,6 +191,7 @@ fn onDraw(node: opaque) {
|
||||
node.drawNode(realX + px - SPRITE_WIDTH / 4, realY + py - SPRITE_HEIGHT / 2, SPRITE_WIDTH, SPRITE_HEIGHT);
|
||||
}
|
||||
|
||||
|
||||
//event functions
|
||||
fn onKeyDown(node: opaque, event: string) {
|
||||
if (event == "character_up") {
|
||||
@@ -205,4 +235,16 @@ fn onKeyUp(node: opaque, event: string) {
|
||||
inputX = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//polyfills - move these to standard
|
||||
fn normalize(x): int {
|
||||
if (x > 0) {
|
||||
return 1;
|
||||
}
|
||||
if (x < 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user