mirror of
http://junepve.top:3000/chicrobot/CINC.git
synced 2026-10-30 07:41:29 +08:00
feat(SS) 添加地图
This commit is contained in:
1 parent
2616dc21f1
commit
d3669bd44e
13 files changed
+1359
-99
No files matched your search
@@ -0,0 +1,74 @@
|
||||
// scenes/GameScene.js
|
||||
|
||||
export class GameScene extends Phaser.Scene {
|
||||
constructor() {
|
||||
super('GameScene');
|
||||
this.moveSpeed = 200;
|
||||
this.joystickId = null;
|
||||
this.inputPlugin = null;
|
||||
}
|
||||
|
||||
preload() {
|
||||
}
|
||||
|
||||
create() {
|
||||
const graphics = this.make.graphics();
|
||||
graphics.fillStyle(0xffffff, 1);
|
||||
graphics.fillRect(0, 0, 32, 32);
|
||||
graphics.generateTexture('player', 32, 32);
|
||||
graphics.destroy();
|
||||
|
||||
this.player = this.physics.add.sprite(400, 300, 'player');
|
||||
this.player.setCollideWorldBounds(true);
|
||||
|
||||
// 获取插件实例(更可靠的方式)
|
||||
this.inputPlugin = this.plugins.get('InputPlugin');
|
||||
|
||||
if (this.inputPlugin) {
|
||||
// 添加触摸轮盘
|
||||
this.joystickId = this.inputPlugin.createJoystick({
|
||||
id: 'movement',
|
||||
x: 100,
|
||||
y: this.sys.game.config.height - 100,
|
||||
radius: 60,
|
||||
maxDistance: 40
|
||||
});
|
||||
} else {
|
||||
console.error('InputPlugin 未找到!');
|
||||
}
|
||||
|
||||
// 添加提示文字
|
||||
this.add.text(10, 10, '使用 WASD/方向键 或 触摸轮盘移动', { fill: '#ffffff', fontSize: '16px' });
|
||||
}
|
||||
|
||||
update() {
|
||||
// 重置速度
|
||||
this.player.setVelocity(0);
|
||||
|
||||
// 键盘输入
|
||||
const cursors = this.input.keyboard.createCursorKeys();
|
||||
const keys = this.input.keyboard.addKeys('W,A,S,D');
|
||||
|
||||
if (cursors.up.isDown || keys.W.isDown) {
|
||||
this.player.setVelocityY(-this.moveSpeed);
|
||||
}
|
||||
if (cursors.down.isDown || keys.S.isDown) {
|
||||
this.player.setVelocityY(this.moveSpeed);
|
||||
}
|
||||
if (cursors.left.isDown || keys.A.isDown) {
|
||||
this.player.setVelocityX(-this.moveSpeed);
|
||||
}
|
||||
if (cursors.right.isDown || keys.D.isDown) {
|
||||
this.player.setVelocityX(this.moveSpeed);
|
||||
}
|
||||
|
||||
// 触摸轮盘输入(带归一化)
|
||||
if (this.inputPlugin && this.joystickId) {
|
||||
const joystickNormalized = this.inputPlugin.getJoystickNormalized(this.joystickId);
|
||||
if (joystickNormalized.x !== 0 || joystickNormalized.y !== 0) {
|
||||
this.player.setVelocityX(joystickNormalized.x * this.moveSpeed);
|
||||
this.player.setVelocityY(joystickNormalized.y * this.moveSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
// scenes/JoystickTestScene.js
|
||||
|
||||
import { InputPlugin } from '../plugins/InputPlugin.js';
|
||||
|
||||
export class JoystickTestScene extends Phaser.Scene {
|
||||
constructor() {
|
||||
super('JoystickTestScene');
|
||||
this.moveSpeed = 200;
|
||||
this.sprintSpeed = 400; // 冲刺速度
|
||||
this.inputPlugin = null;
|
||||
this.joystickId = null;
|
||||
this.sprintButtonId = null;
|
||||
this.isSprinting = false;
|
||||
}
|
||||
|
||||
preload() {
|
||||
}
|
||||
|
||||
create() {
|
||||
// 创建背景
|
||||
this.cameras.main.setBackgroundColor('#2c3e50');
|
||||
|
||||
// 创建玩家
|
||||
const graphics = this.make.graphics();
|
||||
graphics.fillStyle(0x3498db, 1);
|
||||
graphics.fillRect(0, 0, 40, 40);
|
||||
graphics.generateTexture('player', 40, 40);
|
||||
graphics.destroy();
|
||||
|
||||
this.player = this.physics.add.sprite(400, 300, 'player');
|
||||
this.player.setCollideWorldBounds(true);
|
||||
|
||||
// 直接创建 InputPlugin 实例(绕过插件系统)
|
||||
try {
|
||||
this.inputPlugin = new InputPlugin(this, this.plugins);
|
||||
console.log('直接创建 InputPlugin:', this.inputPlugin);
|
||||
|
||||
// 手动启动插件
|
||||
this.inputPlugin.boot();
|
||||
|
||||
// 测试插件方法
|
||||
const testResult = this.inputPlugin.testMethod();
|
||||
console.log('插件测试结果:', testResult);
|
||||
|
||||
// 添加移动轮盘
|
||||
this.joystickId = this.inputPlugin.createJoystick({
|
||||
id: 'movement',
|
||||
x: 150,
|
||||
y: this.sys.game.config.height - 150,
|
||||
radius: 80,
|
||||
maxDistance: 60
|
||||
});
|
||||
console.log('创建轮盘:', this.joystickId);
|
||||
|
||||
// 添加冲刺按钮
|
||||
this.sprintButtonId = this.inputPlugin.createButton({
|
||||
id: 'sprint',
|
||||
x: this.sys.game.config.width - 150,
|
||||
y: this.sys.game.config.height - 150,
|
||||
width: 100,
|
||||
height: 100,
|
||||
label: '冲刺',
|
||||
onDown: () => {
|
||||
this.isSprinting = true;
|
||||
console.log('开始冲刺');
|
||||
},
|
||||
onUp: () => {
|
||||
this.isSprinting = false;
|
||||
console.log('结束冲刺');
|
||||
}
|
||||
});
|
||||
console.log('创建冲刺按钮:', this.sprintButtonId);
|
||||
|
||||
// 添加提示文字
|
||||
this.add.text(10, 10, '触摸轮盘测试场景', {
|
||||
fill: '#ffffff',
|
||||
fontSize: '24px',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
this.add.text(10, 50, '使用左侧轮盘移动', {
|
||||
fill: '#ffffff',
|
||||
fontSize: '16px',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
this.add.text(10, 80, '使用右侧按钮冲刺', {
|
||||
fill: '#ffffff',
|
||||
fontSize: '16px',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
this.add.text(10, 110, '使用 WASD 或方向键也可以移动', {
|
||||
fill: '#ffffff',
|
||||
fontSize: '16px',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
// 显示轮盘状态
|
||||
this.statusText = this.add.text(10, 150, '轮盘状态: 未激活', {
|
||||
fill: '#ffffff',
|
||||
fontSize: '14px',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
// 添加适配器架构信息
|
||||
this.add.text(10, 300, '适配器架构信息:', {
|
||||
fill: '#ffffff',
|
||||
fontSize: '16px',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
this.add.text(10, 330, '- 核心: InputSystem (引擎无关)', {
|
||||
fill: '#ffffff',
|
||||
fontSize: '14px',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
this.add.text(10, 360, '- 适配器: PhaserInputAdapter', {
|
||||
fill: '#ffffff',
|
||||
fontSize: '14px',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
this.add.text(10, 390, '- 插件: InputPlugin (场景插件)', {
|
||||
fill: '#ffffff',
|
||||
fontSize: '14px',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('创建 InputPlugin 失败:', error);
|
||||
this.add.text(10, 10, 'InputPlugin 初始化失败!', {
|
||||
fill: '#ff0000',
|
||||
fontSize: '24px'
|
||||
});
|
||||
this.add.text(10, 50, '错误: ' + error.message, {
|
||||
fill: '#ffffff',
|
||||
fontSize: '16px'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
// 重置速度
|
||||
this.player.setVelocity(0);
|
||||
|
||||
// 确定当前速度(根据是否冲刺)
|
||||
const currentSpeed = this.isSprinting ? this.sprintSpeed : this.moveSpeed;
|
||||
|
||||
// 键盘输入
|
||||
const cursors = this.input.keyboard.createCursorKeys();
|
||||
const keys = this.input.keyboard.addKeys('W,A,S,D,SHIFT');
|
||||
|
||||
let hasKeyboardInput = false;
|
||||
|
||||
// 检查冲刺键(Shift)
|
||||
if (keys.SHIFT.isDown) {
|
||||
this.isSprinting = true;
|
||||
} else if (!this.inputPlugin || this.inputPlugin.isButtonUp(this.sprintButtonId)) {
|
||||
this.isSprinting = false;
|
||||
}
|
||||
|
||||
if (cursors.up.isDown || keys.W.isDown) {
|
||||
this.player.setVelocityY(-currentSpeed);
|
||||
hasKeyboardInput = true;
|
||||
}
|
||||
if (cursors.down.isDown || keys.S.isDown) {
|
||||
this.player.setVelocityY(currentSpeed);
|
||||
hasKeyboardInput = true;
|
||||
}
|
||||
if (cursors.left.isDown || keys.A.isDown) {
|
||||
this.player.setVelocityX(-currentSpeed);
|
||||
hasKeyboardInput = true;
|
||||
}
|
||||
if (cursors.right.isDown || keys.D.isDown) {
|
||||
this.player.setVelocityX(currentSpeed);
|
||||
hasKeyboardInput = true;
|
||||
}
|
||||
|
||||
// 触摸轮盘输入
|
||||
if (this.inputPlugin && this.joystickId) {
|
||||
try {
|
||||
const joystickNormalized = this.inputPlugin.getJoystickNormalized(this.joystickId);
|
||||
const joystickMagnitude = this.inputPlugin.getJoystickMagnitude(this.joystickId);
|
||||
|
||||
if (joystickNormalized.x !== 0 || joystickNormalized.y !== 0) {
|
||||
this.player.setVelocityX(joystickNormalized.x * currentSpeed);
|
||||
this.player.setVelocityY(joystickNormalized.y * currentSpeed);
|
||||
}
|
||||
|
||||
// 更新状态文字
|
||||
if (this.statusText) {
|
||||
const sprintStatus = this.isSprinting ? '(冲刺中)' : '';
|
||||
if (joystickMagnitude > 0) {
|
||||
this.statusText.setText(`轮盘状态: 激活${sprintStatus}\n力度: ${joystickMagnitude.toFixed(2)}\n方向: X=${joystickNormalized.x.toFixed(2)}, Y=${joystickNormalized.y.toFixed(2)}\n速度: ${currentSpeed}`);
|
||||
} else if (hasKeyboardInput) {
|
||||
this.statusText.setText(`轮盘状态: 未激活${sprintStatus} (使用键盘)\n速度: ${currentSpeed}`);
|
||||
} else {
|
||||
this.statusText.setText(`轮盘状态: 未激活${sprintStatus}\n速度: ${currentSpeed}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('轮盘更新失败:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this.inputPlugin) {
|
||||
this.inputPlugin.destroy();
|
||||
}
|
||||
super.destroy();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user