{"id":188173,"student_id":3760,"content":"// 將背景設定為黑色\nsetBackdrop(\"#000000\");\n// 用 \"head.gif\" 創造一個角色\nlet head = createSprite(\"head.gif\");\nhead.x = 320;\nhead.y = 240;\n\nlet food = createSprite(\"food.gif\");\nfood.x = Math.random()*640;\nfood.y = Math.random()*480;\n\nlet bodies = [];\nlet clock = 0;\nlet score = 0;\nlet alive = true;\nlet speed = 8;\n\n\nforever(function() {\n // 在這裡的程式碼會不斷執\n isDie();\n playerControl();\n eat();\n move();\n print(score, 20, 20, \"white\", 20);\n if (!alive) \n print(\"Game Over\", 160, 240, \"red\", 60);\n});\n\nfunction move() {\n clock += 1;\n if (clock%speed===0 \u0026\u0026 alive) {\n if (bodies.length\u003e0) {\n let lastBody = bodies.pop();\n lastBody.hidden = false;\n lastBody.x = head.x;\n lastBody.y = head.y;\n bodies.unshift(lastBody);\n }\n head.stepForward(16);\n }\n}\n\nfunction playerControl() {\n if (key.up \u0026\u0026 head.direction!==180) head.direction = 0;\n if (key.down \u0026\u0026 head.direction!==0) head.direction = 180;\n if (key.right \u0026\u0026 head.direction!==-90) head.direction = 90;\n if (key.left \u0026\u0026 head.direction!==90) head.direction = -90;\n\n}\n\nfunction eat() {\n if (head.touched(food)) {\n food.x = Math.random()*640;\n food.y = Math.random()*480;\n score += 1;\n if (speed\u003e=2 \u0026\u0026 score%3===0) \n speed -= 1;\n \n let body = createSprite(\"body.gif\");\n body.hidden = true;\n bodies.push(body);\n }\n}\n\nfunction isDie() {\n if (head.touched(bodies) || head.x\u003e640 || head.x\u003c0 || head.y\u003c0 || head.y\u003e480) {\n alive = false;\n }\n}\n","created_at":"2020-09-05T00:57:42.503+08:00","updated_at":"2021-07-28T22:39:38.885+08:00","name":"貪食蛇_S 副本","language":"javascript","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/188173/9829a282d620418f3f78e626e3c078a9.jpg"},"parent_id":54317,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":35,"hashid":"9ygs4dj2","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3198944,"file_name":"head.gif","project_id":188173,"asset_id":107712,"created_at":"2020-09-05T00:57:42.511+08:00","updated_at":"2020-09-05T00:57:42.511+08:00"},{"id":3198945,"file_name":"body.gif","project_id":188173,"asset_id":107711,"created_at":"2020-09-05T00:57:42.515+08:00","updated_at":"2020-09-05T00:57:42.515+08:00"},{"id":3198946,"file_name":"food.gif","project_id":188173,"asset_id":107710,"created_at":"2020-09-05T00:57:42.516+08:00","updated_at":"2020-09-05T00:57:42.516+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦