From 1c1744002f7b6b9542a1a02c05bb61f24342f4de Mon Sep 17 00:00:00 2001 From: OfficialCHenry Date: Thu, 14 Apr 2022 21:22:52 -0400 Subject: [PATCH] added extrajump and dash --- src/main.ts | 2 +- src/shattered_sword/AI/EnemyStates/Patrol.ts | 4 ++-- src/shattered_sword/Player/PlayerController.ts | 11 ++++++++--- src/shattered_sword/Player/PlayerStates/Fall.ts | 13 +++++++++++++ src/shattered_sword/Player/PlayerStates/InAir.ts | 2 +- src/shattered_sword/Player/PlayerStates/Jump.ts | 10 ++++++++++ src/shattered_sword/Player/PlayerStates/OnGround.ts | 9 ++++++++- src/shattered_sword/Player/PlayerStates/Walk.ts | 12 ++++++++++-- src/shattered_sword/Scenes/GameLevel.ts | 11 +++-------- 9 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/main.ts b/src/main.ts index 54ce7b2..74cf20a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,7 +22,7 @@ import WeaponTypeRegistry from "./shattered_sword/Registry/WeaponTypeRegistry"; {name: "down", keys: ["s"]}, {name: "jump", keys: ["x","space"]}, {name: "attack", keys: ["j","z","enter"]}, - {name: "dash", keys: ["k","z"]}, + {name: "dash", keys: ["k","x"]}, // {name: "skill", keys: ["l","v"]}, {name: "inventory", keys: ["i","b"]}, {name: "pause", keys: ["escape"]}, diff --git a/src/shattered_sword/AI/EnemyStates/Patrol.ts b/src/shattered_sword/AI/EnemyStates/Patrol.ts index da0d173..ba18f1f 100644 --- a/src/shattered_sword/AI/EnemyStates/Patrol.ts +++ b/src/shattered_sword/AI/EnemyStates/Patrol.ts @@ -40,7 +40,7 @@ export default class Patrol extends EnemyState { //turn around //console.log(this.parent.tilemap.getTileAtRowCol(colrow)); this.parent.direction *= -1; - console.log((this.owner).invertX); + //console.log((this.owner).invertX); //(this.owner).invertX != (this.owner).invertX ; //console.log("turn around cus wall in front"); } @@ -48,7 +48,7 @@ export default class Patrol extends EnemyState { else if(!this.parent.tilemap.isTileCollidable(colrow.x+this.parent.direction,colrow.y+1)){ //turn around this.parent.direction *=-1; - console.log((this.owner).invertX); + //console.log((this.owner).invertX); //console.log("turn around cus no floor in front"); } else{ diff --git a/src/shattered_sword/Player/PlayerController.ts b/src/shattered_sword/Player/PlayerController.ts index f193025..e743b76 100644 --- a/src/shattered_sword/Player/PlayerController.ts +++ b/src/shattered_sword/Player/PlayerController.ts @@ -70,6 +70,10 @@ export default class PlayerController extends StateMachineAI implements BattlerA CURRENT_DEF: number = 100; tilemap: OrthogonalTilemap; + //for doublejumps maybe = # of jumps in air allowed + MAX_airjumps: number = 1; + airjumps:number = 0; + // TODO - damage(damage: number): void { (this.owner).animation.play("HURT", false); @@ -222,10 +226,10 @@ export default class PlayerController extends StateMachineAI implements BattlerA } else if(this.currentState instanceof Fall){ Debug.log("playerstate", "Player State: Fall"); } - Debug.log("playerspeed", "x: " + this.velocity.x + ", y:" + this.velocity.y); - Debug.log("player Coords:", this.owner.position ); + Debug.log("player speed", "player speed: x: " + this.velocity.x + ", y:" + this.velocity.y); + Debug.log("player Coords:", "Player Coords:" +this.owner.position ); - //testing the attacks here, may be moved to another place latera + //testing the attacks here, may be moved to another place later if(Input.isJustPressed("attack")){ let item = this.inventory.getItem(); (this.owner).animation.playIfNotAlready("ATTACK", true); @@ -236,6 +240,7 @@ export default class PlayerController extends StateMachineAI implements BattlerA item.use(this.owner, "player", this.lookDirection); } } + } diff --git a/src/shattered_sword/Player/PlayerStates/Fall.ts b/src/shattered_sword/Player/PlayerStates/Fall.ts index 04c6c60..5d1497c 100644 --- a/src/shattered_sword/Player/PlayerStates/Fall.ts +++ b/src/shattered_sword/Player/PlayerStates/Fall.ts @@ -1,6 +1,7 @@ import GameEvent from "../../../Wolfie2D/Events/GameEvent"; import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite"; import InAir from "./InAir"; +import Input from "../../../Wolfie2D/Input/Input"; export default class Fall extends InAir { owner: AnimatedSprite; @@ -9,6 +10,18 @@ export default class Fall extends InAir { this.owner.animation.play("FALL", true); } + update(deltaT: number): void { + super.update(deltaT); + + //TODO - testing doublejump, may have to move to InAir instead + // If we jump, move to the Jump state, give a burst of upwards velocity + if( this.parent.airjumps>0 && Input.isJustPressed("jump")){ + this.parent.airjumps --; + this.finished("jump"); + this.parent.velocity.y = -600; // basically jump height + + } + } onExit(): Record { this.owner.animation.stop(); return {}; diff --git a/src/shattered_sword/Player/PlayerStates/InAir.ts b/src/shattered_sword/Player/PlayerStates/InAir.ts index fad5d7f..754a91f 100644 --- a/src/shattered_sword/Player/PlayerStates/InAir.ts +++ b/src/shattered_sword/Player/PlayerStates/InAir.ts @@ -15,7 +15,7 @@ export default abstract class InAir extends PlayerState { (this.owner).invertX = MathUtils.sign(dir.x) < 0; } - this.parent.velocity.x += dir.x * this.parent.speed/3.5 - 0.3*this.parent.velocity.x; + this.parent.velocity.x += dir.x * (this.parent.speed+this.parent.CURRENT_BUFFS.speed)/3.5 - 0.3*this.parent.velocity.x; this.owner.move(this.parent.velocity.scaled(deltaT)); diff --git a/src/shattered_sword/Player/PlayerStates/Jump.ts b/src/shattered_sword/Player/PlayerStates/Jump.ts index 54ff2c7..e76c9ba 100644 --- a/src/shattered_sword/Player/PlayerStates/Jump.ts +++ b/src/shattered_sword/Player/PlayerStates/Jump.ts @@ -5,6 +5,7 @@ import { EaseFunctionType } from "../../../Wolfie2D/Utils/EaseFunctions"; import { Player_Events } from "../../sword_enums"; import { PlayerStates } from "../PlayerController"; import InAir from "./InAir"; +import Input from "../../../Wolfie2D/Input/Input"; export default class Jump extends InAir { owner: AnimatedSprite; @@ -24,6 +25,15 @@ export default class Jump extends InAir { this.parent.velocity.y = 0; } + //TODO - testing doublejump, may have to move to InAir instead + // If we jump, move to the Jump state, give a burst of upwards velocity + if( this.parent.airjumps>0 && Input.isJustPressed("jump")){ + this.parent.airjumps --; + this.finished("jump"); + this.parent.velocity.y = -600; // basically jump height + + } + // If we're falling, go to the fall state if(this.parent.velocity.y >= 0){ this.finished(PlayerStates.FALL); diff --git a/src/shattered_sword/Player/PlayerStates/OnGround.ts b/src/shattered_sword/Player/PlayerStates/OnGround.ts index d0f3b35..962bf43 100644 --- a/src/shattered_sword/Player/PlayerStates/OnGround.ts +++ b/src/shattered_sword/Player/PlayerStates/OnGround.ts @@ -8,9 +8,14 @@ export default class OnGround extends PlayerState { onEnter(options: Record): void {} update(deltaT: number): void { + //reset airjumps + this.parent.airjumps = this.parent.MAX_airjumps; + if(this.parent.velocity.y > 0){ this.parent.velocity.y = 0; } + + super.update(deltaT); let direction = this.getInputDirection(); @@ -19,12 +24,14 @@ export default class OnGround extends PlayerState { (this.owner).invertX = MathUtils.sign(direction.x) < 0; } + // If we jump, move to the Jump state, give a burst of upwards velocity if(Input.isJustPressed("jump")){ this.finished("jump"); this.parent.velocity.y = -600; // basically jump height - } else if(!this.owner.onGround){ + } + else if(!this.owner.onGround){ this.finished("fall"); } diff --git a/src/shattered_sword/Player/PlayerStates/Walk.ts b/src/shattered_sword/Player/PlayerStates/Walk.ts index c672b03..9ddd918 100644 --- a/src/shattered_sword/Player/PlayerStates/Walk.ts +++ b/src/shattered_sword/Player/PlayerStates/Walk.ts @@ -22,8 +22,16 @@ export default class Walk extends OnGround { if(dir.isZero()){ this.finished(PlayerStates.IDLE); } - this.parent.velocity.x = dir.x * this.parent.speed - + + this.parent.velocity.x = dir.x * (this.parent.speed + this.parent.CURRENT_BUFFS.speed); + + //TODO - decide how to implement dash - could be a flash - maybe allow in air as well + if(Input.isJustPressed("dash")){ + //play dash anim maybe + //TODO - might give buffed speed stat to dash speed + this.parent.velocity.x = dir.x * 1000; //give sidewards velocity + //TODO - give player i frame + } this.owner.move(this.parent.velocity.scaled(deltaT)); } diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index 23b6246..cc45724 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -170,9 +170,6 @@ export default class GameLevel extends Scene { updateScene(deltaT: number){ - let clickpos = Input.getMousePosition(); - if(Input.isMouseJustPressed()) - console.log("mouse pos: " +clickpos); // Handle events and update the UI if needed while(this.receiver.hasNextEvent()){ let event = this.receiver.getNextEvent(); @@ -184,8 +181,6 @@ export default class GameLevel extends Scene { //remove enemy from enemies this.enemies = this.enemies.filter(item => item !== event.data.get("ai")); this.battleManager.removeEnemy(event.data.get("ai")); - - console.log("enemy destroyed"); node.destroy(); //TODO - this is for testing, add some chance here later this.emitter.fireEvent(Player_Events.GIVE_BUFF); @@ -197,7 +192,7 @@ export default class GameLevel extends Scene { this.buffButton2.text = "Increase "+this.buffs[1].type + " by "+this.buffs[1].value; this.buffButton3.text = "Increase "+this.buffs[2].type + " by "+this.buffs[2].value; - + //pause game here this.buffLayer.enable(); break; @@ -527,7 +522,7 @@ export default class GameLevel extends Scene { case "snake": //snake enemies drop from sky("trees")? or could just be very abundant this.addEnemy("snake", enemy.position.scale(32), { player: this.player, - health: 100, + health: 50, tilemap: "Main", //actions:actions, goal: Statuses.REACHED_GOAL, @@ -536,7 +531,7 @@ export default class GameLevel extends Scene { case "tiger": //tiger can be miniboss for now? this.addEnemy("tiger", enemy.position.scale(32), { player: this.player, - health: 100, + health: 200, tilemap: "Main", //actions:actions, goal: Statuses.REACHED_GOAL,