{"id":79835,"student_id":3647,"content":"// 將背景設定為黑色\nsetBackdrop(\"#4286f4\");\n// 用 \"head.gif\" 創造一個角色\nvar head = createSprite(\"head.gif\");\nvar food = createSprite(\"food.gif\");\n//var body = createSprite(\"body.gif\");\nvar clock = 0;\nfood.x = Math.random ()*480;\nfood.y = Math.random ()*240;\nforever(function() {\n // 在這裡的程式碼會不斷執行\n clock = clock+1;\n console.log(clock);\n if (clock%5 === 0) {\n\n\n Move();\n\n }\n\n\n playercontral();\n print(score, 20, 20, \"white\");\n eat();\n end();\n\n});\nvar score = 0;\n\nvar bodies = [];\n\n// 當按下鍵盤的「右方向鍵」時\nwhen(\"keydown\", \"right\", function() {\n head.direction = 90;\n});\nfunction Move() {\n head.stepForward(16);\n if (bodies.length \u003e 0) {\n var lastbody = bodies.pop();\n\n lastbody.direction = head.direction;\n lastbody.direction = head.direction;\n bodies.unshift(lastbody);\n\n lastbody.y = head.y;\n\n\n\n\n\n lastbody.x = head.x;\n\n }\n \n\n\n\n\n\n}\n\nfunction playercontral() {\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 if (key.left \u0026\u0026 head.direction != 90) {\n head.direction = 270;\n }\n if (key.right \u0026\u0026 head.direction !== 270) {\n head.direction = 90;\n }\n if (key.space) {\n head.stepForward(3);\n }\n if (key.s) {\n head.stepForward(20);\n }\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\n var body = createSprite(\"body.gif\");\n bodies.push(body);\n\n }\n\n\n\n\n\n}\nfunction end() {\n if (head.touched(bodies)) {\n stop;\n }\n if (head.x \u003c 0 \u0026\u0026 head.x \u003e 640 \u0026\u0026 head.y \u003c 0 \u0026\u0026 head.y \u003e 480) {\n stop;\n\n }\n}","created_at":"2019-07-13T18:35:37.860+08:00","updated_at":"2020-06-20T20:15:15.782+08:00","name":"貪食蛇_S 副本","language":"javascript","screenshot":{"url":"https://cdn4.koding.school/uploads/project/screenshot/79835/71f9432213fd17e6dd8f8dab84dc40e8.jpg"},"parent_id":54317,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":101,"hashid":"2pdsmz2j","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":1369023,"file_name":"head.gif","project_id":79835,"asset_id":107712,"created_at":"2019-07-13T18:35:37.864+08:00","updated_at":"2019-07-13T18:35:37.864+08:00"},{"id":1369024,"file_name":"body.gif","project_id":79835,"asset_id":107711,"created_at":"2019-07-13T18:35:37.865+08:00","updated_at":"2019-07-13T18:35:37.865+08:00"},{"id":1369025,"file_name":"food.gif","project_id":79835,"asset_id":107710,"created_at":"2019-07-13T18:35:37.866+08:00","updated_at":"2019-07-13T18:35:37.866+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦