From cf1063239e1903faeb8ed7c44dc63613c52a540c Mon Sep 17 00:00:00 2001 From: Adeet Phanse Date: Wed, 18 Apr 2018 23:04:32 -0400 Subject: [PATCH] Adds Slash to the game (#706) * adding starting files * getting scratch animation to play * adding starting slash animation * adding slash damage * updating slash animation * reverting animatorType change * making stylistic changes --- .../animations/shared/moves/MovesBag.ts | 2 + .../animations/shared/moves/moves/Slash.ts | 101 ++++++++++++++++++ src/components/constants/Moves.ts | 9 +- 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/components/battles/animations/shared/moves/moves/Slash.ts diff --git a/src/components/battles/animations/shared/moves/MovesBag.ts b/src/components/battles/animations/shared/moves/MovesBag.ts index 6fb025139..49831d640 100644 --- a/src/components/battles/animations/shared/moves/MovesBag.ts +++ b/src/components/battles/animations/shared/moves/MovesBag.ts @@ -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"; @@ -30,5 +31,6 @@ export const DefaultMovesBag: IMovesBag = { "SCRATCH": Scratch, "TACKLE": Tackle, "TAIL WHIP": TailWhip, + "SLASH" : Slash, "default": Move, }; diff --git a/src/components/battles/animations/shared/moves/moves/Slash.ts b/src/components/battles/animations/shared/moves/moves/Slash.ts new file mode 100644 index 000000000..8eeeef9df --- /dev/null +++ b/src/components/battles/animations/shared/moves/moves/Slash.ts @@ -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 extends Move { + /** + * 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(this.gameStarter.things.names.scratchLine), + this.gameStarter.objectMaker.make(this.gameStarter.things.names.scratchLine), + this.gameStarter.objectMaker.make(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); + } +} diff --git a/src/components/constants/Moves.ts b/src/components/constants/Moves.ts index 5025f05f2..17d742a77 100644 --- a/src/components/constants/Moves.ts +++ b/src/components/constants/Moves.ts @@ -795,7 +795,14 @@ export class Moves { }, "Slash": { type: "Normal", - effects: [], + effects: + [ + { + damage: 70, + target: EffectTarget.defender, + type: "damage", + }, + ], accuracy: 100, PP: 20, },