Added lejana's kick animation

This commit is contained in:
2023-03-08 07:58:02 +11:00
parent a665e15415
commit b58c1afa42
5 changed files with 191 additions and 25 deletions

View File

@@ -28,7 +28,7 @@ var inputY: int = 0;
var direction: int = null; //BUGFIX: animation not looping properly
var enableMovementCounter: int = 30 * 3; //BUGFIX: freeze while drones reach their starting spot
var attackCounter: int = 0;
//polyfills - animating different cycles on one image
var stepCount: int = 0;
@@ -106,26 +106,9 @@ fn onStep(node: opaque) {
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
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
if (inputY > 0) {
node.faceDown();
@@ -143,21 +126,58 @@ fn onStep(node: opaque) {
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
if (inputX != 0 || inputY != 0) {
parent.callNodeFn("runAI");
}
}
//animation
if (motionX == 0 && motionY == 0 && inputX == 0 && inputY == 0) {
stepCount = 0;
node.setCurrentNodeFrame(0);
//animation - standing still
if (attackCounter == 0 && stepCount == 0) {
//move to standing state
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 (motionX == 0 && motionY == 0 && inputX == 0 && inputY == 0) {
stepCount = 0;
}
if (attackCounter > 0) {
attackCounter--;
}
node.incrementCurrentNodeFrame();
stepCount = 0;
}
//calc movement
@@ -183,6 +203,16 @@ fn customOnDraw(node: opaque, parentX: int, parentY: int) {
//event functions
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") {
inputY -= 1;
return;

View File

@@ -26,6 +26,7 @@
mapInputEventToKeyUp("character_down", "down"); //event, keysym
mapInputEventToKeyUp("character_right", "right"); //event, keysym
mapInputEventToKeyDown("character_attack", "space"); //event, keysym
//TODO: escape to kill the game

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

View File

@@ -488,6 +488,138 @@ static int nativeSetNodeRect(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
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) {
if (arguments->count != 2) {
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},
{"freeNodeTexture", nativeFreeNodeTexture},
{"setNodeRect", nativeSetNodeRect},
//get rect
{"getNodeRectX", nativeGetNodeRectX},
{"getNodeRectY", nativeGetNodeRectY},
{"getNodeRectW", nativeGetNodeRectW},
{"getNodeRectH", nativeGetNodeRectH},
{"setNodeFrames", nativeSetNodeFrames},
{"getNodeFrames", nativeGetNodeFrames},
{"setCurrentNodeFrame", nativeSetCurrentNodeFrame},