Skip to content

Commit

Permalink
pixi refactor: add explosions
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Aug 12, 2023
1 parent 06a26e6 commit 4410f37
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
42 changes: 23 additions & 19 deletions client/src/scripts/objects/explosion.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { Game } from "../game";
import type { GameScene } from "../scenes/gameScene";

import { localStorageInstance } from "../utils/localStorageHandler";

import { distanceSquared } from "../../../../common/src/utils/math";
import { type Vector, vMul } from "../../../../common/src/utils/vector";
import { type ObjectType } from "../../../../common/src/utils/objectType";
import type { ExplosionDefinition } from "../../../../common/src/definitions/explosions";
import { type ObjectCategory } from "../../../../common/src/constants";
import { SuroiSprite } from "../utils/pixi";
import { gsap } from "gsap";

/**
* Custom particle class that adds friction to its velocity.
Expand All @@ -27,10 +25,16 @@ import { type ObjectCategory } from "../../../../common/src/constants";

export function explosion(game: Game, type: ObjectType<ObjectCategory.Explosion, ExplosionDefinition>, position: Vector): void {
const definition = type.definition;
const phaserPos = vMul(position, 20);
position = vMul(position, 20);

const image = new SuroiSprite(definition.animation.frame);

image.scale.set(0);
image.setPos(position.x, position.y);

/*const image = scene.add.image(phaserPos.x, phaserPos.y, "main", definition.animation.frame).setScale(0);
const emitter = scene.add.particles(phaserPos.x, phaserPos.y, "main", {
game.camera.container.addChild(image);

/*const emitter = scene.add.particles(phaserPos.x, phaserPos.y, "main", {
frame: definition.particles.frame,
lifespan: definition.particles.duration,
speed: { min: 0, max: definition.radius.max * 60 },
Expand All @@ -48,25 +52,25 @@ export function explosion(game: Game, type: ObjectType<ObjectCategory.Explosion,
emitter.explode(definition.particles.count);
// Destroy particle emitter.
setTimeout(() => { emitter.destroy(); }, definition.particles.duration);
setTimeout(() => { emitter.destroy(); }, definition.particles.duration);*/

scene.tweens.add({
targets: image,
scale: definition.animation.scale,
duration: definition.animation.duration,
gsap.to(image.scale, {
x: definition.animation.scale,
y: definition.animation.scale,
duration: definition.animation.duration / 1000,
ease: "Expo.Out"
});

scene.tweens.add({
targets: image,
gsap.to(image, {
alpha: 0,
duration: definition.animation.duration * 1.5, // the alpha animation is a bit longer so it looks nicer
ease: "Expo.Out"
}).on("complete", (): void => {
image.destroy();
duration: definition.animation.duration * 1.5 / 1000, // the alpha animation is a bit longer so it looks nicer
ease: "Expo.Out",
onComplete: () => {
image.destroy();
}
});

if (game?.activePlayer !== undefined && distanceSquared(game.activePlayer.position, position) <= 4900) {
/*if (game?.activePlayer !== undefined && distanceSquared(game.activePlayer.position, position) <= 4900) {
if (localStorageInstance.config.cameraShake) {
scene.cameras.main.shake(definition.cameraShake.duration, definition.cameraShake.intensity);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/scripts/objects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { type SkinDefinition } from "../../../../common/src/definitions/skins";
import { SuroiSprite } from "../utils/pixi";
import { Container, Graphics } from "pixi.js";

const showMeleeDebugCircle = true;
const showMeleeDebugCircle = false;

export class Player extends GameObject<ObjectCategory.Player> {
name!: string;
Expand Down

0 comments on commit 4410f37

Please sign in to comment.