Implement controls by clicking, implement game over.

pull/3040/head
Pavel Machek 2023-10-07 23:05:05 +02:00
parent f09532d6f7
commit 7a0c3f2bd9
1 changed files with 23 additions and 2 deletions

View File

@ -95,6 +95,11 @@ function redrawPF(ly) {
}
}
function gameOver() {
g.setColor(1, 1, 1).setFontAlign(0, 1, 0).setFont("Vector",22)
.drawString("Game Over", 176/2, 76);
}
function insertAndCheck() {
for (y=0; y<ct.length; ++y)
for (x=0; x<ct[y].length; ++x)
@ -119,6 +124,9 @@ function insertAndCheck() {
ct = rotateTile(tiles[ctn], ntr);
ntr = Math.floor(Math.random()*4);
showNext(ntn, ntr);
if (!moveOk(ct, 0, 0)) {
gameOver();
}
}
function moveOk(t, dx, dy) {
@ -162,8 +170,21 @@ function move(x, y) {
}
Bangle.setUI();
Bangle.on("touch", (e) => {
Bangle.on("drag", (e) => {
let h = 176/2;
if (!e.b)
return;
if (e.y < h) {
if (e.x < h)
rotate();
else
move(0, 1);
} else {
if (e.x < h)
move(-1, 0);
else
move(1, 0);
}
});
Bangle.on("swipe", (x,y) => {