feat(control) 多角色控制

This commit is contained in:
chicrobot committed 2025-12-30 21:45:25 +08:00
1 parent be5ee91328
commit f86e5f3a79
11 files changed
+431

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
// systems/SelectionSystem.js
import { clearSelection, addToSelection, setActiveUnit } from './ControlMode.js';
export class SelectionSystem {
constructor(scene) {
this.scene = scene;
this.selectionBox = null;
scene.events.on('selection-start', this.onStart, this);
scene.events.on('selection-end', this.onEnd, this);
}
onStart(pos) {
if (!this.selectionBox) {
this.selectionBox = this.scene.add.rectangle(pos.x, pos.y, 1, 1, 0x00ff00, 0.3)
.setStrokeStyle(1, 0xffffff)
.setVisible(true);
} else {
this.selectionBox.setPosition(pos.x, pos.y).setSize(1, 1).setVisible(true);
}
}
onEnd(rect) {
if (this.selectionBox) {
this.selectionBox.setVisible(false);
}
const units = this.scene.unitGroup.getChildren();
const selected = units.filter(unit => {
const unitRect = unit.getBounds();
return Phaser.Geom.Rectangle.Overlaps(rect, unitRect);
});
clearSelection();
selected.forEach(addToSelection);
if (selected.length > 0) {
setActiveUnit(selected[0]); // 激活第一个
this.scene.events.emit('units-selected', selected);
}
}
}