{"id":162129,"student_id":1909,"content":"redTarget.hidden = false\nblueTarget.hidden = false\npinkTarget.hidden = false\norangeTarget.hidden = false\nplayer.AI = function () {\n if (key.up) {\n player.nextDirection =0\n }\n if (key.down) {\n player.nextDirection =180\n }\n if (key.right) {\n player.nextDirection =90\n }\n if (key.left) {\n player.nextDirection =270\n }\n}\nfunction getDirection(x,y,direction){\n var arr = []\n if (map[y][x+1] == \" \"\u0026\u0026direction != 270) {\n arr.push(90)\n }\n if (map[y][x-1] == \" \"\u0026\u0026direction != 90 ){\n arr.push(270)\n }\n if (map[y+1][x] == \" \"\u0026\u0026direction != 0) {\n arr.push(180)\n }\n if (map[y-1][x] == \" \"\u0026\u0026direction != 180) {\n arr.push(0)\n }\n return arr;\n}\n\nfunction closet(available_direction,current_dir){\n var min_dir = 100000000\n var best_dir = -1\n for (var i = 0; i \u003c available_direction.length; i++) {\n var dir = available_direction[i]-current_dir\n if (dir\u003c0) {\n dir = dir*-1\n }\n if (dir\u003e180) {\n dir = 360-dir\n }\n if (dir\u003cmin_dir) {\n min_dir = dir\n best_dir = available_direction[i]\n }\n }\n return best_dir\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n}\n// var arr = getDirection(1,1,90)\n// console.log(arr)\nBlinky.AI = function(){\n var choices = getDirection(Blinky.X,Blinky.Y,Blinky.direction)\n var picked = choices[Math.floor(Math.random()*choices.length)];\n \n Blinky.nextDirection = picked\n}\nPinky.AI = function(){\n var choices = getDirection(Pinky.X,Pinky.Y,Pinky.direction)\n var picked = choices[Math.floor(Math.random()*choices.length)];\n \n Pinky.nextDirection = picked\n}\nInky.AI = function(){\n var choices = getDirection(Inky.X,Inky.Y,Inky.direction)\n var picked = choices[Math.floor(Math.random()*choices.length)];\n \n Inky.nextDirection = picked\n}\nClyde.AI = function(){\n var choices = getDirection(Clyde.X,Clyde.Y,Clyde.direction)\n var picked = choices[Math.floor(Math.random()*choices.length)];\n \n Clyde.nextDirection = picked\n}\n\n\n\n\n// 追逐下的AI\nBlinky.chaseAI = function(){\n redTarget.moveTo(player);\n var arr = getDirection(Blinky.X,Blinky.Y,Blinky.direction)\n Blinky.toward(redTarget)\n Blinky.nextDirection = closet(arr,Blinky.direction)\n}\nPinky.chaseAI = function(){\n pinkTarget.moveTo(player)\n pinkTarget.direction = player.direction\n pinkTarget.stepForward(15*4)\n var arr = getDirection(Pinky.X,Pinky.Y,Pinky.direction)\n Pinky.toward(pinkTarget)\n Pinky.nextDirection = closet(arr,Pinky.direction)\n}\nInky.chaseAI = function(){\n blueTarget.moveTo(Blinky)\n blueTarget.toward(pinkTarget)\n blueTarget.stepForward(pinkTarget.distanceTo(Blinky)*2)\n var arr = getDirection(Inky.X,Inky.Y,Inky.direction)\n Inky.toward(blueTarget)\n Inky.nextDirection = closet(arr,Inky.direction)\n}\nClyde.chaseAI = function(){\n if (Clyde.distanceTo(player)\u003e120) {\n orangeTarget.moveTo(player)\n } else {\n orangeTarget.moveTo(0,33*15)\n }\n var arr = getDirection(Clyde.X,Clyde.Y,Clyde.direction)\n Clyde.toward(orangeTarget)\n Clyde.nextDirection = closet(arr,Clyde.direction)\n}\n\n\n// function min_val(arr){\n// var min = 100000000\n// for (var i = 0; i \u003c arr.length; i++) {\n// if (arr[i]\u003cmin) {\n// min = arr[i]\n// }\n// }\n// return min\n// }\n// function max_val(arr){\n// var min = -100000000\n// for (var i = 0; i \u003c arr.length; i++) {\n// if (arr[i]\u003emin) {\n// min = arr[i]\n// }\n// }\n// return min\n// }\n\n// function max_cnt_val(arr){\n// var cnt_arr = [0, 0, 0, 0, 0, 0];\n// for (var i = 0; i \u003c arr.length; i++) {\n// var idx = arr[i] - 1;\n// cnt_arr[idx] += 1\n// }\n// console.log(cnt);\n// var max_val = -1000000\n// var max_idx = 0\n// for (var i = 0; i \u003c cnt_arr.length; i++) {\n// if (cnt_arr[i] \u003e max_val) {\n// max_val = cnt_arr[i];\n// max_idx = i;\n// }\n// }\n// return max_idx + 1;\n// }\n// function max_cnt_val(arr){\n// var cnt_obj = {}\n// for (var i = 0; i \u003c arr.length; i++) {\n// var key = arr[i]\n// if (key in cnt_obj) {\n// cnt_obj[key] += 1\n// } else {\n// cnt_obj[key = 1]\n// }\n \n// console.log(cnt_obj)\n// }\n// var max_val = -1000000\n// var max_key = -1\n// for (var i = 0; i \u003c cnt_arr.length; i++) {\n// if (cnt_obj[i] \u003e max_val) {\n// max_val = cnt_obj[i];\n// max_key = key;\n// }\n// }\n// return max_key;\n// }\n \n \n \n// }\n// 巡邏模式下的 AI\nBlinky.scatterAI = function(){\n redTarget.moveTo(117,15)\n var arr = getDirection(Blinky.X,Blinky.Y,Blinky.direction)\n Blinky.toward(redTarget)\n Blinky.nextDirection = closet(arr,Blinky.direction)\n}\nPinky.scatterAI = function(){\n pinkTarget.moveTo(522,15)\n var arr = getDirection(Pinky.X,Pinky.Y,Pinky.direction)\n Pinky.toward(pinkTarget)\n Pinky.nextDirection = closet(arr,Pinky.direction)\n}\nInky.scatterAI = function(){\n blueTarget.moveTo(117,465)\n var arr = getDirection(Inky.X,Inky.Y,Inky.direction)\n Inky.toward(blueTarget)\n Inky.nextDirection = closet(arr,Inky.direction)\n}\nClyde.scatterAI = function(){\n orangeTarget.moveTo(522,465)\n var arr = getDirection(Clyde.X,Clyde.Y,Clyde.direction)\n Clyde.toward(orangeTarget)\n Clyde.nextDirection = closet(arr,Clyde.direction)\n}\n//驚嚇模式下的AI\nBlinky.backToHouse = function(){\n redTarget.moveTo(320,240)\n var arr = getDirection(Blinky.X,Blinky.Y,Blinky.direction)\n Blinky.toward(redTarget)\n Blinky.nextDirection = closet(arr,Blinky.direction)\n}\nPinky.backToHouse = function(){\n pinkTarget.moveTo(320,240)\n var arr = getDirection(Pinky.X,Pinky.Y,Pinky.direction)\n Pinky.toward(pinkTarget)\n Pinky.nextDirection = closet(arr,Pinky.direction)\n}\nInky.backToHouse = function(){\n blueTarget.moveTo(320,240)\n var arr = getDirection(Inky.X,Inky.Y,Inky.direction)\n Inky.toward(blueTarget)\n Inky.nextDirection = closet(arr,Inky.direction)\n}\nClyde.backToHouse = function(){\n orangeTarget.moveTo(320,240)\n var arr = getDirection(Clyde.X,Clyde.Y,Clyde.direction)\n Clyde.toward(orangeTarget)\n Clyde.nextDirection = closet(arr,Clyde.direction)\n}\n\n\n\n\n// function odd_even_compare(arr){\n// var cnt= [0a, 0];\n// for (var i = 0; i \u003c arr.length; i++) {\n// var key = arr[i];\n// if (key%2 == 0) {\n// cnt[1]+=1\n// } else {\n// cnt[0]+=1\n// }\n// }console.log(cnt);\n// if (cnt[0] \u003e cnt[1]) {\n// return \"奇數贏\"\n// }\n// if (cnt[0] \u003c cnt[1]) {\n// return \"偶數贏\"\n// }\n// if (cnt[0] = cnt[1]) {\n// return \"平手\"\n// }\n// }\n\n\n\n\n\n","created_at":"2020-07-04T16:21:23.971+08:00","updated_at":"2020-07-25T16:36:05.268+08:00","name":"小精靈 副本","language":"javascript","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/162129/89edcce60b8890776f43b51e69f48ea4.jpg"},"parent_id":52859,"plugin":"var MODE; // chase, scatter, frightened\nvar tmpMODE;\nsetBackdrop('black');\nvar width = 15;\nvar offsetX = 110 + 7;\nvar offsetY = 15;\nvar food = [];\nvar level = 1;\nvar score = 0;\nvar timer = 0;\nvar life = 3;\nvar bestScore = 0;\nvar bonus = 100; // 吃掉鬼魂的獎勵\nvar startTime = Date.now();\nvar map = [\n '┏━━━━━━━━━━━━┓┏━━━━━━━━━━━━┓',\n '┃............┃┃............┃',\n '┃.┏━━┓.┏━━━┓.┃┃.┏━━━┓.┏━━┓.┃',\n '┃.┃ ┃.┃ ┃.┃┃.┃ ┃.┃ ┃.┃',\n '┃*┗━━┛.┗━━━┛.┗┛.┗━━━┛.┗━━┛*┃',\n '┃..........................┃',\n '┃.┏━━┓.┏┓.┏━━━━━━┓.┏┓.┏━━┓.┃',\n '┃.┗━━┛.┃┃.┗━━┓┏━━┛.┃┃.┗━━┛.┃',\n '┃......┃┃....┃┃....┃┃......┃',\n '┗━━━━┓.┃┗━━┓.┃┃.┏━━┛┃.┏━━━━┛',\n ' ┃.┃┏━━┛.┗┛.┗━━┓┃.┃ ',\n ' ┃.┃┃ ┃┃.┃ ',\n ' ┃.┃┃ ┏━┓ ┏━┓ ┃┃.┃ ',\n '━━━━━┛.┗┛ ┃┏┛ ┗┓┃ ┗┛.┗━━━━━',\n ' ┃┃ ┃┃ ',\n '━━━━━┓.┏┓ ┃┗━━━━┛┃ ┏┓.┏━━━━━',\n ' ┃.┃┃ ┗━━━━━━┛ ┃┃.┃ ',\n ' ┃.┃┃ ┃┃.┃ ',\n ' ┃.┃┃ ┏━━━━━━┓ ┃┃.┃ ',\n '┏━━━━┛.┗┛ ┗━━┓┏━━┛ ┗┛.┗━━━━┓',\n '┃............┃┃............┃',\n '┃.┏━━┓.┏━━━┓.┃┃.┏━━━┓.┏━━┓.┃',\n '┃.┗━┓┃.┗━━━┛.┃┃.┗━━━┛.┃┏━┛.┃',\n '┃*..┃┃.......┃┃.......┃┃..*┃',\n '┗━┓.┃┃.┏┓.┏━━┛┗━━┓.┏┓.┃┃.┏━┛',\n '┏━┛.┗┛.┃┃.┗━━┓┏━━┛.┃┃.┗┛.┗━┓',\n '┃......┃┃....┃┃....┃┃......┃',\n '┃.┏━━━━┛┗━━┓.┃┃.┏━━┛┗━━━━┓.┃',\n '┃.┗━━━━━━━━┛.┗┛.┗━━━━━━━━┛.┃',\n '┃..........................┃',\n '┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛',\n]\n\nforever(function() {\n print('best: ' + bestScore, 10, 20, 'gold');\n print('score: ' + score, 10, 40, '#fff');\n print('level: ' + level, 10, 60, '#fff');\n print('mode: ' + MODE, 10, 80, '#fff');\n});\n\n// 地圖\nvar grid = (function (M) {\n var grid = {};\n for (var x = 0; x \u003c 28; x++) {\n grid[x] = {};\n for (var y = 0; y \u003c 31; y++) {\n var b = createSprite(['block_1.png', 'block_2.png', 'food.png', 'empty.png']);\n b.x = x*width + offsetX;\n b.y = y*width + offsetY;\n b.role = M[y][x];\n var t = M[y][x];\n b.scale = 1/7;\n b.isWall = ['┃', '━', '┛', '┗', '┏', '┓'].indexOf(t) !== -1\n if (['┃', '━', '┛', '┗', '┏', '┓'].indexOf(t) != -1) b.role = 'x';\n if (t == '━' || t == '┃') b.costumeId = 1;\n if (t == '.' || t == '*') b.costumeId = 2;\n if (t == ' ') b.costumeId = 3;\n if (t == '.') b.scale *= 0.25;\n if (t == '*') b.scale *= 0.5;\n if (t == '━') b.direction = 0;\n if (t == '┓') b.direction = 0;\n if (t == '┗') b.direction = 180;\n if (t == '┏') b.direction = 270;\n if (t == '.' || t == '*') food.push(b);\n grid[x][y] = b;\n }\n }\n\n for (var x = 0; x \u003c 28; x++) {\n for (var y = 0; y \u003c 31; y++) {\n var b = grid[x][y];\n b.count = 0;\n b.X = x;\n b.Y = y;\n if (x \u003e 0 \u0026\u0026 grid[x-1][y] \u0026\u0026 !grid[x-1][y].isWall) {\n b.left = grid[x-1][y];\n b.count++;\n }\n if (x \u003c 27 \u0026\u0026 grid[x+1][y] \u0026\u0026 !grid[x+1][y].isWall) {\n b.right = grid[x+1][y];\n b.count++;\n }\n if (y \u003c 30 \u0026\u0026 grid[x][y+1] \u0026\u0026 !grid[x][y+1].isWall) {\n b.bottom = grid[x][y+1];\n b.count++;\n }\n if (y \u003e 0 \u0026\u0026 grid[x][y-1] \u0026\u0026 !grid[x][y-1].isWall) {\n b.top = grid[x][y-1];\n b.count++;\n }\n }\n }\n\n forever(function() {\n pen.color = 'orange';\n pen.size = 4;\n pen.drawLine(299, 202, 341, 202);\n });\n return grid;\n})(map);\n\n\nfunction Player (costumes) {\n \n var s = createSprite(costumes);\n \n s.rotationStyle = 'fixed';\n s.speed = 1;\n s.X = 0;\n s.Y = 0;\n s.release = false;\n s.target = grid[0][0]; // 要移動到的目標格子\n \n s.mode = 'chase'; // chase, scatter, frightened, dead, leave\n \n s.forever(function() {\n s.updatePosition(); // 移動角色\n s.updateCostume(); // 更新造型\n });\n\n // 更新角色座標,朝著 target 的格子前進\n s.updatePosition = function () {\n\n if (s.release === false || MODE === 'pause') return;\n \n if (this.distanceTo(this.target) \u003e this.speed) {\n this.toward(this.target);\n this.stepForward(this.speed);\n } else {\n this.moveTo(this.target);\n this.X = this.target.X;\n this.Y = this.target.Y;\n this.decision();\n this.updateTarget();\n }\n }\n\n // 執行 AI 相關指令決策出下一個要移動的方向 nextDirection\n s.decision = function () {\n\n if (s.AI) s.AI();\n\n if (s.target.count \u003e= 3) {\n if (this.mode === 'chase' \u0026\u0026 s.chaseAI) s.chaseAI();\n if (this.mode === 'scatter' \u0026\u0026 s.scatterAI) s.scatterAI();\n if (this.mode === 'frightened' \u0026\u0026 s.frightenedAI) s.frightenedAI();\n if (this.mode === 'dead' \u0026\u0026 s.backToHouseAI) s.backToHouseAI();\n }\n \n if (this.mode === 'leave') this.leaveAI();\n }\n \n // 如果有 nextDirection 且是可以行走的格子\n // 更新下一個移動的目標 target\n s.updateTarget = function () {\n if (this.nextDirection == 0 \u0026\u0026 this.target.top) this.target = this.target.top;\n if (this.nextDirection == 90 \u0026\u0026 this.target.right) this.target = this.target.right;\n if (this.nextDirection == 180 \u0026\u0026 this.target.bottom) this.target = this.target.bottom;\n if (this.nextDirection == 270 \u0026\u0026 this.target.left) this.target = this.target.left;\n this.nextDirection = undefined;\n }\n \n // 角色造型切換\u0026移動時的動畫\n s.updateCostume = function () {\n this.costumeId = Math.floor(this.direction/90);\n \n if (this.mode == 'dead') this.costumeId += 8;\n if (this.mode == 'frightened') this.costumeId = 12;\n \n if (this.distanceTo(this.target) == 0) return;\n\n var bool = Math.floor(timer/150)%2 == 0;\n if (bool \u0026\u0026 (this.mode === 'chase' || MODE === 'scatter')) {\n this.costumeId += 4;\n }\n if (bool \u0026\u0026 this.mode === 'frightened') {\n this.costumeId += 1;\n }\n }\n \n // 離開鬼屋\n s.leaveAI = function () {\n if (s.target.top) s.nextDirection = 0;\n else if (s.target.right) s.nextDirection = 90;\n else if (s.target.left) s.nextDirection = 270;\n else s.nextDirection = 180;\n }\n\n // 角色轉向\n s.reverse = function () {\n if (this.direction == 0 \u0026\u0026 this.target.bottom) this.target = this.target.bottom;\n if (this.direction == 90 \u0026\u0026 this.target.left) this.target = this.target.left;\n if (this.direction == 180 \u0026\u0026 this.target.top) this.target = this.target.top;\n if (this.direction == 270 \u0026\u0026 this.target.right) this.target = this.target.right;\n }\n \n s.reset = function (x, y, direction) {\n s.X = x;\n s.Y = y;\n s.direction = direction;\n s.nextDirection = direction;\n s.target = grid[x][y];\n s.moveTo(grid[x][y]);\n }\n\n return s;\n}\n\n// 初始化四隻鬼魂、玩家角色\nvar Clyde = Player(['o1.png', 'o2.png', 'o3.png', 'o4.png', 'o5.png', 'o6.png', 'o7.png', 'o8.png', 'o9.png', 'o10.png', 'o11.png', 'o12.png', 'f13.png', 'f14.png']);\nvar Inky = Player(['b1.png', 'b2.png', 'b3.png', 'b4.png', 'b5.png', 'b6.png', 'b7.png', 'b8.png', 'b9.png', 'b10.png', 'b11.png', 'b12.png', 'f13.png', 'f14.png']);\nvar Pinky = Player(['p1.png', 'p2.png', 'p3.png', 'p4.png', 'p5.png', 'p6.png', 'p7.png', 'p8.png', 'p9.png', 'p10.png', 'p11.png', 'p12.png', 'f13.png', 'f14.png']);\nvar Blinky = Player(['r1.png', 'r2.png', 'r3.png', 'r4.png', 'r5.png', 'r6.png', 'r7.png', 'r8.png', 'r9.png', 'r10.png', 'r11.png', 'r12.png', 'f13.png', 'f14.png']);\nvar player = Player(['player_1.png', 'player.png', 'player_3.png', 'player_4.png', 'player_5.png', 'player_6.png', 'player_7.png', 'player_8.png', 'player_8.png', 'player_8.png', 'player_8.png', 'player_8.png', 'player_8.png', 'player_8.png']);\nvar ghosts = [Blinky, Inky, Pinky, Clyde];\n\nfunction restart () {\n MODE = 'pause';\n setTimeout(() =\u003e MODE='scatter', 2000);\n startTime = Date.now();\n Blinky.reset(12, 14, 90);\n Pinky.reset(13, 14, 90);\n Inky.reset(14, 14, 90);\n Clyde.reset(15, 14, 90);\n player.reset(13, 17, 90);\n}\nrestart();\n\nplayer.scale = 2;\nplayer.release = true;\nghosts.forEach((g) =\u003e g.scale = 0.23);\n\n// 神奇的傳送門\nghosts.concat(player).forEach((s) =\u003e {\n s.forever(function () {\n if (s.X == 1 \u0026\u0026 s.Y == 14 \u0026\u0026 s.distanceTo(grid[1][14]) == 0) {\n s.target = grid[25][14];\n s.moveTo(grid[26][14]);\n }\n if (s.X == 26 \u0026\u0026 s.Y == 14 \u0026\u0026 s.distanceTo(grid[26][14]) == 0) {\n s.target = grid[2][14];\n s.moveTo(grid[1][14]);\n }\n });\n});\n\n// 更新鬼魂的模式\nforever(function () {\n ghosts.forEach(function (g) {\n if (g.release === false) return g.mode = '';\n \n if (g.distanceTo(player) \u003c width) {\n if (g.mode === 'frightened') {\n score += bonus;\n bonus *= 2;\n g.mode = 'dead';\n createText('+'+bonus, g.x, g.y);\n }\n \n if (MODE !== 'frightened') {\n restart();\n life -= 1;\n if (life \u003c 0) {\n if (score \u003e bestScore) bestScore = score;\n life = 3;\n level = 1;\n }\n }\n }\n \n if (g.mode !== 'dead') g.mode = MODE;\n \n if (g.x \u003e 270 \u0026\u0026 g.x \u003c 370 \u0026\u0026 g.y \u003e 190 \u0026\u0026 g.y \u003c 240) {\n g.mode = 'leave';\n }\n })\n});\n\nforever(function() {\n \n // 如果切換模式則鬼魂進行轉向\n if (tmpMODE !== MODE) {\n bonus = 100; // 疊加獎勵恢復成 100\n ghosts.forEach(function (g) {g.reverse()});\n }\n tmpMODE = MODE;\n \n if (MODE == 'pause') return;\n \n // 遊戲經過時間\n timer = Date.now() - startTime;\n\n if (MODE == 'frightened') return;\n \n // level 1\n if (level == 1) {\n if (timer \u003c 7000) MODE = 'scatter';\n else if (timer \u003c 27000) MODE = 'chase';\n else if (timer \u003c 34000) MODE = 'scatter';\n else if (timer \u003c 54000) MODE = 'chase';\n else if (timer \u003c 59000) MODE = 'scatter';\n else if (timer \u003c 79000) MODE = 'chase';\n else if (timer \u003c 84000) MODE = 'scatter';\n else MODE = 'chase';\n // level 2 ~ 4\n } else if (level \u003c 5) {\n if (timer \u003c 7000) MODE = 'scatter';\n else if (timer \u003c 27000) MODE = 'chase';\n else if (timer \u003c 34000) MODE = 'scatter';\n else if (timer \u003c 54000) MODE = 'chase';\n else if (timer \u003c 59000) MODE = 'scatter';\n else if (timer \u003c 79000) MODE = 'chase';\n else if (timer \u003c 84000) MODE = 'scatter';\n else MODE = 'chase';\n // level 5 以上\n } else {\n if (timer \u003c 7000) MODE = 'scatter';\n else if (timer \u003c 27000) MODE = 'chase';\n else if (timer \u003c 34000) MODE = 'scatter';\n else if (timer \u003c 54000) MODE = 'chase';\n else if (timer \u003c 59000) MODE = 'scatter';\n else if (timer \u003c 79000) MODE = 'chase';\n else if (timer \u003c 84000) MODE = 'scatter';\n else MODE = 'chase';\n }\n\n Blinky.release = timer \u003e 0;\n Pinky.release = timer \u003e 5000;\n Inky.release = timer \u003e 8000;\n Clyde.release = timer \u003e 11000;\n});\n\nforever(function() {\n var limit = 2;\n var playerSpeed;\n var ghostsSpeed;\n // level 1\n if (level == 1) {\n if (MODE == 'frightened') {\n playerSpeed = limit*0.9;\n ghostsSpeed = limit*0.5;\n } else {\n playerSpeed = limit*0.8;\n ghostsSpeed = limit*0.75;\n }\n }\n // level 2 ~ 4\n else if (level \u003c 5) {\n if (MODE == 'frightened') {\n playerSpeed = limit*0.95;\n ghostsSpeed = limit*0.55;\n } else {\n playerSpeed = limit*0.9;\n ghostsSpeed = limit*0.85;\n }\n }\n // level \u003e= 5\n else {\n if (MODE == 'frightened') {\n playerSpeed = limit*1.0;\n ghostsSpeed = limit*0.6;\n } else {\n playerSpeed = limit*1.0;\n ghostsSpeed = limit*0.95;\n }\n }\n ghosts.forEach((g) =\u003e {\n if (g.mode == 'dead') g.speed = 10;\n else g.speed = ghostsSpeed;\n });\n player.speed = playerSpeed;\n});\n\nforever(function() {\n var success = true;\n food.forEach((f) =\u003e {\n success = f.hidden \u0026\u0026 success;\n if (!f.hidden \u0026\u0026 f.distanceTo(player) \u003c 5) {\n f.hidden = true;\n score += 10;\n if (f.role == '*') {\n MODE = 'frightened';\n setTimeout(function() {\n MODE = '';\n }, 8000);\n }\n }\n });\n if (success) nextLevel();\n});\n\nvar texts = [];\nfunction createText (text, x, y) {\n texts.push([text, x, y]);\n setTimeout(function () {\n texts.shift();\n }, 2000);\n forever(function(){\n texts.forEach(function (t) {\n print(t[0], t[1] - width, t[2] - width/2, 'lightblue', 14);\n });\n });\n}\n\nfunction nextLevel() {\n for (var x = 0; x \u003c 28; x++) {\n for (var y = 0; y \u003c 31; y++) {\n grid[x][y].hidden = false;\n }\n }\n restart();\n level++;\n}\n\n// 標記\nvar redTarget = createSprite('red_target.png');\nvar pinkTarget = createSprite('pink.png');\nvar blueTarget = createSprite('blue_target.png');\nvar orangeTarget = createSprite('orange_target.png');\n[redTarget, pinkTarget, blueTarget, orangeTarget].forEach((t) =\u003e {\n t.scale = 1.2/7;\n t.rotationStyle = 'fixed';\n t.hidden = true;\n});\n\nfor (var x=0; x\u003c31; x++) {\n for (var y=0; y\u003c28; y++) {\n if (map[x][y] == '.' || map[x][y] == '*') {\n map[x] = map[x].substr(0, y) + ' ' + map[x].substr(y + 1)\n }\n } \n}\n\n// 顯示剩餘生命\nvar lifes = [\n createSprite('player.png'),\n createSprite('player.png'),\n createSprite('player.png'),\n];\nfor (var i=0; i\u003c3; i++) {\n lifes[i].moveTo(80, 350 + 40*i);\n lifes[i].scale = 2;\n}\nforever(function(){\n if (life \u003c= 0) lifes[2].hidden = true;\n if (life \u003c= 1) lifes[1].hidden = true;\n if (life \u003c= 2) lifes[0].hidden = true;\n});\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":54,"hashid":"2pdsnqzw","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2821650,"file_name":"o9.png","project_id":162129,"asset_id":105480,"created_at":"2020-07-04T16:21:23.979+08:00","updated_at":"2020-07-04T16:21:23.979+08:00"},{"id":2821651,"file_name":"o12.png","project_id":162129,"asset_id":105481,"created_at":"2020-07-04T16:21:23.980+08:00","updated_at":"2020-07-04T16:21:23.980+08:00"},{"id":2821652,"file_name":"o11.png","project_id":162129,"asset_id":105482,"created_at":"2020-07-04T16:21:23.981+08:00","updated_at":"2020-07-04T16:21:23.981+08:00"},{"id":2821653,"file_name":"o10.png","project_id":162129,"asset_id":105483,"created_at":"2020-07-04T16:21:23.982+08:00","updated_at":"2020-07-04T16:21:23.982+08:00"},{"id":2821654,"file_name":"r8.png","project_id":162129,"asset_id":105484,"created_at":"2020-07-04T16:21:23.983+08:00","updated_at":"2020-07-04T16:21:23.983+08:00"},{"id":2821655,"file_name":"r7.png","project_id":162129,"asset_id":105485,"created_at":"2020-07-04T16:21:23.984+08:00","updated_at":"2020-07-04T16:21:23.984+08:00"},{"id":2821656,"file_name":"r6.png","project_id":162129,"asset_id":105486,"created_at":"2020-07-04T16:21:23.984+08:00","updated_at":"2020-07-04T16:21:23.984+08:00"},{"id":2821657,"file_name":"r5.png","project_id":162129,"asset_id":105487,"created_at":"2020-07-04T16:21:23.985+08:00","updated_at":"2020-07-04T16:21:23.985+08:00"},{"id":2821658,"file_name":"r4.png","project_id":162129,"asset_id":105488,"created_at":"2020-07-04T16:21:23.986+08:00","updated_at":"2020-07-04T16:21:23.986+08:00"},{"id":2821659,"file_name":"r3.png","project_id":162129,"asset_id":105489,"created_at":"2020-07-04T16:21:23.987+08:00","updated_at":"2020-07-04T16:21:23.987+08:00"},{"id":2821660,"file_name":"r2.png","project_id":162129,"asset_id":105490,"created_at":"2020-07-04T16:21:23.988+08:00","updated_at":"2020-07-04T16:21:23.988+08:00"},{"id":2821661,"file_name":"r1.png","project_id":162129,"asset_id":105491,"created_at":"2020-07-04T16:21:23.989+08:00","updated_at":"2020-07-04T16:21:23.989+08:00"},{"id":2821662,"file_name":"r9.png","project_id":162129,"asset_id":105492,"created_at":"2020-07-04T16:21:23.990+08:00","updated_at":"2020-07-04T16:21:23.990+08:00"},{"id":2821663,"file_name":"r10.png","project_id":162129,"asset_id":105493,"created_at":"2020-07-04T16:21:23.991+08:00","updated_at":"2020-07-04T16:21:23.991+08:00"},{"id":2821664,"file_name":"r12.png","project_id":162129,"asset_id":105494,"created_at":"2020-07-04T16:21:23.992+08:00","updated_at":"2020-07-04T16:21:23.992+08:00"},{"id":2821665,"file_name":"r11.png","project_id":162129,"asset_id":105495,"created_at":"2020-07-04T16:21:23.993+08:00","updated_at":"2020-07-04T16:21:23.993+08:00"},{"id":2821666,"file_name":"p12.png","project_id":162129,"asset_id":105496,"created_at":"2020-07-04T16:21:23.994+08:00","updated_at":"2020-07-04T16:21:23.994+08:00"},{"id":2821667,"file_name":"p11.png","project_id":162129,"asset_id":105497,"created_at":"2020-07-04T16:21:23.995+08:00","updated_at":"2020-07-04T16:21:23.995+08:00"},{"id":2821668,"file_name":"p10.png","project_id":162129,"asset_id":105498,"created_at":"2020-07-04T16:21:23.996+08:00","updated_at":"2020-07-04T16:21:23.996+08:00"},{"id":2821669,"file_name":"p9.png","project_id":162129,"asset_id":105499,"created_at":"2020-07-04T16:21:23.996+08:00","updated_at":"2020-07-04T16:21:23.996+08:00"},{"id":2821670,"file_name":"p8.png","project_id":162129,"asset_id":105500,"created_at":"2020-07-04T16:21:23.997+08:00","updated_at":"2020-07-04T16:21:23.997+08:00"},{"id":2821671,"file_name":"p7.png","project_id":162129,"asset_id":105501,"created_at":"2020-07-04T16:21:23.998+08:00","updated_at":"2020-07-04T16:21:23.998+08:00"},{"id":2821672,"file_name":"p6.png","project_id":162129,"asset_id":105502,"created_at":"2020-07-04T16:21:23.999+08:00","updated_at":"2020-07-04T16:21:23.999+08:00"},{"id":2821673,"file_name":"p5.png","project_id":162129,"asset_id":105503,"created_at":"2020-07-04T16:21:24.000+08:00","updated_at":"2020-07-04T16:21:24.000+08:00"},{"id":2821674,"file_name":"p4.png","project_id":162129,"asset_id":105504,"created_at":"2020-07-04T16:21:24.001+08:00","updated_at":"2020-07-04T16:21:24.001+08:00"},{"id":2821675,"file_name":"p3.png","project_id":162129,"asset_id":105505,"created_at":"2020-07-04T16:21:24.002+08:00","updated_at":"2020-07-04T16:21:24.002+08:00"},{"id":2821676,"file_name":"p2.png","project_id":162129,"asset_id":105506,"created_at":"2020-07-04T16:21:24.003+08:00","updated_at":"2020-07-04T16:21:24.003+08:00"},{"id":2821677,"file_name":"p1.png","project_id":162129,"asset_id":105507,"created_at":"2020-07-04T16:21:24.004+08:00","updated_at":"2020-07-04T16:21:24.004+08:00"},{"id":2821678,"file_name":"o8.png","project_id":162129,"asset_id":105508,"created_at":"2020-07-04T16:21:24.005+08:00","updated_at":"2020-07-04T16:21:24.005+08:00"},{"id":2821679,"file_name":"o7.png","project_id":162129,"asset_id":105509,"created_at":"2020-07-04T16:21:24.006+08:00","updated_at":"2020-07-04T16:21:24.006+08:00"},{"id":2821680,"file_name":"o6.png","project_id":162129,"asset_id":105510,"created_at":"2020-07-04T16:21:24.006+08:00","updated_at":"2020-07-04T16:21:24.006+08:00"},{"id":2821681,"file_name":"o5.png","project_id":162129,"asset_id":105511,"created_at":"2020-07-04T16:21:24.007+08:00","updated_at":"2020-07-04T16:21:24.007+08:00"},{"id":2821682,"file_name":"o4.png","project_id":162129,"asset_id":105512,"created_at":"2020-07-04T16:21:24.008+08:00","updated_at":"2020-07-04T16:21:24.008+08:00"},{"id":2821683,"file_name":"o3.png","project_id":162129,"asset_id":105513,"created_at":"2020-07-04T16:21:24.009+08:00","updated_at":"2020-07-04T16:21:24.009+08:00"},{"id":2821684,"file_name":"o2.png","project_id":162129,"asset_id":105514,"created_at":"2020-07-04T16:21:24.010+08:00","updated_at":"2020-07-04T16:21:24.010+08:00"},{"id":2821685,"file_name":"o1.png","project_id":162129,"asset_id":105515,"created_at":"2020-07-04T16:21:24.011+08:00","updated_at":"2020-07-04T16:21:24.011+08:00"},{"id":2821686,"file_name":"f14.png","project_id":162129,"asset_id":105516,"created_at":"2020-07-04T16:21:24.012+08:00","updated_at":"2020-07-04T16:21:24.012+08:00"},{"id":2821687,"file_name":"f13.png","project_id":162129,"asset_id":105517,"created_at":"2020-07-04T16:21:24.013+08:00","updated_at":"2020-07-04T16:21:24.013+08:00"},{"id":2821688,"file_name":"b12.png","project_id":162129,"asset_id":105518,"created_at":"2020-07-04T16:21:24.014+08:00","updated_at":"2020-07-04T16:21:24.014+08:00"},{"id":2821689,"file_name":"b11.png","project_id":162129,"asset_id":105519,"created_at":"2020-07-04T16:21:24.015+08:00","updated_at":"2020-07-04T16:21:24.015+08:00"},{"id":2821690,"file_name":"b10.png","project_id":162129,"asset_id":105520,"created_at":"2020-07-04T16:21:24.015+08:00","updated_at":"2020-07-04T16:21:24.015+08:00"},{"id":2821691,"file_name":"b9.png","project_id":162129,"asset_id":105521,"created_at":"2020-07-04T16:21:24.016+08:00","updated_at":"2020-07-04T16:21:24.016+08:00"},{"id":2821692,"file_name":"b8.png","project_id":162129,"asset_id":105522,"created_at":"2020-07-04T16:21:24.017+08:00","updated_at":"2020-07-04T16:21:24.017+08:00"},{"id":2821693,"file_name":"b7.png","project_id":162129,"asset_id":105523,"created_at":"2020-07-04T16:21:24.018+08:00","updated_at":"2020-07-04T16:21:24.018+08:00"},{"id":2821694,"file_name":"b6.png","project_id":162129,"asset_id":105524,"created_at":"2020-07-04T16:21:24.019+08:00","updated_at":"2020-07-04T16:21:24.019+08:00"},{"id":2821695,"file_name":"b5.png","project_id":162129,"asset_id":105525,"created_at":"2020-07-04T16:21:24.020+08:00","updated_at":"2020-07-04T16:21:24.020+08:00"},{"id":2821696,"file_name":"b4.png","project_id":162129,"asset_id":105526,"created_at":"2020-07-04T16:21:24.021+08:00","updated_at":"2020-07-04T16:21:24.021+08:00"},{"id":2821697,"file_name":"b3.png","project_id":162129,"asset_id":105527,"created_at":"2020-07-04T16:21:24.022+08:00","updated_at":"2020-07-04T16:21:24.022+08:00"},{"id":2821698,"file_name":"b2.png","project_id":162129,"asset_id":105528,"created_at":"2020-07-04T16:21:24.023+08:00","updated_at":"2020-07-04T16:21:24.023+08:00"},{"id":2821699,"file_name":"b1.png","project_id":162129,"asset_id":105529,"created_at":"2020-07-04T16:21:24.024+08:00","updated_at":"2020-07-04T16:21:24.024+08:00"},{"id":2821700,"file_name":"blue_target.png","project_id":162129,"asset_id":105530,"created_at":"2020-07-04T16:21:24.025+08:00","updated_at":"2020-07-04T16:21:24.025+08:00"},{"id":2821701,"file_name":"pink.png","project_id":162129,"asset_id":105531,"created_at":"2020-07-04T16:21:24.026+08:00","updated_at":"2020-07-04T16:21:24.026+08:00"},{"id":2821702,"file_name":"orange_target.png","project_id":162129,"asset_id":105532,"created_at":"2020-07-04T16:21:24.027+08:00","updated_at":"2020-07-04T16:21:24.027+08:00"},{"id":2821703,"file_name":"red_target.png","project_id":162129,"asset_id":105533,"created_at":"2020-07-04T16:21:24.028+08:00","updated_at":"2020-07-04T16:21:24.028+08:00"},{"id":2821704,"file_name":"food.png","project_id":162129,"asset_id":105534,"created_at":"2020-07-04T16:21:24.028+08:00","updated_at":"2020-07-04T16:21:24.028+08:00"},{"id":2821705,"file_name":"block_2.png","project_id":162129,"asset_id":105535,"created_at":"2020-07-04T16:21:24.029+08:00","updated_at":"2020-07-04T16:21:24.029+08:00"},{"id":2821706,"file_name":"block_1.png","project_id":162129,"asset_id":105536,"created_at":"2020-07-04T16:21:24.030+08:00","updated_at":"2020-07-04T16:21:24.030+08:00"},{"id":2821707,"file_name":"empty.png","project_id":162129,"asset_id":105537,"created_at":"2020-07-04T16:21:24.031+08:00","updated_at":"2020-07-04T16:21:24.031+08:00"},{"id":2821708,"file_name":"player.png","project_id":162129,"asset_id":105538,"created_at":"2020-07-04T16:21:24.032+08:00","updated_at":"2020-07-04T16:21:24.032+08:00"},{"id":2821709,"file_name":"player_4.png","project_id":162129,"asset_id":105539,"created_at":"2020-07-04T16:21:24.033+08:00","updated_at":"2020-07-04T16:21:24.033+08:00"},{"id":2821710,"file_name":"player_1.png","project_id":162129,"asset_id":105540,"created_at":"2020-07-04T16:21:24.034+08:00","updated_at":"2020-07-04T16:21:24.034+08:00"},{"id":2821711,"file_name":"player_3.png","project_id":162129,"asset_id":105541,"created_at":"2020-07-04T16:21:24.035+08:00","updated_at":"2020-07-04T16:21:24.035+08:00"},{"id":2821712,"file_name":"player_8.png","project_id":162129,"asset_id":105542,"created_at":"2020-07-04T16:21:24.036+08:00","updated_at":"2020-07-04T16:21:24.036+08:00"},{"id":2821713,"file_name":"player_6.png","project_id":162129,"asset_id":105543,"created_at":"2020-07-04T16:21:24.037+08:00","updated_at":"2020-07-04T16:21:24.037+08:00"},{"id":2821714,"file_name":"player_5.png","project_id":162129,"asset_id":105544,"created_at":"2020-07-04T16:21:24.038+08:00","updated_at":"2020-07-04T16:21:24.038+08:00"},{"id":2821715,"file_name":"player_7.png","project_id":162129,"asset_id":105545,"created_at":"2020-07-04T16:21:24.039+08:00","updated_at":"2020-07-04T16:21:24.039+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦