{"id":199420,"student_id":12205,"content":"// 將背景設定為黑色\nsetBackdrop(\"#000000\");\n// 用 \"head.gif\" 創造一個角色\nvar head = createSprite(\"head.gif\");\nvar score = 0;\nvar clock = 0;\nvar food = createSprite(\"food.gif\");\nfood.x = Math.random()*640;\nfood.y = Math.random()*480;\nvar bodies = [];\nvar alive = true;\nvar speed = 16;\nvar cloock = 0;\n\nforever(function() {\n if (head.direction == 0 || head.direction == 180) {\n if (key.right) {\n head.direction = 90;\n }\n if (key.left) {\n head.direction = -90;\n }\n }\n if (head.direction == 270 || head.direction == 90) {\n if (key.up) {\n head.direction = 0;\n }\n if (key.down) {\n head.direction = 180;\n }\n }\n // 在這裡的程式碼會不斷執行\n clock += 1;\n if (clock %6 == 0) {\n eat();\n move();\n die();\n\n\n }\n print(bodies.length, 10, 10, \"white\");\n print(speed, 10, 50, );\n\n});\n\n\nfunction move() {\n if (bodies.length \u003e 0) {\n var lastbody = bodies.pop();\n lastbody.x = head.x;\n lastbody.y = head.y;\n bodies.unshift(lastbody);\n\n }\n head.stepForward(speed);\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 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 print(\"game over\", 100, 165, \"red\", 100);\n stop();\n }\n}\nfunction score(){\n if (score\u003e3){\n speed +=1;\n }\n \n if (score %3 == 0) {\n speed +=1;\n }\n}\n// || alive == true\n// 當按下鍵盤的「右方向鍵」時\n//when(\"keydown\", \"right\", function() {\n// head.direction = 90;\n//});\n//when(\"keydown\", \"left\", function() {\n// head.direction = -90;\n//});\n//when(\"keydown\", \"up\", function() {\n// head.direction = 0;\n//});\n//when(\"keydown\", \"down\", function() {\n// head.direction = 180;\n//});","created_at":"2020-10-30T19:05:51.258+08:00","updated_at":"2020-11-27T20:26:23.208+08:00","name":"貪食蛇_S 副本","language":"javascript","screenshot":{"url":"https://cdn2.koding.school/uploads/project/screenshot/199420/152538346c907585e59ff436877fdf0f.jpg"},"parent_id":54317,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":42,"hashid":"gk4skg288","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3431605,"file_name":"head.gif","project_id":199420,"asset_id":107712,"created_at":"2020-10-30T19:05:51.264+08:00","updated_at":"2020-10-30T19:05:51.264+08:00"},{"id":3431606,"file_name":"body.gif","project_id":199420,"asset_id":107711,"created_at":"2020-10-30T19:05:51.266+08:00","updated_at":"2020-10-30T19:05:51.266+08:00"},{"id":3431607,"file_name":"food.gif","project_id":199420,"asset_id":107710,"created_at":"2020-10-30T19:05:51.267+08:00","updated_at":"2020-10-30T19:05:51.267+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦