From f09532d6f7722353b3528030b2d65a32fa4d8e62 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 7 Oct 2023 22:28:13 +0200 Subject: [PATCH 1/5] Split functions in preparation. --- apps/tetris/tetris.app.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/tetris/tetris.app.js b/apps/tetris/tetris.app.js index e24a731a9..a84873e36 100644 --- a/apps/tetris/tetris.app.js +++ b/apps/tetris/tetris.app.js @@ -143,24 +143,32 @@ function gameStep() { } } -Bangle.setUI(); -Bangle.on("touch", (e) => { +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("touch", (e) => { + rotate(); +}); + +Bangle.on("swipe", (x,y) => { + if (y<0) y = 0; + move(x, y); }); drawBoundingBox(); From 7a0c3f2bd975eff97eb0f30456601ce4c114d574 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 7 Oct 2023 23:05:05 +0200 Subject: [PATCH 2/5] Implement controls by clicking, implement game over. --- apps/tetris/tetris.app.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/tetris/tetris.app.js b/apps/tetris/tetris.app.js index a84873e36..255437b62 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 { - rotate(); +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) => { From 87afbe89388a4bb9051e5dba1dd7bf65eb7a4954 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sun, 8 Oct 2023 12:00:00 +0200 Subject: [PATCH 3/5] Update metadata/changelogs. --- apps/tetris/ChangeLog | 2 ++ apps/tetris/README.md | 4 ++-- apps/tetris/metadata.json | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 apps/tetris/ChangeLog 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..790874648 100644 --- a/apps/tetris/metadata.json +++ b/apps/tetris/metadata.json @@ -6,7 +6,9 @@ "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} From ade2df3f0fc6990a76727fc3e750f3daadd1c5a0 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sun, 8 Oct 2023 12:05:30 +0200 Subject: [PATCH 4/5] Implement move down with one click. --- apps/tetris/tetris.app.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/tetris/tetris.app.js b/apps/tetris/tetris.app.js index 255437b62..77c40de9a 100644 --- a/apps/tetris/tetris.app.js +++ b/apps/tetris/tetris.app.js @@ -177,8 +177,13 @@ Bangle.on("drag", (e) => { if (e.y < h) { if (e.x < h) rotate(); - else - move(0, 1); + else { + let i = 0; + for (i=0; i<10; i++) { + move(0, 1); + g.flip(); + } + } } else { if (e.x < h) move(-1, 0); From 2dbde15cc4d8c0f1da8f12eb96dca9c9f2ac45be Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sun, 8 Oct 2023 12:10:31 +0200 Subject: [PATCH 5/5] Update version to 0.02 --- apps/tetris/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/tetris/metadata.json b/apps/tetris/metadata.json index 790874648..f10c06c54 100644 --- a/apps/tetris/metadata.json +++ b/apps/tetris/metadata.json @@ -1,7 +1,7 @@ { "id": "tetris", "name": "Tetris", "shortName":"Tetris", - "version":"0.01", + "version":"0.02", "description": "Tetris", "icon": "tetris.png", "readme": "README.md",