mirror of
https://github.com/cmclark00/tetris-3d.git
synced 2025-05-17 23:25:21 +01:00
Fix issues with 3D rotation and hard drop interaction
This commit is contained in:
parent
742cbb1297
commit
c29e868320
1 changed files with 48 additions and 16 deletions
64
script.js
64
script.js
|
@ -1059,6 +1059,12 @@ class Piece {
|
||||||
this.rotationTransition = false;
|
this.rotationTransition = false;
|
||||||
this.rotationProgress = 0;
|
this.rotationProgress = 0;
|
||||||
|
|
||||||
|
// Clear target references to avoid memory leaks and state issues
|
||||||
|
this.targetTetromino = null;
|
||||||
|
this.targetPattern = undefined;
|
||||||
|
this.targetKick = undefined;
|
||||||
|
this.originalTetromino = null;
|
||||||
|
|
||||||
// Reset rotation angles
|
// Reset rotation angles
|
||||||
this.rotationAngleX = 0;
|
this.rotationAngleX = 0;
|
||||||
this.rotationAngleY = 0;
|
this.rotationAngleY = 0;
|
||||||
|
@ -1105,10 +1111,17 @@ class Piece {
|
||||||
|
|
||||||
if (this.completionEffectProgress >= 1) {
|
if (this.completionEffectProgress >= 1) {
|
||||||
this.showCompletionEffect = false;
|
this.showCompletionEffect = false;
|
||||||
|
this.completionEffectProgress = 0;
|
||||||
|
|
||||||
// Reset rotation angles
|
// Reset rotation angles
|
||||||
this.rotationAngleX = 0;
|
this.rotationAngleX = 0;
|
||||||
this.rotationAngleY = 0;
|
this.rotationAngleY = 0;
|
||||||
this.rotationAngleZ = 0;
|
this.rotationAngleZ = 0;
|
||||||
|
|
||||||
|
// Clear all rotation references
|
||||||
|
this.rotationDirection = null;
|
||||||
|
this.originalTetromino = null;
|
||||||
|
this.targetTetromino = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2306,6 +2319,8 @@ let secondLastTapX = 0; // Track position of second-to-last tap
|
||||||
let secondLastTapY = 0; // Track position of second-to-last tap
|
let secondLastTapY = 0; // Track position of second-to-last tap
|
||||||
const TAP_DISTANCE_THRESHOLD = 40; // Increased from 20 to be more forgiving for double-taps
|
const TAP_DISTANCE_THRESHOLD = 40; // Increased from 20 to be more forgiving for double-taps
|
||||||
const MOVE_COOLDOWN = 60; // Cooldown between moves to prevent too rapid movement
|
const MOVE_COOLDOWN = 60; // Cooldown between moves to prevent too rapid movement
|
||||||
|
let tapCount = 0;
|
||||||
|
let doubleTapInProgress = false;
|
||||||
|
|
||||||
// Initialize touch controls
|
// Initialize touch controls
|
||||||
function initTouchControls() {
|
function initTouchControls() {
|
||||||
|
@ -2394,40 +2409,57 @@ function handleTouchEnd(event) {
|
||||||
const touchX = touch.clientX;
|
const touchX = touch.clientX;
|
||||||
const touchY = touch.clientY;
|
const touchY = touch.clientY;
|
||||||
|
|
||||||
|
// Skip if we're in the middle of a rotation animation
|
||||||
|
if (p.rotationTransition || p.showCompletionEffect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a double tap is in progress, prevent further processing
|
||||||
|
if (doubleTapInProgress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for tap (quick touch)
|
// Check for tap (quick touch)
|
||||||
if (touchDuration < TAP_THRESHOLD) {
|
if (touchDuration < TAP_THRESHOLD) {
|
||||||
// Calculate distances between taps
|
// Calculate distance from last tap
|
||||||
const distanceFromLastTap = Math.sqrt(
|
const distanceFromLastTap = Math.sqrt(
|
||||||
Math.pow(touchX - lastTapX, 2) +
|
Math.pow(touchX - lastTapX, 2) +
|
||||||
Math.pow(touchY - lastTapY, 2)
|
Math.pow(touchY - lastTapY, 2)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check for double tap (for hard drop)
|
const timeSinceLastTap = touchEndTime - lastTapTime;
|
||||||
const timeBetweenTaps = touchEndTime - lastTapTime;
|
|
||||||
|
|
||||||
if (lastTapTime > 0 && timeBetweenTaps < DOUBLE_TAP_THRESHOLD && distanceFromLastTap < TAP_DISTANCE_THRESHOLD) {
|
// Check for double tap (two taps close together in time and position)
|
||||||
// This is a double-tap, do hard drop
|
if (timeSinceLastTap < DOUBLE_TAP_THRESHOLD && distanceFromLastTap < TAP_DISTANCE_THRESHOLD) {
|
||||||
|
// This is a double tap - perform hard drop
|
||||||
|
doubleTapInProgress = true;
|
||||||
|
|
||||||
|
// Perform the hard drop
|
||||||
p.hardDrop();
|
p.hardDrop();
|
||||||
|
|
||||||
// Reset tap tracking to prevent any further actions
|
// Reset tap tracking
|
||||||
|
tapCount = 0;
|
||||||
lastTapTime = 0;
|
lastTapTime = 0;
|
||||||
lastTapX = 0;
|
lastTapX = 0;
|
||||||
lastTapY = 0;
|
lastTapY = 0;
|
||||||
|
|
||||||
// Debug
|
// Reset the double tap flag after a delay
|
||||||
console.log("Double tap detected - hard drop");
|
setTimeout(() => {
|
||||||
return;
|
doubleTapInProgress = false;
|
||||||
}
|
}, 300);
|
||||||
|
|
||||||
// Only rotate if we're not in the middle of another action
|
|
||||||
if (!p.rotationTransition && !p.showCompletionEffect) {
|
|
||||||
// Single tap - rotates piece
|
|
||||||
p.rotate('right');
|
|
||||||
|
|
||||||
// Update tracking for potential double tap
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a single tap
|
||||||
|
if (!doubleTapInProgress) {
|
||||||
|
// If this might be the first tap of a double tap, record it
|
||||||
lastTapTime = touchEndTime;
|
lastTapTime = touchEndTime;
|
||||||
lastTapX = touchX;
|
lastTapX = touchX;
|
||||||
lastTapY = touchY;
|
lastTapY = touchY;
|
||||||
|
|
||||||
|
// Only rotate on single tap if we're not expecting a double tap
|
||||||
|
p.rotate('right');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue