feat(game): 创建游戏核心框架(常量、配置、状态管理、地图渲染、主场景)

This commit is contained in:
Cloud Bot
2026-03-21 07:56:48 +00:00
parent 80024a5200
commit 85377f1cb2
5 changed files with 489 additions and 0 deletions

26
game/config.ts Normal file
View File

@@ -0,0 +1,26 @@
import type Phaser from 'phaser'
import { GAME_WIDTH, GAME_HEIGHT } from './constants'
/**
* 创建 Phaser 游戏配置
* 注意:此文件只在客户端(动态 import 后)执行,不会在 SSR 中运行
* @param containerId HTML 容器元素的 id
*/
export function createGameConfig(containerId: string): Phaser.Types.Core.GameConfig {
return {
type: (globalThis as typeof globalThis & { Phaser?: { AUTO: number } }).Phaser?.AUTO ?? 0,
width: GAME_WIDTH,
height: GAME_HEIGHT,
parent: containerId,
backgroundColor: '#0a1628',
scale: {
mode: 3, // Phaser.Scale.FIT = 3
autoCenter: 1, // Phaser.Scale.CENTER_BOTH = 1
},
scene: [], // 场景在 GamePage 中动态注入
physics: {
default: 'arcade',
arcade: { debug: false },
},
}
}