tetris: bug fixes, add back swipe controls
parent
1a1b79d41b
commit
60bab26d83
|
|
@ -115,7 +115,7 @@ function calculateSpeed() {
|
||||||
step = 20; // usually limited by the hardware
|
step = 20; // usually limited by the hardware
|
||||||
// levels 15+ are programmed to go faster by skipping lines
|
// levels 15+ are programmed to go faster by skipping lines
|
||||||
}
|
}
|
||||||
print(`level ${level}: drop interval ${step}ms`)
|
print(`level ${level}: drop interval ${step}ms`);
|
||||||
if (control == 3)
|
if (control == 3)
|
||||||
step = step*2;
|
step = step*2;
|
||||||
dropInterval = step;
|
dropInterval = step;
|
||||||
|
|
@ -272,8 +272,28 @@ function linear(x) {
|
||||||
|
|
||||||
function newGame() {
|
function newGame() {
|
||||||
E.showMenu();
|
E.showMenu();
|
||||||
Bangle.setUI();
|
Bangle.setUI({mode : "custom", btn: () => load()});
|
||||||
if (control == 2) {
|
if (control == 4) { // Swipe
|
||||||
|
Bangle.on("touch", (e) => {
|
||||||
|
t = rotateTile(ct, 3);
|
||||||
|
if (moveOk(t, 0, 0)) {
|
||||||
|
drawTile(ct, ctn, ox+px*8, oy+py*8, true);
|
||||||
|
ct = t;
|
||||||
|
drawTile(ct, ctn, ox+px*8, oy+py*8, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Bangle.on("swipe", (x,y) => {
|
||||||
|
if (y<0) y = 0;
|
||||||
|
if (moveOk(ct, x, y)) {
|
||||||
|
drawTile(ct, ctn, ox+px*8, oy+py*8, true);
|
||||||
|
px += x;
|
||||||
|
py += y;
|
||||||
|
drawTile(ct, ctn, ox+px*8, oy+py*8, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else { // control != 4
|
||||||
|
if (control == 2) { // Tilt
|
||||||
Bangle.on("accel", (e) => {
|
Bangle.on("accel", (e) => {
|
||||||
if (state != 1) return;
|
if (state != 1) return;
|
||||||
if (control != 2) return;
|
if (control != 2) return;
|
||||||
|
|
@ -281,7 +301,7 @@ function newGame() {
|
||||||
linear((0.2-e.x) * 2.5);
|
linear((0.2-e.x) * 2.5);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (control == 3) {
|
if (control == 3) { // Move
|
||||||
Bangle.setBarometerPower(true);
|
Bangle.setBarometerPower(true);
|
||||||
Bangle.on("pressure", (e) => {
|
Bangle.on("pressure", (e) => {
|
||||||
if (state != 1) return;
|
if (state != 1) return;
|
||||||
|
|
@ -325,6 +345,7 @@ function newGame() {
|
||||||
move(1, 0);
|
move(1, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
setWatch(() => {
|
setWatch(() => {
|
||||||
if (state == 1)
|
if (state == 1)
|
||||||
pauseGame();
|
pauseGame();
|
||||||
|
|
@ -333,9 +354,9 @@ function newGame() {
|
||||||
}, BTN1, {repeat: true});
|
}, BTN1, {repeat: true});
|
||||||
|
|
||||||
initGame();
|
initGame();
|
||||||
drawGame();
|
|
||||||
state = 1;
|
|
||||||
calculateSpeed();
|
calculateSpeed();
|
||||||
|
state = 1;
|
||||||
|
drawGame();
|
||||||
var gi = setInterval(gameStep, 20);
|
var gi = setInterval(gameStep, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,8 +367,8 @@ function drawGame() {
|
||||||
.drawString("Level", 22, 80)
|
.drawString("Level", 22, 80)
|
||||||
.drawString("Lines", 22, 130)
|
.drawString("Lines", 22, 130)
|
||||||
.drawString("Next", 176-22, 30);
|
.drawString("Next", 176-22, 30);
|
||||||
showNext(ntn, ntr);
|
|
||||||
redrawStats();
|
redrawStats();
|
||||||
|
showNext(ntn, ntr);
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectGame() {
|
function selectGame() {
|
||||||
|
|
@ -359,6 +380,7 @@ function selectGame() {
|
||||||
menu["Drag"] = () => { control = 1; newGame(); };
|
menu["Drag"] = () => { control = 1; newGame(); };
|
||||||
menu["Tilt"] = () => { control = 2; newGame(); };
|
menu["Tilt"] = () => { control = 2; newGame(); };
|
||||||
menu["Pressure"] = () => { control = 3; newGame(); };
|
menu["Pressure"] = () => { control = 3; newGame(); };
|
||||||
|
menu["Swipe"] = () => { control = 4; newGame(); };
|
||||||
level = 1;
|
level = 1;
|
||||||
menu["Level"] = {
|
menu["Level"] = {
|
||||||
value : 1,
|
value : 1,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue