Skip to content

Commit

Permalink
Adds Slash to the game (#706)
Browse files Browse the repository at this point in the history
* adding starting files

* getting scratch animation to play

* adding starting slash animation

* adding slash damage

* updating slash animation

* reverting animatorType change

* making stylistic changes
  • Loading branch information
Phansa authored and Josh Goldberg committed Apr 19, 2018
1 parent 8f35d40 commit cf10632
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/components/battles/animations/shared/moves/MovesBag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Ember } from "./moves/Ember";
import { Growl } from "./moves/Growl";
import { QuickAttack } from "./moves/QuickAttack";
import { Scratch } from "./moves/Scratch";
import { Slash } from "./moves/Slash";
import { Tackle } from "./moves/Tackle";
import { TailWhip } from "./moves/TailWhip";

Expand All @@ -30,5 +31,6 @@ export const DefaultMovesBag: IMovesBag = {
"SCRATCH": Scratch,
"TACKLE": Tackle,
"TAIL WHIP": TailWhip,
"SLASH" : Slash,
"default": Move,
};
101 changes: 101 additions & 0 deletions src/components/battles/animations/shared/moves/moves/Slash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { FullScreenPokemon } from "../../../../../../FullScreenPokemon";
import { Direction } from "../../../../../Constants";
import { IMenu } from "../../../../../Menus";
import { IThing } from "../../../../../Things";
import { Move } from "../Move";

/**
* Animates a Slash battle move.
*/
export class Slash<TGameStartr extends FullScreenPokemon> extends Move<TGameStartr> {
/**
* Runs the move's animation.
*
* @param callback Callback for when the animation is done.
*/
public runAnimation(callback: () => void): void {
const differenceX: number = this.defenderThing.width / 2;
const lineArray: IThing[] = [];
const menu: IMenu = this.gameStarter.menuGrapher.getMenu("BattleDisplayInitial") as IMenu;
const slashes: IThing[] = [
this.gameStarter.objectMaker.make<IThing>(this.gameStarter.things.names.scratchLine),
this.gameStarter.objectMaker.make<IThing>(this.gameStarter.things.names.scratchLine),
this.gameStarter.objectMaker.make<IThing>(this.gameStarter.things.names.scratchLine),
];
let startX: number;
let startY: number;

if (this.direction === Direction.Right) {
startX = menu.right;
startY = menu.top + this.defenderThing.height / 2;
} else {
startX = menu.left + this.defenderThing.width;
startY = menu.bottom - (this.defenderThing.height + 8);
}

const offset: number = slashes[0].width / 2;
this.gameStarter.things.add(slashes[0], startX, startY);
this.gameStarter.things.add(slashes[1], startX + offset * this.direction * -5, startY);
this.gameStarter.things.add(slashes[2], startX + offset * this.direction * -10, startY);
let time = 0;
const explosionArray: IThing[] = [];
this.gameStarter.timeHandler.addEventInterval(
(): void => {
for (const slash of slashes) {
const left: number = this.direction === Direction.Right ? slash.left : slash.right - 3;
const top: number = slash.bottom - 3;

this.gameStarter.timeHandler.addEvent(
(): void => this.gameStarter.physics.shiftHoriz(slash, differenceX * (this.direction * -1) / 16),
1);
this.gameStarter.timeHandler.addEvent(
(): void => this.gameStarter.physics.shiftVert(slash, differenceX * (this.direction) / 16),
1);

const line: IThing = this.gameStarter.things.add(this.gameStarter.things.names.scratchLine, left, top);
if (this.direction === 1) {
this.gameStarter.graphics.flipHoriz(line);
}
lineArray.push(line);
if (time === 14) {
const explosion = this.gameStarter.things.add
(this.gameStarter.things.names.explosionSmall,
left - 18, top);
explosionArray.push(explosion);
}
}
time += 1;
},
1,
16);
this.gameStarter.timeHandler.addEvent(
(): void => {
for (const slash of slashes) {
this.gameStarter.physics.killNormal(slash);
}

for (const line of lineArray) {
this.gameStarter.battles.animations.things.flicker({
clearTime: 10,
interval: 2,
thing: line,
});
}
for (const explosion of explosionArray) {
this.gameStarter.physics.killNormal(explosion);
}

for (const line of lineArray) {
this.gameStarter.physics.killNormal(line);
}

this.gameStarter.battles.animations.things.flicker({
callback,
clearTime: 14,
interval: 5,
thing: this.defenderThing,
});
},
24);
}
}
9 changes: 8 additions & 1 deletion src/components/constants/Moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,14 @@ export class Moves {
},
"Slash": {
type: "Normal",
effects: [],
effects:
[
{
damage: 70,
target: EffectTarget.defender,
type: "damage",
},
],
accuracy: 100,
PP: 20,
},
Expand Down

0 comments on commit cf10632

Please sign in to comment.