Added lejana's kick animation
This commit is contained in:
@@ -28,7 +28,7 @@ var inputY: int = 0;
|
|||||||
|
|
||||||
var direction: int = null; //BUGFIX: animation not looping properly
|
var direction: int = null; //BUGFIX: animation not looping properly
|
||||||
var enableMovementCounter: int = 30 * 3; //BUGFIX: freeze while drones reach their starting spot
|
var enableMovementCounter: int = 30 * 3; //BUGFIX: freeze while drones reach their starting spot
|
||||||
|
var attackCounter: int = 0;
|
||||||
|
|
||||||
//polyfills - animating different cycles on one image
|
//polyfills - animating different cycles on one image
|
||||||
var stepCount: int = 0;
|
var stepCount: int = 0;
|
||||||
@@ -109,23 +109,6 @@ fn onStep(node: opaque) {
|
|||||||
|
|
||||||
//process input when aligned to a grid
|
//process input when aligned to a grid
|
||||||
if (realX / TILE_WIDTH == gridX && realY / TILE_HEIGHT == gridY && motionX == 0 && motionY == 0) {
|
if (realX / TILE_WIDTH == gridX && realY / TILE_HEIGHT == gridY && motionX == 0 && motionY == 0) {
|
||||||
//disallow wall phasing
|
|
||||||
if (inputX != 0 && parent.callNodeFn("getCollisionAt", gridX + inputX, gridY) != true) {
|
|
||||||
inputX = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputY != 0 && parent.callNodeFn("getCollisionAt", gridX, gridY + inputY) != true) {
|
|
||||||
inputY = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//disallow diagonal movement
|
|
||||||
if (abs(inputX) != 0) {
|
|
||||||
gridX += inputX;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gridY += inputY;
|
|
||||||
}
|
|
||||||
|
|
||||||
//facing
|
//facing
|
||||||
if (inputY > 0) {
|
if (inputY > 0) {
|
||||||
node.faceDown();
|
node.faceDown();
|
||||||
@@ -143,21 +126,58 @@ fn onStep(node: opaque) {
|
|||||||
node.faceLeft();
|
node.faceLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//disallow wall phasing
|
||||||
|
if (inputX != 0 && parent.callNodeFn("getCollisionAt", gridX + inputX, gridY) != true) {
|
||||||
|
inputX = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputY != 0 && parent.callNodeFn("getCollisionAt", gridX, gridY + inputY) != true) {
|
||||||
|
inputY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//disallow diagonal movement
|
||||||
|
if (abs(inputX) != 0) {
|
||||||
|
gridX += inputX;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gridY += inputY;
|
||||||
|
}
|
||||||
|
|
||||||
//trigger the world
|
//trigger the world
|
||||||
if (inputX != 0 || inputY != 0) {
|
if (inputX != 0 || inputY != 0) {
|
||||||
parent.callNodeFn("runAI");
|
parent.callNodeFn("runAI");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//animation
|
//animation - standing still
|
||||||
if (motionX == 0 && motionY == 0 && inputX == 0 && inputY == 0) {
|
if (attackCounter == 0 && stepCount == 0) {
|
||||||
stepCount = 0;
|
//move to standing state
|
||||||
node.setCurrentNodeFrame(0);
|
if (node.getNodeRectY() != 0) {
|
||||||
|
node.setNodeRect(direction * 32 * 4, 0, 32, 32);
|
||||||
|
node.setNodeFrames(4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//animation - attacking
|
||||||
|
if (attackCounter > 0 && stepCount == 0) {
|
||||||
|
//move to attacking state
|
||||||
|
if (node.getNodeRectY() != 32) {
|
||||||
|
node.setNodeRect(direction * 32 * 4, 32, 32, 32);
|
||||||
|
node.setNodeFrames(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually animate
|
||||||
if (++stepCount >= 5) {
|
if (++stepCount >= 5) {
|
||||||
|
if (motionX == 0 && motionY == 0 && inputX == 0 && inputY == 0) {
|
||||||
|
stepCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attackCounter > 0) {
|
||||||
|
attackCounter--;
|
||||||
|
}
|
||||||
|
|
||||||
node.incrementCurrentNodeFrame();
|
node.incrementCurrentNodeFrame();
|
||||||
stepCount = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//calc movement
|
//calc movement
|
||||||
@@ -183,6 +203,16 @@ fn customOnDraw(node: opaque, parentX: int, parentY: int) {
|
|||||||
|
|
||||||
//event functions
|
//event functions
|
||||||
fn onKeyDown(node: opaque, event: string) {
|
fn onKeyDown(node: opaque, event: string) {
|
||||||
|
//initial freeze
|
||||||
|
if (enableMovementCounter > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event == "character_attack" && inputX == 0 && inputY == 0) {
|
||||||
|
attackCounter = 2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event == "character_up") {
|
if (event == "character_up") {
|
||||||
inputY -= 1;
|
inputY -= 1;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
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
|
||||||
|
|
||||||
//TODO: escape to kill the game
|
//TODO: escape to kill the game
|
||||||
|
|
||||||
|
|||||||
BIN
assets/sprites/lejana-mask.png
Normal file
BIN
assets/sprites/lejana-mask.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 3.9 KiB |
137
box/lib_node.c
137
box/lib_node.c
@@ -488,6 +488,138 @@ static int nativeSetNodeRect(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int nativeGetNodeRectX(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
if (arguments->count != 1) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to getNodeRectX\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the arguments
|
||||||
|
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal nodeIdn = nodeLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) {
|
||||||
|
Toy_freeLiteral(nodeIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check argument types
|
||||||
|
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to getNodeRectX\n");
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually get
|
||||||
|
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||||
|
Toy_Literal resultLiteral = TOY_TO_INTEGER_LITERAL(node->rect.x);
|
||||||
|
Toy_pushLiteralArray(&interpreter->stack, resultLiteral);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(resultLiteral);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nativeGetNodeRectY(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
if (arguments->count != 1) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to getNodeRectY\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the arguments
|
||||||
|
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal nodeIdn = nodeLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) {
|
||||||
|
Toy_freeLiteral(nodeIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check argument types
|
||||||
|
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to getNodeRectY\n");
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually get
|
||||||
|
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||||
|
Toy_Literal resultLiteral = TOY_TO_INTEGER_LITERAL(node->rect.y);
|
||||||
|
Toy_pushLiteralArray(&interpreter->stack, resultLiteral);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(resultLiteral);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nativeGetNodeRectW(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
if (arguments->count != 1) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to getNodeRectW\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the arguments
|
||||||
|
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal nodeIdn = nodeLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) {
|
||||||
|
Toy_freeLiteral(nodeIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check argument types
|
||||||
|
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to getNodeRectW\n");
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually get
|
||||||
|
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||||
|
Toy_Literal resultLiteral = TOY_TO_INTEGER_LITERAL(node->rect.w);
|
||||||
|
Toy_pushLiteralArray(&interpreter->stack, resultLiteral);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(resultLiteral);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nativeGetNodeRectH(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
if (arguments->count != 1) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to getNodeRectH\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the arguments
|
||||||
|
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal nodeIdn = nodeLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) {
|
||||||
|
Toy_freeLiteral(nodeIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check argument types
|
||||||
|
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to getNodeRectH\n");
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually get
|
||||||
|
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||||
|
Toy_Literal resultLiteral = TOY_TO_INTEGER_LITERAL(node->rect.h);
|
||||||
|
Toy_pushLiteralArray(&interpreter->stack, resultLiteral);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(resultLiteral);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int nativeSetNodeFrames(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
static int nativeSetNodeFrames(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
if (arguments->count != 2) {
|
if (arguments->count != 2) {
|
||||||
interpreter->errorOutput("Incorrect number of arguments passed to setNodeFrames\n");
|
interpreter->errorOutput("Incorrect number of arguments passed to setNodeFrames\n");
|
||||||
@@ -973,7 +1105,10 @@ int Box_hookNode(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Liter
|
|||||||
{"loadNodeTexture", nativeLoadNodeTexture},
|
{"loadNodeTexture", nativeLoadNodeTexture},
|
||||||
{"freeNodeTexture", nativeFreeNodeTexture},
|
{"freeNodeTexture", nativeFreeNodeTexture},
|
||||||
{"setNodeRect", nativeSetNodeRect},
|
{"setNodeRect", nativeSetNodeRect},
|
||||||
//get rect
|
{"getNodeRectX", nativeGetNodeRectX},
|
||||||
|
{"getNodeRectY", nativeGetNodeRectY},
|
||||||
|
{"getNodeRectW", nativeGetNodeRectW},
|
||||||
|
{"getNodeRectH", nativeGetNodeRectH},
|
||||||
{"setNodeFrames", nativeSetNodeFrames},
|
{"setNodeFrames", nativeSetNodeFrames},
|
||||||
{"getNodeFrames", nativeGetNodeFrames},
|
{"getNodeFrames", nativeGetNodeFrames},
|
||||||
{"setCurrentNodeFrame", nativeSetCurrentNodeFrame},
|
{"setCurrentNodeFrame", nativeSetCurrentNodeFrame},
|
||||||
|
|||||||
Reference in New Issue
Block a user