summaryrefslogtreecommitdiff
path: root/src/engine/systems/Input.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-07 20:45:47 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-07 20:45:47 -0700
commite6e29440563e33bb67e0ad51f9fb6c5c2c3fe809 (patch)
tree5deaee322ff1a039dc44a3cb52ecc48a671fda2a /src/engine/systems/Input.ts
parent823620b2a6ebb7ece619991e47a37ad46542b69f (diff)
downloadthe-abstraction-engine-e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809.tar.gz
the-abstraction-engine-e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809.zip
level one (applications prototype finished!)
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));