Skip to content

Commit 0c9929a

Browse files
authored
Add files via upload
1 parent 451f850 commit 0c9929a

6 files changed

Lines changed: 41 additions & 20 deletions

File tree

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ <h1>Pacman VR FPS</h1>
170170
<label for="set-turnSpeed">Velocità Rotazione VR</label>
171171
<input type="number" id="set-turnSpeed" value="2.0" min="0.5" max="5.0" step="0.1">
172172
</div>
173+
<div class="setting-row">
174+
<label for="set-leftHanded">Modalità Mancino</label>
175+
<input type="checkbox" id="set-leftHanded" style="width: 20px; height: 20px;">
176+
</div>
173177

174178
<button id="btn-start">Gioca (Modalità Flat)</button>
175179
<div class="vr-hint">Per giocare in realtà virtuale, clicca sul pulsante "ENTER VR"</div>

src/InputManager.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export class InputManager {
5757
}
5858

5959
initVRControls(onSessionStart, onSessionEnd) {
60+
// Determiniamo quale mano spara
61+
const fireHand = CURRENT_SETTINGS.leftHanded ? 'left' : 'right';
62+
6063
for (let i = 0; i < 2; i++) {
6164
const controller = this.renderer.xr.getController(i);
6265

@@ -66,23 +69,26 @@ export class InputManager {
6669

6770
if (xrInputSource.handedness === 'right') {
6871
this.rightController = controller;
69-
if (this.renderer.xr.isPresenting && onSessionStart) {
70-
onSessionStart();
71-
}
7272
} else if (xrInputSource.handedness === 'left') {
7373
this.leftController = controller;
7474
}
75+
76+
// Avvia la sessione quando viene connesso il controller che impugna l'arma
77+
if (xrInputSource.handedness === fireHand && this.renderer.xr.isPresenting && onSessionStart) {
78+
onSessionStart();
79+
}
7580
});
7681

82+
// Ascoltiamo il grilletto sulla mano che spara
7783
controller.addEventListener('selectstart', () => {
78-
if (controller.handedness === 'right') {
84+
if (controller.handedness === fireHand) {
7985
this.isTriggerDown = true;
8086
this.triggerPressedThisFrame = true;
8187
}
8288
});
8389

8490
controller.addEventListener('selectend', () => {
85-
if (controller.handedness === 'right') {
91+
if (controller.handedness === fireHand) {
8692
this.isTriggerDown = false;
8793
}
8894
});
@@ -104,16 +110,19 @@ export class InputManager {
104110
inputX = Number(this.moveState.right) - Number(this.moveState.left);
105111
} else if (this.renderer.xr.isPresenting) {
106112
const session = this.renderer.xr.getSession();
113+
const moveHand = CURRENT_SETTINGS.leftHanded ? 'right' : 'left';
114+
const turnHand = CURRENT_SETTINGS.leftHanded ? 'left' : 'right';
115+
107116
if (session && session.inputSources) {
108117
for (const source of session.inputSources) {
109118
if (source.gamepad && source.gamepad.axes.length >= 4) {
110-
if (source.handedness === 'left') {
119+
if (source.handedness === moveHand) {
111120
const xAxis = source.gamepad.axes[2];
112121
const zAxis = source.gamepad.axes[3];
113122
if (Math.abs(xAxis) > 0.1) inputX = xAxis;
114123
if (Math.abs(zAxis) > 0.1) inputZ = -zAxis;
115124
}
116-
else if (source.handedness === 'right') {
125+
else if (source.handedness === turnHand) {
117126
const turnAxis = source.gamepad.axes[2];
118127
if (Math.abs(turnAxis) > 0.1) {
119128
this.playerRig.rotation.y -= turnAxis * CURRENT_SETTINGS.turnSpeed * delta;
@@ -126,7 +135,6 @@ export class InputManager {
126135
}
127136
}
128137
}
129-
130138
return { inputX, inputZ };
131139
}
132140

src/Player.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ export class Player {
2020
}
2121

2222
onVRSessionStart() {
23-
if (this.weapon && this.input.rightController) {
23+
// Determina il controller corretto
24+
const fireController = CURRENT_SETTINGS.leftHanded ? this.input.leftController : this.input.rightController;
25+
if (this.weapon && fireController) {
2426
if (this.weapon.mesh.parent) {
2527
this.weapon.mesh.parent.remove(this.weapon.mesh);
2628
}
27-
this.input.rightController.add(this.weapon.mesh);
29+
fireController.add(this.weapon.mesh);
2830
this.weapon.mesh.position.set(0, 0, 0);
2931
this.weapon.mesh.rotation.set(0, 0, 0);
3032
}
@@ -36,7 +38,8 @@ export class Player {
3638
this.weapon.mesh.parent.remove(this.weapon.mesh);
3739
}
3840
this.camera.add(this.weapon.mesh);
39-
this.weapon.mesh.position.set(0.3, -0.3, -0.6);
41+
const offsetX = CURRENT_SETTINGS.leftHanded ? -0.3 : 0.3;
42+
this.weapon.mesh.position.set(offsetX, -0.3, -0.6);
4043
this.weapon.mesh.rotation.set(0, 0, 0);
4144
}
4245
}
@@ -62,20 +65,22 @@ export class Player {
6265
update(delta, ghosts) {
6366
if (this.weapon) {
6467
const wStats = this.weapon.stats[this.weapon.currentType];
65-
6668
const shouldShoot = (wStats.automatic && this.input.isTriggerDown) || this.input.triggerPressedThisFrame;
6769

6870
if (shouldShoot) {
69-
const activeController = this.renderer.xr.isPresenting ? this.input.rightController : null;
70-
// Salviamo l'esito dello sparo
71+
// Prendi il controller attivo (destro o sinistro)
72+
const fireController = CURRENT_SETTINGS.leftHanded ? this.input.leftController : this.input.rightController;
73+
const activeController = this.renderer.xr.isPresenting ? fireController : null;
74+
7175
const didShoot = this.weapon.shoot(ghosts, this.scene, activeController);
7276

73-
// --- FEEDBACK ATTICO: RINCULO ---
7477
if (didShoot && this.renderer.xr.isPresenting) {
75-
// Il fucile vibra leggermente ma velocemente, la pistola dà un colpo secco e forte
7678
const intensity = this.weapon.currentType === 'rifle' ? 0.4 : 0.8;
7779
const duration = this.weapon.currentType === 'rifle' ? 50 : 100;
78-
this.input.triggerHaptic('right', intensity, duration);
80+
81+
// Invia l'aptica alla mano corretta
82+
const fireHand = CURRENT_SETTINGS.leftHanded ? 'left' : 'right';
83+
this.input.triggerHaptic(fireHand, intensity, duration);
7984
}
8085
}
8186
}

src/Weapon.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as THREE from 'three';
2-
import { STATS } from './config.js';
2+
import { STATS, CURRENT_SETTINGS } from './config.js';
33
import { createPistolMesh, createRifleMesh } from './WeaponModels.js';
44

55
export class Weapon {
@@ -10,7 +10,9 @@ export class Weapon {
1010
// Contenitore vuoto che ospiterà la mesh dell'arma attiva
1111
this.mesh = new THREE.Group();
1212
this.camera.add(this.mesh);
13-
this.mesh.position.set(0.3, -0.3, -0.6);
13+
14+
const offsetX = CURRENT_SETTINGS.leftHanded ? -0.3 : 0.3;
15+
this.mesh.position.set(offsetX, -0.3, -0.6);
1416

1517
// -- Setup Raycaster per mirare --
1618
this.raycaster = new THREE.Raycaster();

src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const DEFAULT_SETTINGS = {
1919
ghostBaseSpeed: 1.5,
2020
ghostHuntSpeed: 2.5,
2121
playerSpeed: 2.0,
22-
turnSpeed: 2.0
22+
turnSpeed: 2.0,
23+
leftHanded: false
2324
};
2425

2526
// Impostazioni correnti (queste verranno sovrascritte dalla UI del Menu)

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function applySettingsAndStart() {
6464
CURRENT_SETTINGS.ghostHuntSpeed = parseFloat(document.getElementById('set-ghostHuntSpeed').value);
6565
CURRENT_SETTINGS.playerSpeed = parseFloat(document.getElementById('set-playerSpeed').value);
6666
CURRENT_SETTINGS.turnSpeed = parseFloat(document.getElementById('set-turnSpeed').value);
67+
CURRENT_SETTINGS.leftHanded = document.getElementById('set-leftHanded').checked;
6768

6869
// Assicuriamoci che la mappa sia sempre dispari
6970
if (CURRENT_SETTINGS.mapSize % 2 === 0) CURRENT_SETTINGS.mapSize += 1;

0 commit comments

Comments
 (0)