Skip to content

Commit

Permalink
Bugfix for bunny spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Babis committed Sep 6, 2017
1 parent d8289ce commit f2aa37c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
22 changes: 21 additions & 1 deletion src/client/js/app/entities/creatures/enemies/DustBunny.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@ import DamageTypes from '../../DamageTypes.js';

import DustMite from './DustMite.js';

/**
* Basic melee attack for a dust bunny
*/
class DustBunnyAttack extends Weapon {
/** @override */
getRange() {
return 1;
}

/** @override */
getDamage() {
return 2;
}

/** @override */
getDamageType() {
return DamageTypes.MELEE_PHYSICAL;
}
}

/**
* A fast moving, weak melee enemy that spawns
* smaller enemies on death
*/
export default class DustBunny extends Creature {
/** @override */
constructor() {
super();
this.setStrategy(new Strategies.CompositeStrategy(
Expand All @@ -30,21 +41,30 @@ export default class DustBunny extends Creature {
));
}

/** @override */
getMeleeWeapon() {
return new DustBunnyAttack();
}

/** @override */
getSpeed() {
return 300;
}

/** @override */
getBaseHP() {
return 2;
}

/**
* Creates up to 3 dust mites on adjacent empty tiles
* @override
* @param {*} dungeon
* @param {*} location
*/
onDeath(dungeon, location) {
location.getNeighbors8(dungeon).filter((tile) =>
!tile.getCreature() && tile.hasFloor() && !tile.isSolid()).slice(-3)
.forEach((tile)=>dungeon.moveCreature(new DustMite(), tile.getX(), tile.getY()));
.forEach((tile)=>dungeon.moveCreature(new DustMite(), tile.getX(), tile.getY()));
}
}
18 changes: 7 additions & 11 deletions src/client/js/app/views/DefaultPixiAnimationPack.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export default class DefaultPixiAnimationPack {
getAnimation(sharedData, pixiDungeonView, gameEvent) {
const dungeon = sharedData.getDungeon();
const stage = pixiDungeonView.getStage();
const spritePack = pixiDungeonView.getSpritePack();
let cumulativeTime = 0;
if(gameEvent instanceof GameEvents.PositionChangeEvent) {
const cause = gameEvent.getCause();
Expand Down Expand Up @@ -299,16 +298,13 @@ export default class DefaultPixiAnimationPack {
// TODO: Also place creature from here rather than handling it entirely in the PixiDungeonView
const creature = gameEvent.getCreature();

const hpAnimation = new Animation(0);
hpAnimation.onStart = () => pixiDungeonView.setCreatureHpBarWidth(
creature.getId(),
Math.max(0, creature.getCurrentHP()) / creature.getBaseHP()
);
hpAnimation.advance = () => {};

const animations = [hpAnimation];

return new AnimationGroup(animations);
return new SingleFrameAnimation(() => {
pixiDungeonView.moveCreatureGroup(creature, gameEvent.getX(), gameEvent.getY());
pixiDungeonView.setCreatureHpBarWidth(
creature.getId(),
Math.max(0, creature.getCurrentHP()) / creature.getBaseHP()
);
});
} else if(gameEvent instanceof GameEvents.TakeItemEvent) {
return new SingleFrameAnimation(() => {
pixiDungeonView.removeEntityById(gameEvent.getItem().getId());
Expand Down

0 comments on commit f2aa37c

Please sign in to comment.