{"id":182077,"student_id":1981,"content":"// 將背景設定為黑色\nsetBackdrop(\"#000000\");\n\nvar head = createSprite(\"head.gif\");\nvar clock = 0;\nvar score = 0;\nvar bodies = [];\nvar food = createSprite(\"food.gif\");\nvar alive = true;\nforever(function() {\n clock = clock+1;\n if (clock%6 === 0 \u0026\u0026 alive === true) {\n playercontrol();\n eat();\n move();\n die();\n }\n print(score, 20, 20, \"white\");\n\n});\n// when(\"keydown\", \"right\", function() {\n// console.log(\"right\")\n// if (head.direction != 270) {\n// head.direction = 90;\n// }\n \n// });\n// when(\"keydown\", \"left\", function() {\n// if (head.direction != 90) {\n// head.direction = 270;\n// }\n// });\n// when(\"keydown\", \"right\", function() {\n// head.direction = 90;\n// });\n// when(\"keydown\", \"right\", function() {\n// head.direction = 90;\n// });\nfunction move() {\n if (bodies.length \u003e 0) {\n //當身體的長度大於零\n var lastbody = bodies.pop(); //移除並回傳陣列的最後一個元素\n lastbody.x = head.x;\n lastbody.y = head.y;\n bodies.unshift(lastbody); //方法會添加一個或多個元素至陣列的開頭\n }\n playercontrol();\n head.stepForward(16);\n}\nfunction playercontrol() {\n if (key.up \u0026\u0026 head.direction != 180) {\n head.direction = 0;\n }\n if (key.down \u0026\u0026 head.direction !== 0) {\n head.direction = 180;\n }\n console.log(\"playercontrol\")\n if (key.right \u0026\u0026 head.direction != 270) {\n head.direction = 90;\n }\n if (key.left \u0026\u0026 head.direction != 90) {\n head.direction = 270;\n }\n}\nfunction eat() {\n if (head.touched(food)) {\n food.x = Math.random()*640;\n food.y = Math.random()*480;\n score = score += 1;\n var body = createSprite(\"body.gif\");\n bodies.push(body);\n }\n}\nfunction die() {\n if (head.touched(bodies) || head.x \u003c 0 || head.x \u003e 640 || head.y \u003c 0 || head.y \u003e 480) {\n alive = false;\n }\n}","created_at":"2020-08-16T10:09:32.016+08:00","updated_at":"2021-04-14T19:12:13.450+08:00","name":"貪食蛇_S 副本","language":"javascript","screenshot":{"url":"https://cdn5.koding.school/uploads/project/screenshot/182077/851429b757dd60643234fb20b5d83f0e.jpg"},"parent_id":54317,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":53,"hashid":"d5ms54dg","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3104723,"file_name":"head.gif","project_id":182077,"asset_id":107712,"created_at":"2020-08-16T10:09:32.023+08:00","updated_at":"2020-08-16T10:09:32.023+08:00"},{"id":3104724,"file_name":"body.gif","project_id":182077,"asset_id":107711,"created_at":"2020-08-16T10:09:32.024+08:00","updated_at":"2020-08-16T10:09:32.024+08:00"},{"id":3104725,"file_name":"food.gif","project_id":182077,"asset_id":107710,"created_at":"2020-08-16T10:09:32.025+08:00","updated_at":"2020-08-16T10:09:32.025+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦