added gaining shield on hit

This commit is contained in:
OfficialCHenry 2022-04-19 02:16:29 -04:00
parent a0271d7a97
commit e6f1cbcf39
8 changed files with 23 additions and 43 deletions

View File

@ -212,11 +212,11 @@
"frames": [
{
"index": 0,
"duration": 50
"duration": 500
},
{
"index": 39,
"duration": 50
"duration": 500
}
]
},

View File

@ -1,27 +0,0 @@
{
"name": "Hiro",
"spriteSheetImage": "Hiro.png",
"spriteWidth": 32,
"spriteHeight": 32,
"columns": 1,
"rows": 1,
"durationType": "time",
"animations": [
{
"name": "IDLE",
"frames": [ {"index": 0, "duration": 540} ]
},
{
"name": "JUMP",
"frames":[ {"index": 0, "duration": 32}]
},
{
"name": "WALK",
"frames": [ {"index": 0, "duration": 540} ]
},
{
"name": "FALL",
"frames": [ {"index": 0, "duration": 540} ]
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 819 B

View File

@ -23,7 +23,12 @@ export default class Patrol extends EnemyState {
onEnter(options: Record<string, any>): void {
//this.currentPath = this.getNextPath();
(<AnimatedSprite>this.owner).animation.play("IDLE", true);
//if(!(<AnimatedSprite>this.owner).animation.isPlaying("DYING")){
//(<AnimatedSprite>this.owner).animation.queue("IDLE", true);
//}
//else{
(<AnimatedSprite>this.owner).animation.playIfNotAlready("IDLE", true);
//}
}
handleInput(event: GameEvent): void { }

View File

@ -20,6 +20,10 @@ export default class BattleManager {
if (weapon.hits(enemy.owner)) {
enemy.damage(weapon.type.damage + weapon.EXTRA_DAMAGE);
//console.log("enemy took dmg");
//TODO - test shield,
//add checking for each onhit buff here
(<PlayerController>this.players[0]).addShield(1);
}
}
}
@ -28,6 +32,7 @@ export default class BattleManager {
for (let player of this.players) {
if (weapon.hits(player.owner)) {
(<PlayerController>player).damage(weapon.type.damage, user);
}
}
}

View File

@ -72,10 +72,8 @@ export default class PlayerController extends StateMachineAI implements BattlerA
CURRENT_DEF: number = 100;
CURRENT_EXP : number = 0;
MAX_EXP : number = 100;
//shield buff
CURRENT_SHIELD : number =0;
MAX_SHIELD : number = 20;
invincible : boolean = false;
tilemap: OrthogonalTilemap;
@ -85,7 +83,6 @@ export default class PlayerController extends StateMachineAI implements BattlerA
airjumps:number = 0;
private lookDirection: Vec2;
/** A list of items in the game world */
private items: Array<Item>;
@ -110,20 +107,21 @@ export default class PlayerController extends StateMachineAI implements BattlerA
//shield absorbs the damage and sends dmg back to attacker
if(this.CURRENT_SHIELD > 0){
let newshield = Math.max(0, this.CURRENT_SHIELD - damage ); //calculate the new shield value
(<EnemyAI>attacker._ai).damage(this.CURRENT_SHIELD - newshield); //damage the attacker the dmg taken to shield
if( attacker !== undefined){
(<EnemyAI>attacker._ai).damage(this.CURRENT_SHIELD - newshield); //damage the attacker the dmg taken to shield
}
this.CURRENT_SHIELD = newshield; //update shield value
}
else{
//i frame here
PlayerController.invincibilityTimer.start();
this.invincible = true;
(<AnimatedSprite>this.owner).animation.playIfNotAlready("HURT", false);
//console.log("hurt anim");
(<AnimatedSprite>this.owner).animation.play("HURT" );
this.CURRENT_HP -= damage;
if(this.CURRENT_HP <= 0){
this.emitter.fireEvent(Player_Events.PLAYER_KILLED);
(<AnimatedSprite>this.owner).animation.playIfNotAlready("DYING", false);
(<AnimatedSprite>this.owner).animation.queue("DEAD", false);
(<AnimatedSprite>this.owner).animation.play("DYING");
(<AnimatedSprite>this.owner).animation.queue("DEAD", true, Player_Events.PLAYER_KILLED);
}
}
@ -236,7 +234,7 @@ export default class PlayerController extends StateMachineAI implements BattlerA
//this.addBuff( {type:BuffType.HEALTH, value:1} );
//i frame timer
PlayerController.invincibilityTimer = new Timer(400);
PlayerController.invincibilityTimer = new Timer(2000);
}
initializePlatformer(): void {
@ -285,7 +283,7 @@ export default class PlayerController extends StateMachineAI implements BattlerA
//testing the attacks here, may be moved to another place later
if(InputWrapper.isAttackJustPressed()){
let item = this.inventory.getItem();
(<AnimatedSprite>this.owner).animation.playIfNotAlready("ATTACK", true);
(<AnimatedSprite>this.owner).animation.play("ATTACK", true);
//TODO - get proper look direction
this.lookDirection.x = (<Sprite>this.owner).invertX ? -1 : 1;
// If there is an item in the current slot, use it

View File

@ -13,7 +13,7 @@ export default class Walk extends OnGround {
update(deltaT: number): void {
//console.log("walking anim");
console.log("walking anim");
this.owner.animation.playIfNotAlready("WALK", true);
let dir = this.getInputDirection();

View File

@ -718,7 +718,6 @@ export default class GameLevel extends Scene {
}
if(typeof enemy != undefined && typeof player != undefined){
//damage the player
console.log("player collision damage");
(<PlayerController>this.player._ai).damage(10); //10 collision dmg for now
}