Add touch control for mobile devices
This commit is contained in:
@@ -36,8 +36,10 @@
|
|||||||
<a id="git-repo" href="https://github.com/KingOfDog/Tetris.js" target="_blank">Github</a>
|
<a id="git-repo" href="https://github.com/KingOfDog/Tetris.js" target="_blank">Github</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="https://hammerjs.github.io/dist/hammer.js"></script>
|
||||||
<script src="language.js"></script>
|
<script src="language.js"></script>
|
||||||
<script src="tetris.js"></script>
|
<script src="tetris.js"></script>
|
||||||
<script src="menu.js"></script>
|
<script src="menu.js"></script>
|
||||||
|
<script src="touch-control.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@@ -308,7 +308,7 @@ document.addEventListener('keydown', event => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function startGame() {
|
function startGame() {
|
||||||
arena = createMatrix(fieldSize.x, fieldSize.y)
|
arena = createMatrix(fieldSize.x, fieldSize.y);
|
||||||
playerReset();
|
playerReset();
|
||||||
update();
|
update();
|
||||||
updateScore();
|
updateScore();
|
||||||
|
24
touch-control.js
Normal file
24
touch-control.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const hammertime = new Hammer(document.getElementById("tetris"));
|
||||||
|
|
||||||
|
hammertime.on('swipeleft', () => {
|
||||||
|
keys.left.action();
|
||||||
|
});
|
||||||
|
|
||||||
|
hammertime.on('swiperight', () => {
|
||||||
|
keys.right.action();
|
||||||
|
});
|
||||||
|
|
||||||
|
hammertime.on('swipe', (e) => {
|
||||||
|
console.log(e.direction);
|
||||||
|
keys.down.action();
|
||||||
|
});
|
||||||
|
|
||||||
|
hammertime.on('tap', (e) => {
|
||||||
|
if (e.tapCount >= 2) {
|
||||||
|
keys.rotateRight.action();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
hammertime.on('press', () => {
|
||||||
|
keys.down.action();
|
||||||
|
});
|
Reference in New Issue
Block a user