{"id":512233,"student_id":26492,"content":"// 將背景設定為黑色\r\nsetBackdrop(\"#000000\");\r\n// 用 \"head.gif\" 創造一個角色\r\nvar head = createSprite( \"head.gif\" );\r\n head.x = 320;\r\n head.y = 240;\r\n//用foos.gif創造一個角色\r\nvar food = createSprite(\"food.gif\");\r\n food.x = Math.random()*640;\r\n food.y = Math.random()*480;\r\nvar clock = 0;\r\nvar score = 0;\r\nvar bodies = [];\r\n\r\nforever(function(){\r\n // 在這裡的程式碼會不斷執行\r\n print(bodies.length, 10, 10, 'white')\r\n //console.log(clock);\r\n clock = clock + 1;\r\n if(clock % 6 == 0){\r\n playerControl();\r\n eat();\r\n move();\r\n checkGameover();\r\n }\r\n});\r\n\r\nfunction eat(){\r\n if(head.touched(food)){\r\n food.x = Math.random()*640;\r\n food.y = Math.random()*480;\r\n score = score + 1;\r\n \r\n var body = createSprite(\"body.gif\");\r\n bodies.push(body);\r\n }\r\n}\r\n\r\nfunction move(){\r\n if(bodies.length \u003e 0){\r\n var lastBody = bodies.pop();\r\n lastBody.x = head.x;\r\n lastBody.y = head.y;\r\n bodies.unshift(lastBody);\r\n }\r\n head.stepForward(16);\r\n}\r\n\r\nfunction playerControl(){\r\n if(key.up){\r\n head.direction = 0;\r\n }\r\n if(key.down){\r\n head.direction = 180;\r\n }\r\n if(key.right){\r\n head.direction = 90;\r\n }\r\n if(key.left){\r\n head.direction = 270;\r\n }\r\n}\r\n\r\n//遊戲結束\r\nfunction checkGameover(){\r\n if(head.touched(bodies) || head.x \u003c 0 || head.x \u003e 640 || head.y \u003c 0 || head.y \u003e 480){\r\n stop(); \r\n print('Game Over', 200, 200, 'white', 60);\r\n }\r\n}\r\n\r\n\r\n","created_at":"2023-03-28T19:03:25.380+08:00","updated_at":"2023-03-28T20:54:42.135+08:00","name":"貪食蛇_S 副本","language":"javascript","screenshot":{"url":"https://cdn2.koding.school/uploads/project/screenshot/512233/bf4bfdb199cc2e6a66c88a58b8563abb.jpg"},"parent_id":54317,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":7,"hashid":"kdmsjeg46","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":11659412,"file_name":"food.gif","project_id":512233,"asset_id":107710,"created_at":"2023-03-28T19:03:25.388+08:00","updated_at":"2023-03-28T19:03:25.388+08:00"},{"id":11659413,"file_name":"body.gif","project_id":512233,"asset_id":107711,"created_at":"2023-03-28T19:03:25.389+08:00","updated_at":"2023-03-28T19:03:25.389+08:00"},{"id":11659414,"file_name":"head.gif","project_id":512233,"asset_id":107712,"created_at":"2023-03-28T19:03:25.390+08:00","updated_at":"2023-03-28T19:03:25.390+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦