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,59 +272,80 @@ 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("accel", (e) => {
|
Bangle.on("touch", (e) => {
|
||||||
if (state != 1) return;
|
t = rotateTile(ct, 3);
|
||||||
if (control != 2) return;
|
if (moveOk(t, 0, 0)) {
|
||||||
print(e.x);
|
drawTile(ct, ctn, ox+px*8, oy+py*8, true);
|
||||||
linear((0.2-e.x) * 2.5);
|
ct = t;
|
||||||
});
|
drawTile(ct, ctn, ox+px*8, oy+py*8, false);
|
||||||
}
|
|
||||||
if (control == 3) {
|
|
||||||
Bangle.setBarometerPower(true);
|
|
||||||
Bangle.on("pressure", (e) => {
|
|
||||||
if (state != 1) return;
|
|
||||||
if (control != 3) return;
|
|
||||||
let a = e.altitude;
|
|
||||||
if (alt_start == -9999)
|
|
||||||
alt_start = a;
|
|
||||||
a = a - alt_start;
|
|
||||||
//print(e.altitude, a);
|
|
||||||
linear(a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Bangle.on("drag", (e) => {
|
|
||||||
let h = 176/2;
|
|
||||||
if (state == 2) {
|
|
||||||
if (e.b)
|
|
||||||
selectGame();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!e.b)
|
|
||||||
return;
|
|
||||||
if (state == 0) return;
|
|
||||||
if (e.y < h) {
|
|
||||||
if (e.x < h)
|
|
||||||
rotate();
|
|
||||||
else {
|
|
||||||
while (move(0, 1)) {
|
|
||||||
score++;
|
|
||||||
g.flip();
|
|
||||||
}
|
}
|
||||||
redrawStats(true);
|
});
|
||||||
|
|
||||||
|
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) => {
|
||||||
|
if (state != 1) return;
|
||||||
|
if (control != 2) return;
|
||||||
|
print(e.x);
|
||||||
|
linear((0.2-e.x) * 2.5);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
if (control == 3) { // Move
|
||||||
if (control == 1)
|
Bangle.setBarometerPower(true);
|
||||||
linear((e.x - 20) / 156);
|
Bangle.on("pressure", (e) => {
|
||||||
if (control != 0)
|
if (state != 1) return;
|
||||||
return;
|
if (control != 3) return;
|
||||||
if (e.x < h)
|
let a = e.altitude;
|
||||||
move(-1, 0);
|
if (alt_start == -9999)
|
||||||
else
|
alt_start = a;
|
||||||
move(1, 0);
|
a = a - alt_start;
|
||||||
}
|
//print(e.altitude, a);
|
||||||
});
|
linear(a);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Bangle.on("drag", (e) => {
|
||||||
|
let h = 176/2;
|
||||||
|
if (state == 2) {
|
||||||
|
if (e.b)
|
||||||
|
selectGame();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!e.b)
|
||||||
|
return;
|
||||||
|
if (state == 0) return;
|
||||||
|
if (e.y < h) {
|
||||||
|
if (e.x < h)
|
||||||
|
rotate();
|
||||||
|
else {
|
||||||
|
while (move(0, 1)) {
|
||||||
|
score++;
|
||||||
|
g.flip();
|
||||||
|
}
|
||||||
|
redrawStats(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (control == 1)
|
||||||
|
linear((e.x - 20) / 156);
|
||||||
|
if (control != 0)
|
||||||
|
return;
|
||||||
|
if (e.x < h)
|
||||||
|
move(-1, 0);
|
||||||
|
else
|
||||||
|
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