summaryrefslogtreecommitdiff
path: root/src/engine/systems/Input.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/systems/Input.ts')
-rw-r--r--src/engine/systems/Input.ts51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/engine/systems/Input.ts b/src/engine/systems/Input.ts
index 8900f4e..c527f29 100644
--- a/src/engine/systems/Input.ts
+++ b/src/engine/systems/Input.ts
@@ -2,7 +2,7 @@ import { Grid as GridSystem, SystemNames, System } from ".";
import { Game } from "..";
import { ComponentNames, Grid, Interactable } from "../components";
import { Control } from "../components/Control";
-import { Action, KeyConstants } from "../config";
+import { Action, KeyConstants, MovingSound, SOUNDS } from "../config";
import { Entity, Particles } from "../entities";
import { Coord2D, Direction } from "../interfaces";
import { colors } from "../utils";
@@ -105,27 +105,44 @@ export class Input extends System {
}
if (moveUp || moveLeft || moveRight || moveDown) {
- const gridPosition = gridComponent.gridPosition;
- const gridSystem = game.getSystem<GridSystem>(SystemNames.Grid);
- const particles = new Particles({
- center: gridSystem.gridToScreenPosition(gridPosition),
- particleCount: 5,
- particleShape: "circle",
- particleMeanSpeed: 0.05,
- particleSpeedVariance: 0.005,
- particleMeanLife: 120,
- particleMeanSize: 5,
- particleSizeVariance: 2,
- particleLifeVariance: 30,
- particleColors: [colors.gray, colors.darkGray],
- });
-
- game.addEntity(particles);
+ this.spawnParticlesAround(entity, game);
+ this.playMoveSound();
}
entity.addComponent(gridComponent);
}
+ private playMoveSound() {
+ const movingSounds = Array.from(MovingSound.states!.values());
+ const soundName =
+ movingSounds[Math.floor(Math.random() * movingSounds.length)].name;
+ SOUNDS.get(soundName)!.play();
+ }
+
+ private spawnParticlesAround(entity: Entity, game: Game) {
+ const gridSystem = game.getSystem<GridSystem>(SystemNames.Grid);
+ const gridComponent = entity.getComponent<Grid>(ComponentNames.Grid)!;
+ const particles = new Particles({
+ center: gridSystem.gridToScreenPosition(gridComponent.gridPosition),
+ particleCount: 4,
+ spawnerShape: "circle",
+ spawnerDimensions: {
+ width: 10,
+ height: 10,
+ },
+ particleShape: "rectangle",
+ particleMeanSpeed: 0.05,
+ particleSpeedVariance: 0.005,
+ particleMeanLife: 120,
+ particleMeanSize: 3,
+ particleSizeVariance: 1,
+ particleLifeVariance: 30,
+ particleColors: [colors.gray, colors.darkGray, colors.lightPurple],
+ });
+
+ game.addEntity(particles);
+ }
+
private hasSomeKey(keys?: string[]): boolean {
if (keys) {
return keys.some((key) => this.keys.has(key));