{"id":503851,"student_id":2589,"content":"","created_at":"2023-03-09T12:24:14.183+08:00","updated_at":"2023-03-09T13:45:58.812+08:00","name":"貪食蛇 - 開始後用滑鼠點擊舞台以啟用按鍵,重整畫面即可重新遊戲。","language":"javascript","screenshot":{"url":null},"parent_id":2,"plugin":"// 將背景設定為黑色\nsetBackdrop(\"#000000\");\n// 用 \"head.gif\" 創造一個角色\nvar head = createSprite(\"head.gif\");\nhead.x = 320;\nhead.y = 240;\nvar food = createSprite(\"food.gif\");\nfood.x = Math.random()*640;\nfood.y = Math.random()*480;\n\nvar bodies = [];\nvar score = 0;\nvar clock = 0;\nvar speed = 6;\nvar alive = true;\n\nforever(function() {\n // 在這裡的程式碼會不斷執行\n clock = clock + 1;\n\n if (clock%speed == 0 \u0026\u0026 alive == true) {\n playerControl();\n eat();\n move();\n die();\n }\n if (alive == false) {\n print(\"Game over!\", 160, 200, \"white\", 60);\n }\n print(score, 20, 20, \"white\");\n\n});\n\nfunction 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 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}\n\nfunction eat() {\n if (head.touched(food)) {\n score += 1;\n food.x = Math.random()*640;\n food.y = Math.random()*480;\n\n var body = createSprite(\"body.gif\");\n\n bodies.push(body);\n\n if (score % 3 == 0 \u0026\u0026 speed\u003e1) {\n speed -= 1;\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 head.stepForward(16);\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}","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":79,"hashid":"jzmsk3w4g","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":11449225,"file_name":"head.gif","project_id":503851,"asset_id":612325,"created_at":"2023-03-09T12:24:18.891+08:00","updated_at":"2023-03-09T12:24:18.891+08:00"},{"id":11449226,"file_name":"body.gif","project_id":503851,"asset_id":612326,"created_at":"2023-03-09T12:24:18.898+08:00","updated_at":"2023-03-09T12:24:18.898+08:00"},{"id":11449227,"file_name":"food.gif","project_id":503851,"asset_id":612327,"created_at":"2023-03-09T12:24:18.906+08:00","updated_at":"2023-03-09T12:24:18.906+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦