{"id":197264,"student_id":12205,"content":"var player = createSprite(\"player.png\");\nvar shadow = createSprite(\"shadow.png\");\nvar target = createSprite(\"target.png\");\ntarget.moveTo(630, 470);\ntarget.scale = 0.7;\nshadow.opacity = 0;\nplayer.scale = 0.7;\n\nplayer.from = {x: 0, y: 0}\nplayer.to = {x: 0, y: 0}\nplayer.x = 10;\nplayer.y = 10;\nplayer.nextDirection;\n\nvar status = '';\nvar SIZE = 20;\nvar W = 640/SIZE;\nvar H = 480/SIZE;\nvar grid = [];\nvar groups = [];\n\nfor (var x=0; x\u003cW; x++) {\n grid[x] = [];\n for (var y=0; y\u003cH; y++) {\n grid[x][y] = '1234';\n groups.push([y*W + x]);\n }\n}\n\nfunction merge () {\n\n if (groups.length \u003c= 1) return;\n\n var rand = Math.floor(Math.random()*groups.length);\n var group1 = groups.splice(rand, 1)[0];\n var group2 = [];\n var a, b, direction;\n\n while (true) {\n a = group1[Math.floor(Math.random()*group1.length)];\n b = direction = undefined;\n\n direction = Math.ceil(Math.random()*4);\n\n if (direction == 1) b = a - W;\n if (direction == 2) b = a + 1;\n if (direction == 3) b = a + W;\n if (direction == 4) b = a - 1;\n\n if (group1.includes(b)) continue;\n if (b \u003c 0 || b \u003e W*H-1) continue;\n if (a%W == 0 \u0026\u0026 direction == 4) continue;\n if (a%W == W-1 \u0026\u0026 direction == 2) continue;\n\n var cell1 = grid[a%W][Math.floor(a/W)];\n var cell2 = grid[b%W][Math.floor(b/W)];\n grid[a%W][Math.floor(a/W)] = cell1.replace(direction, '');\n grid[b%W][Math.floor(b/W)] = cell2.replace(direction \u003e 2 ? direction - 2 : direction + 2, '');\n\n break;\n }\n\n for (var i=0; i\u003cgroups.length; i++) {\n if (groups[i].includes(b)) {\n var index = groups.indexOf(groups[i]);\n group2 = groups.splice(index, 1)[0];\n }\n }\n groups.push(group1.concat(group2));\n}\n\nforever(function(){\n\n if (groups.length \u003e 1) {\n for(var i=0; i\u003c4; i++) merge();\n }\n\n if (status == 'gameOver') {\n shadow.opacity -= 0.01;\n if (shadow.opacity \u003c 0) shadow.opacity = 0;\n } else if (shadow.opacity \u003c 1) {\n shadow.opacity += 0.005;\n }\n if (player.from.x == 31 \u0026\u0026 player.from.y == 23) { \n status = 'gameOver'\n }\n shadow.moveTo(player);\n\n for (var x=0; x\u003cgrid.length; x++) {\n for (var y=0; y\u003cgrid[x].length; y++) {\n var cell = grid[x][y];\n if (cell.includes(1)) pen.drawRect(x*SIZE, y*SIZE, SIZE, 2);\n if (cell.includes(2)) pen.drawRect(x*SIZE + SIZE - 2, y*SIZE, 2, SIZE);\n if (cell.includes(3)) pen.drawRect(x*SIZE, y*SIZE + SIZE - 2, SIZE, 2);\n if (cell.includes(4)) pen.drawRect(x*SIZE, y*SIZE, 2, SIZE);\n }\n }\n});\n\nforever(function(){\n\n if (key.up) player.nextDirection = 1;\n if (key.right) player.nextDirection = 2;\n if (key.down) player.nextDirection = 3;\n if (key.left) player.nextDirection = 4;\n\n var x = player.to.x*20 + 10;\n var y = player.to.y*20 + 10;\n\n player.toward(x, y);\n\n if (player.distanceTo(x, y) \u003c 0.5) {\n player.moveTo(x, y);\n player.from = player.to;\n\n if (!grid[player.from.x][player.from.y].includes(player.nextDirection)) {\n if (player.nextDirection == 1) {\n player.to.x = player.from.x;\n player.to.y = player.from.y - 1;\n } \n if (player.nextDirection == 2) {\n player.to.x = player.from.x + 1;\n player.to.y = player.from.y;\n } \n if (player.nextDirection == 3) {\n player.to.x = player.from.x;\n player.to.y = player.from.y + 1;\n } \n if (player.nextDirection == 4) {\n player.to.x = player.from.x - 1;\n player.to.y = player.from.y;\n } \n }\n\n } else {\n player.stepForward(1); \n }\n});","created_at":"2020-10-23T19:30:11.478+08:00","updated_at":"2020-12-08T15:17:20.228+08:00","name":"迷宮 副本","language":"javascript","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/197264/2c5436b5b0a5a1959170467fad0db7b3.jpg"},"parent_id":13997,"plugin":"","description":"上、下、左、右按鍵移動\n走到右下角的黃色方塊迷宮出口","note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":36,"hashid":"qmds8kggm","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3384458,"file_name":"target.png","project_id":197264,"asset_id":34371,"created_at":"2020-10-23T19:30:11.484+08:00","updated_at":"2020-10-23T19:30:11.484+08:00"},{"id":3384459,"file_name":"shadow.png","project_id":197264,"asset_id":34370,"created_at":"2020-10-23T19:30:11.486+08:00","updated_at":"2020-10-23T19:30:11.486+08:00"},{"id":3384460,"file_name":"player.png","project_id":197264,"asset_id":34369,"created_at":"2020-10-23T19:30:11.487+08:00","updated_at":"2020-10-23T19:30:11.487+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦