diff --git a/apps/tetris/ChangeLog b/apps/tetris/ChangeLog new file mode 100644 index 000000000..6366af6c0 --- /dev/null +++ b/apps/tetris/ChangeLog @@ -0,0 +1,2 @@ +0.01: New app! +0.02: Better controls, implement game over. diff --git a/apps/tetris/README.md b/apps/tetris/README.md index 2c41657f4..611c5c25c 100644 --- a/apps/tetris/README.md +++ b/apps/tetris/README.md @@ -4,5 +4,5 @@ Bangle version of the classic game of Tetris. ## Controls -Tapping the screen rotates the pieces once, swiping left, right or down moves the -piece in that direction, if possible. \ No newline at end of file +Tap top part of screen to rotate and move down, tap bottom part to +move left/right. \ No newline at end of file diff --git a/apps/tetris/metadata.json b/apps/tetris/metadata.json index f683a5be7..f10c06c54 100644 --- a/apps/tetris/metadata.json +++ b/apps/tetris/metadata.json @@ -1,12 +1,14 @@ { "id": "tetris", "name": "Tetris", "shortName":"Tetris", - "version":"0.01", + "version":"0.02", "description": "Tetris", "icon": "tetris.png", "readme": "README.md", "tags": "game", - "supports" : ["BANGLEJS2"], + "supports" : ["BANGLEJS2"], + "allow_emulator": true, + "readme": "README.md", "storage": [ {"name":"tetris.app.js","url":"tetris.app.js"}, {"name":"tetris.img","url":"app-icon.js","evaluate":true} diff --git a/apps/tetris/tetris.app.js b/apps/tetris/tetris.app.js index e24a731a9..77c40de9a 100644 --- a/apps/tetris/tetris.app.js +++ b/apps/tetris/tetris.app.js @@ -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 { +function rotate() { 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; +function move(x, y) { 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); } +} + +Bangle.setUI(); +Bangle.on("drag", (e) => { + let h = 176/2; + if (!e.b) + return; + if (e.y < h) { + if (e.x < h) + rotate(); + else { + let i = 0; + for (i=0; i<10; i++) { + move(0, 1); + g.flip(); + } + } + } else { + if (e.x < h) + move(-1, 0); + else + move(1, 0); + } +}); + +Bangle.on("swipe", (x,y) => { + if (y<0) y = 0; + move(x, y); }); drawBoundingBox();