diff --git a/src/common/snake.js b/src/common/snake.js index 88e34e4..734e401 100644 --- a/src/common/snake.js +++ b/src/common/snake.js @@ -34,6 +34,30 @@ function turn(current, desired) { return desired } +// Classify every segment as a texture piece (head/body/corner/tail + compass side), +// so the page can render each cell with the right PNG. Returns one name per segment. +// Sides are screen compass (y grows down): e/w/n/s = right/left/up/down. +function renderPieces(snakeCells, dir) { + const D = { '1,0': 'e', '-1,0': 'w', '0,-1': 'n', '0,1': 's' } + const opp = { e: 'w', w: 'e', n: 's', s: 'n' } + return snakeCells.map((s, i) => { + if (i === 0) return 'head_' + D[dir.x + ',' + dir.y] + const prev = snakeCells[i - 1] + const next = snakeCells[i + 1] + const from = D[(prev.x - s.x) + ',' + (prev.y - s.y)] // side toward head + if (!next) return 'tail_' + opp[from] // tip points away from body + const to = D[(next.x - s.x) + ',' + (next.y - s.y)] // side toward tail tip + if ((from === 'e' || from === 'w') && (to === 'e' || to === 'w')) return 'body_h' + if ((from === 'n' || from === 's') && (to === 'n' || to === 's')) return 'body_v' + // corner: name = the two sides it connects; pairs are alphabetically sorted + const pair = [from, to].sort() + if (pair[0] === 'e' && pair[1] === 'n') return 'corner_en' + if (pair[0] === 'n' && pair[1] === 'w') return 'corner_nw' + if (pair[0] === 'e' && pair[1] === 's') return 'corner_es' + return 'corner_sw' + }) +} + // Rotate a direction 90°: clockwise order right->down->left->up. Always ±90°, never a reversal. function rotateDir(dir, clockwise) { const order = [{ x: 1, y: 0 }, { x: 0, y: 1 }, { x: -1, y: 0 }, { x: 0, y: -1 }] @@ -56,4 +80,4 @@ function spawnFood(snake, N) { return { x, y } } -module.exports = { initialSnake, step, turn, rotateDir, spawnFood } +module.exports = { initialSnake, step, turn, renderPieces, rotateDir, spawnFood } diff --git a/src/common/tex/apple.png b/src/common/tex/apple.png new file mode 100644 index 0000000..556ee0e Binary files /dev/null and b/src/common/tex/apple.png differ diff --git a/src/common/tex/board.png b/src/common/tex/board.png new file mode 100644 index 0000000..3fc917a Binary files /dev/null and b/src/common/tex/board.png differ diff --git a/src/common/tex/body.png b/src/common/tex/body.png new file mode 100644 index 0000000..186c627 Binary files /dev/null and b/src/common/tex/body.png differ diff --git a/src/common/tex/body_h.png b/src/common/tex/body_h.png new file mode 100644 index 0000000..2e50ed1 Binary files /dev/null and b/src/common/tex/body_h.png differ diff --git a/src/common/tex/body_v.png b/src/common/tex/body_v.png new file mode 100644 index 0000000..f43235b Binary files /dev/null and b/src/common/tex/body_v.png differ diff --git a/src/common/tex/corner_en.png b/src/common/tex/corner_en.png new file mode 100644 index 0000000..3bb5503 Binary files /dev/null and b/src/common/tex/corner_en.png differ diff --git a/src/common/tex/corner_es.png b/src/common/tex/corner_es.png new file mode 100644 index 0000000..bdccc5f Binary files /dev/null and b/src/common/tex/corner_es.png differ diff --git a/src/common/tex/corner_nw.png b/src/common/tex/corner_nw.png new file mode 100644 index 0000000..9382c87 Binary files /dev/null and b/src/common/tex/corner_nw.png differ diff --git a/src/common/tex/corner_sw.png b/src/common/tex/corner_sw.png new file mode 100644 index 0000000..06020aa Binary files /dev/null and b/src/common/tex/corner_sw.png differ diff --git a/src/common/tex/head_e.png b/src/common/tex/head_e.png new file mode 100644 index 0000000..29d2ad0 Binary files /dev/null and b/src/common/tex/head_e.png differ diff --git a/src/common/tex/head_n.png b/src/common/tex/head_n.png new file mode 100644 index 0000000..89772e8 Binary files /dev/null and b/src/common/tex/head_n.png differ diff --git a/src/common/tex/head_s.png b/src/common/tex/head_s.png new file mode 100644 index 0000000..6b97ccc Binary files /dev/null and b/src/common/tex/head_s.png differ diff --git a/src/common/tex/head_w.png b/src/common/tex/head_w.png new file mode 100644 index 0000000..2878d29 Binary files /dev/null and b/src/common/tex/head_w.png differ diff --git a/src/common/tex/tail_e.png b/src/common/tex/tail_e.png new file mode 100644 index 0000000..1cbeb52 Binary files /dev/null and b/src/common/tex/tail_e.png differ diff --git a/src/common/tex/tail_n.png b/src/common/tex/tail_n.png new file mode 100644 index 0000000..5891509 Binary files /dev/null and b/src/common/tex/tail_n.png differ diff --git a/src/common/tex/tail_s.png b/src/common/tex/tail_s.png new file mode 100644 index 0000000..9168b17 Binary files /dev/null and b/src/common/tex/tail_s.png differ diff --git a/src/common/tex/tail_w.png b/src/common/tex/tail_w.png new file mode 100644 index 0000000..bee4e41 Binary files /dev/null and b/src/common/tex/tail_w.png differ diff --git a/src/manifest.json b/src/manifest.json index 24dcb84..7b480cb 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,8 +2,8 @@ "package": "com.ilias.snake", "name": "SNAKE", "icon": "/common/icon.png", - "versionName": "0.5", - "versionCode": 5, + "versionName": "0.6", + "versionCode": 6, "minAPILevel": 1, "deviceTypeList": [ "watch" diff --git a/src/pages/index/index.ux b/src/pages/index/index.ux index f8387c2..0f29379 100644 --- a/src/pages/index/index.ux +++ b/src/pages/index/index.ux @@ -1,9 +1,9 @@