Skip to content

Commit

Permalink
refactor: config for the speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
rengert committed Feb 2, 2024
1 parent f798c55 commit 180d4b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/app/game-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface GameConfig extends Config {
},
ships: Record<ShipType, {
shotSpeed: number;
rocketSpeed: number;
}>,
}

Expand All @@ -27,10 +28,12 @@ export const GAME_CONFIG: GameConfig = {
},
ships: {
[ShipType.ship]: {
shotSpeed: 6, // speed in pixel
rocketSpeed: 6,
shotSpeed: 1,
},
[ShipType.enemy]: {
shotSpeed: 4, // speed in pixel
rocketSpeed: 4,
shotSpeed: 0.1,
},
},
powerUpConfig: [
Expand Down
3 changes: 3 additions & 0 deletions src/app/models/pixijs/ship.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FrameObject, Texture } from 'pixi.js';
import { GAME_CONFIG } from '../../game-constants';
import { GameShotService } from '../../services/game-shot.service';
import { AnimatedGameSprite } from './animated-game-sprite';
import { ShipType } from './ship-type.enum';
Expand All @@ -21,6 +22,8 @@ export class Ship extends AnimatedGameSprite {
textures: Texture[] | FrameObject[],
autoUpdate?: boolean) {
super(speed, textures, autoUpdate);

this.shotSpeed = GAME_CONFIG.ships[this.type].shotSpeed;
}

set energy(value: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/game-shot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class GameShotService {
shot(power: number, ship: Ship, up: boolean): void {
const { x, y } = ship;
for (let i = 1; i <= power; i++) {
const shot = new Rocket(up ? -GAME_CONFIG.ships[ship.type].shotSpeed : GAME_CONFIG.ships[ship.type].shotSpeed, this.laserAnimation !);
const shot = new Rocket(up ? -GAME_CONFIG.ships[ship.type].rocketSpeed : GAME_CONFIG.ships[ship.type].rocketSpeed, this.laserAnimation !);
shot.reference = ship;
shot.animationSpeed = 0.167;
shot.play();
Expand Down

0 comments on commit 180d4b5

Please sign in to comment.