Skip to content

Commit

Permalink
Nivel
Browse files Browse the repository at this point in the history
  • Loading branch information
drbn68 committed Dec 22, 2023
1 parent 8cfd580 commit 267e591
Showing 1 changed file with 66 additions and 5 deletions.
71 changes: 66 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@
}


function onResize() {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
}
function onResize() {
var width = window.innerWidth;
var height = window.innerHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}


function onMoveKey(axis) {
Expand Down Expand Up @@ -294,6 +296,15 @@
KeyboardJS.bind.axis('left', 'right', 'down', 'up', onMoveKey);
KeyboardJS.bind.axis('h', 'l', 'j', 'k', onMoveKey);
$(window).resize(onResize);




// Eventos táctiles para dispositivos móviles
document.addEventListener('touchstart', handleTouchStart, false);
document.addEventListener('touchmove', handleTouchMove, false);




// Set the initial game state.
Expand All @@ -305,6 +316,53 @@
})


var xDown = null;
var yDown = null;

function getTouches(evt) {
return evt.touches || // API de navegador
evt.originalEvent.touches; // jQuery
}

function handleTouchStart(evt) {
const firstTouch = getTouches(evt)[0];
xDown = firstTouch.clientX;
yDown = firstTouch.clientY;
};

function handleTouchMove(evt) {
if ( ! xDown || ! yDown ) {
return;
}

var xUp = evt.touches[0].clientX;
var yUp = evt.touches[0].clientY;

var xDiff = xDown - xUp;
var yDiff = yDown - yUp;

if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
if ( xDiff > 0 ) {
/* izquierda swipe */
onMoveKey([-1, 0]);
} else {
/* derecha swipe */
onMoveKey([1, 0]);
}
} else {
if ( yDiff > 0 ) {
/* arriba swipe */
onMoveKey([0, -1]);
} else {
/* abajo swipe */
onMoveKey([0, 1]);
}
}
// Reset values
xDown = null;
yDown = null;
};


</script>

Expand All @@ -315,6 +373,7 @@
margin: 0;
padding: 0;
font-family: 'Helvetica';
overflow: hidden;
}

#instructions {
Expand Down Expand Up @@ -346,6 +405,8 @@

</style>

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

</head>

<body>
Expand Down

0 comments on commit 267e591

Please sign in to comment.