mirror of
http://junepve.top:3000/chicrobot/CINC.git
synced 2026-10-30 01:31:29 +08:00
94 lines
2.9 KiB
JavaScript
94 lines
2.9 KiB
JavaScript
// 测试场景2:目标点移动
|
|
import Unit from '../objects/Unit.js';
|
|
import { InputSystem } from '../systems/InputSystem.js';
|
|
import { SelectionSystem } from '../systems/SelectionSystem.js';
|
|
import { CommandSystem } from '../systems/CommandSystem.js';
|
|
|
|
export default class MovementTestScene2 extends Phaser.Scene {
|
|
constructor() {
|
|
super({ key: 'MovementTestScene2' });
|
|
}
|
|
|
|
create() {
|
|
// 创建玩家纹理
|
|
if (!this.textures.exists('player')) {
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = 32;
|
|
canvas.height = 32;
|
|
const ctx = canvas.getContext('2d');
|
|
ctx.fillStyle = '#000000ff';
|
|
ctx.beginPath();
|
|
ctx.arc(16, 16, 14, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
this.textures.addCanvas('player', canvas);
|
|
}
|
|
|
|
// 物理世界和相机边界
|
|
const worldSize = 1000;
|
|
this.physics.world.setBounds(-worldSize, -worldSize, worldSize * 2, worldSize * 2);
|
|
this.cameras.main.setBounds(-worldSize, -worldSize, worldSize * 2, worldSize * 2);
|
|
this.cameras.main.centerOn(0, 0);
|
|
|
|
// 初始化系统 - 只开启鼠标移动,禁用框选
|
|
this.inputSystem = new InputSystem(this, {
|
|
keyboard: false,
|
|
mouse: true,
|
|
joystick: false,
|
|
selection: false
|
|
});
|
|
this.selectionSystem = new SelectionSystem(this);
|
|
this.commandSystem = new CommandSystem(this);
|
|
|
|
// 创建单位组
|
|
this.unitGroup = this.add.group();
|
|
|
|
// 创建一个测试单位
|
|
const unit = new Unit(this, 0, 0, 'player');
|
|
this.unitGroup.add(unit);
|
|
|
|
// 自动选中单位
|
|
this.events.emit('select-unit', unit);
|
|
|
|
// 添加碰撞检测
|
|
this.physics.add.collider(this.unitGroup, this.unitGroup);
|
|
|
|
// 添加场景说明文本
|
|
const titleText = this.add.text(10, 10, '测试场景2:目标点移动', {
|
|
fontSize: '20px',
|
|
fill: '#ffffff'
|
|
});
|
|
titleText.setScrollFactor(0, 0); // 固定在屏幕上,不随相机移动
|
|
titleText.setDepth(10); // 设置深度,确保显示在游戏元素上方
|
|
|
|
const moveText = this.add.text(10, 40, '点击鼠标右键或点击空地指定移动目标点', {
|
|
fontSize: '16px',
|
|
fill: '#ffffff'
|
|
});
|
|
moveText.setScrollFactor(0, 0); // 固定在屏幕上,不随相机移动
|
|
moveText.setDepth(10); // 设置深度,确保显示在游戏元素上方
|
|
|
|
const spaceText = this.add.text(10, 70, '按空格键返回菜单', {
|
|
fontSize: '16px',
|
|
fill: '#ffffff'
|
|
});
|
|
spaceText.setScrollFactor(0, 0); // 固定在屏幕上,不随相机移动
|
|
spaceText.setDepth(10); // 设置深度,确保显示在游戏元素上方
|
|
|
|
// 空格键切换场景
|
|
this.input.keyboard.on('keydown-SPACE', () => {
|
|
this.scene.start('BootScene');
|
|
});
|
|
}
|
|
|
|
update() {
|
|
this.inputSystem.update();
|
|
|
|
this.unitGroup.getChildren().forEach(unit => {
|
|
if (unit.update) {
|
|
unit.update();
|
|
}
|
|
unit.updateMovement();
|
|
});
|
|
}
|
|
}
|