diff --git a/src/config/constants.ts b/src/config/constants.ts index b8d3361..0ecb7d0 100644 --- a/src/config/constants.ts +++ b/src/config/constants.ts @@ -1,3 +1,8 @@ +// Game settings +export const DEBUG = true; +export const FPS = 60; +export const UI_BOTTOM_PADDING = 60; // pixels - space below rink for UI elements + // Rink dimensions (meters) export const RINK_LENGTH = 60; // meters export const RINK_WIDTH = 30; // meters @@ -23,10 +28,6 @@ export const COLOR_RED_LINE = 0xff0000; export const COLOR_BLUE_LINE = 0x0000ff; export const COLOR_GOAL_CREASE = 0x87ceeb; -// Game settings -export const FPS = 60; -export const DEBUG = false; - // Player constants export const PLAYER_RADIUS_GOALIE = 12; // pixels export const PLAYER_RADIUS_SKATER = 10; // pixels diff --git a/src/game/GameScene.ts b/src/game/GameScene.ts index b44bba3..fbfe5bf 100644 --- a/src/game/GameScene.ts +++ b/src/game/GameScene.ts @@ -53,6 +53,10 @@ export class GameScene extends Phaser.Scene { // Track last reception attempt time for each player to avoid spamming attempts private lastReceptionAttempt: Map = new Map(); + // Pause state + private isPaused: boolean = false; + private pauseButton!: Phaser.GameObjects.Text; + constructor() { super({ key: 'GameScene' }); } @@ -63,6 +67,7 @@ export class GameScene extends Phaser.Scene { this.createPuck(); this.createPlayers(); this.setupEventListeners(); + this.createPauseButton(); } private createPlayers() { @@ -195,7 +200,41 @@ export class GameScene extends Phaser.Scene { graphics.strokeRoundedRect(2, 2, RINK_LENGTH * SCALE - 4, RINK_WIDTH * SCALE - 4, RINK_CORNER_RADIUS * SCALE); } + private createPauseButton() { + const centerX = (RINK_LENGTH * SCALE) / 2; + const rinkHeight = RINK_WIDTH * SCALE; + + // Create pause button at bottom center + this.pauseButton = this.add.text(centerX, rinkHeight + 20, 'PAUSE', { + fontSize: '20px', + color: '#ffffff', + backgroundColor: '#333333', + padding: { x: 16, y: 8 } + }) + .setOrigin(0.5) + .setInteractive({ useHandCursor: true }) + .on('pointerdown', () => this.togglePause()); + } + + private togglePause() { + this.isPaused = !this.isPaused; + + if (this.isPaused) { + // Pause physics and update button + this.physics.pause(); + this.pauseButton.setText('RESUME'); + this.pauseButton.setBackgroundColor('#2d6a2d'); + } else { + // Resume physics and update button + this.physics.resume(); + this.pauseButton.setText('PAUSE'); + this.pauseButton.setBackgroundColor('#333333'); + } + } + update(_time: number, delta: number) { + if (this.isPaused) return; + this.updatePuck(); this.updatePlayers(delta); this.checkGoals(); diff --git a/src/game/main.ts b/src/game/main.ts index d542050..34cc598 100644 --- a/src/game/main.ts +++ b/src/game/main.ts @@ -1,11 +1,11 @@ import Phaser from 'phaser'; import { GameScene } from './GameScene'; -import { RINK_LENGTH, RINK_WIDTH, SCALE, FPS, DEBUG } from '../config/constants'; +import { RINK_LENGTH, RINK_WIDTH, SCALE, FPS, DEBUG, UI_BOTTOM_PADDING } from '../config/constants'; const config: Phaser.Types.Core.GameConfig = { type: Phaser.AUTO, width: RINK_LENGTH * SCALE, - height: RINK_WIDTH * SCALE, + height: RINK_WIDTH * SCALE + UI_BOTTOM_PADDING, parent: 'game-container', backgroundColor: '#1a1a1a', physics: {