Skip to content

Commit

Permalink
feat: make fire via mouse click
Browse files Browse the repository at this point in the history
  • Loading branch information
ufocoder committed May 31, 2024
1 parent b681c2f commit 9027486
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/lib/ecs/systems/WeaponSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import SoundManager from "src/managers/SoundManager";
import ECS from "src/lib/ecs/ExtendedECS";
import AnimatedSpriteComponent from "src/lib/ecs/components/AnimatedSpriteComponent";

const spaceKeyCode = "Space";

export default class WeaponSystem extends System {
public readonly componentsRequired = new Set([BulletComponent, CircleComponent]);

Expand Down Expand Up @@ -80,11 +78,7 @@ export default class WeaponSystem extends System {
this.destroyListeners();
}

handleDocumentKeyDown = (e: KeyboardEvent) => {
if (e.code !== spaceKeyCode) {
return
}

handleDocumentClick = (e: MouseEvent) => {
e.preventDefault();

const [player] = this.ecs.query([CameraComponent, WeaponComponent, AngleComponent, PositionComponent]);
Expand All @@ -93,6 +87,7 @@ export default class WeaponSystem extends System {
if (!playerContainer) {
return;
}

const weapon = playerContainer.get(WeaponComponent);

if (weapon.bullets <= 0) {
Expand All @@ -114,10 +109,10 @@ export default class WeaponSystem extends System {
};

createListeners() {
document.addEventListener("keydown", this.handleDocumentKeyDown);
document.addEventListener("keydown", this.handleDocumentClick);

Check failure on line 112 in src/lib/ecs/systems/WeaponSystem.ts

View workflow job for this annotation

GitHub Actions / deploy

No overload matches this call.
}

destroyListeners() {
document.removeEventListener("keydown", this.handleDocumentKeyDown);
document.removeEventListener("keydown", this.handleDocumentClick);

Check failure on line 116 in src/lib/ecs/systems/WeaponSystem.ts

View workflow job for this annotation

GitHub Actions / deploy

No overload matches this call.
}
}

0 comments on commit 9027486

Please sign in to comment.