{"id":382773,"student_id":10,"content":"let bg = createSprite('bg.png'); //背景圖\nlet master = createSprite('master_0.png', 'master_1.png', 'master_2.png'); //魔王\nlet laser = createSprite('laser_b.png'); //玩家子彈\nlet player = createSprite('player.png'); //玩家飛船\nlet info = createSprite('info.png', 'success.png', 'fail.png'); //遊戲說明\n\nlet enemies = []; //存放小兵角色\nlet lasers = []; //存放敵人子彈\nlet clock = 0; //紀錄遊戲迴圈執行次數\nlet level = 0; //關卡等級\nlet vx = 3; //魔王水平移動速度\nlet playerLife = 10; //玩家血量\nlet masterLife = 10; //魔王血量\nlet count = 0; //消滅小兵數量\n\nmaster.y = 100;\nplayer.y = 800;\nlaser.direction = 0;\nlaser.hidden = true;\ninfo.opacity = 0;\ncreateSound('bgm.mp3', true);\ninfo.layer = 1;\n\n//初始化關卡\nfunction startLevel () {\n clock = -500;\n level += 1;\n count = 0;\n masterLife = 10;\n playerLife = 10;\n enemies = [];\n for (let x = 0; x \u003c 9; x++) {\n for (let y = 0; y \u003c level; y++) {\n let e = createSprite('enemy_0.png', 'enemy_1.png', 'enemy_2.png');\n e.x = x * 100 + 50;\n e.y = y * 100 + 50 + 200;\n e.y -= 500;\n e.costumeId = level - 1;\n enemies.push(e);\n }\n }\n master.y = -400;\n master.costumeId = level - 1;\n}\n\n//遊戲主迴圈\nfunction gameloop () {\n if (info.opacity \u003c 1) {\n clock++;\n laser.y -= 30;\n updatePlayer(); //更新玩家\n updateMaster(); //更新魔王\n updateLasers(); //更新敵人子彈\n enemies.forEach(updateEnemy); //更新小兵\n checkIsGameover(); //檢查遊戲是否結束\n updateBg(); //更新背景圖\n drawTexts(); //顯示變數資訊\n }\n if (key.space) {\n info.opacity = 0;\n }\n if (info.costumeId != 0 \u0026\u0026 info.opacity \u003c 1) {\n info.opacity += 0.01;\n }\n}\n\n//更新玩家角色\nfunction updatePlayer () {\n if (key.right \u0026\u0026 player.x \u003c 1100) {\n player.x += 5;\n }\n if (key.left \u0026\u0026 player.x \u003e 100) {\n player.x -= 5;\n }\n if (key.up \u0026\u0026 (laser.hidden || laser.y \u003c 0)) {\n laser.x = player.x;\n laser.y = player.y;\n laser.hidden = false;\n createSound('laser.mp3');\n }\n}\n\n//更新魔王角色\nfunction updateMaster () {\n if (clock \u003c 0) master.y += 1;\n master.x += vx;\n if (master.x \u003e 1100 || master.x \u003c 100 || Math.random() \u003c 0.01) {\n vx = -vx;\n }\n\n if (masterLife \u003e 0 \u0026\u0026 clock % 60 == 0) {\n if (level == 1 || level == 3) {\n createLaser(master.x, master.y, 180);\n }\n if (level == 2 || level == 3) {\n createLaser(master.x + 30, master.y, 180);\n createLaser(master.x - 30, master.y, 180);\n }\n }\n if (masterLife \u003e 0 \u0026\u0026 clock % 300 == 0 \u0026\u0026 level == 3) {\n for (let i = 0; i \u003c 12; i++) {\n createLaser(master.x, master.y, 30 * i);\n }\n }\n\n if (master.touched(laser)) {\n masterLife -= 1;\n laser.hidden = true;\n master.opacity = 0;\n createSound('boom.mp3');\n } else {\n master.opacity = 1;\n }\n\n master.hidden = masterLife \u003c= 0;\n\n}\n\n//更新小兵\nfunction updateEnemy(e) {\n if (clock \u003c 0) {\n e.y += 1;\n } else {\n re = clock % 700;\n if (re \u003c 300) e.x += 1;\n else if (re \u003c 350) e.y += 1;\n else if (re \u003c 650) e.x -= 1;\n else e.y += 1;\n }\ns\n if (e.touched(laser)) {\n e.destroy();\n laser.hidden = true;\n count++;\n for (let i = 0; i \u003c 8; i++) {\n createLaser(e.x, e.y, 45 * i);\n }\n createSound('boom.mp3');\n }\n \n if (e.y \u003e 800) playerLife = 0;\n}\n\n//創造敵人子彈\nfunction createLaser (x, y, d) {\n let laser = createSprite('laser_r.png');\n laser.moveTo(x, y);\n laser.direction = d;\n lasers.push(laser);\n}\n\n//更新敵人子彈\nfunction updateLasers () {\n for (let i = 0; i \u003c lasers.length; i++) {\n lasers[i].stepForward(5);\n if (lasers[i].touched(player)) {\n lasers[i].destroy();\n playerLife -= 1;\n player.opacity = 0;\n createSound('boom.mp3');\n } else {\n player.opacity = 1;\n }\n }\n}\n\n//檢查遊戲是否結束\nfunction checkIsGameover () {\n if (masterLife \u003c= 0 \u0026\u0026 count == level * 9) {\n if (level == 3) {\n info.costumeId = 1;\n } else {\n startLevel();\n }\n }\n if (playerLife \u003c= 0) {\n info.costumeId = 2;\n }\n}\n\n//更新背景圖\nfunction updateBg () {\n bg.y += 2;\n if (bg.y \u003e 900) bg.y -= 900;\n}\n\n//顯示遊戲資訊\nfunction drawTexts () {\n drawText('masterLife: ' + masterLife, 10, 10, 'white', 30);\n drawText('playerLife: ' + playerLife, 10, 40, 'white', 30);\n drawText('level: ' + level, 10, 70, 'white', 30);\n drawText('count: ' + count, 10, 100, 'white', 30);\n}\n\n\nforever(gameloop);\nstartLevel();","created_at":"2022-05-24T15:30:49.600+08:00","updated_at":"2022-06-14T16:52:36.683+08:00","name":"太空侵略者(完整版)","language":"javascript","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/382773/d50ed6677169d99527cd49f8f1195de6.jpg"},"parent_id":4,"plugin":"Game.set({width: 1200, height: 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":143,"hashid":"jzmseq6q6","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":8548679,"file_name":"enemy_1.png","project_id":382773,"asset_id":508000,"created_at":"2022-05-24T15:31:11.825+08:00","updated_at":"2022-05-24T15:31:11.825+08:00"},{"id":8548680,"file_name":"enemy_2.png","project_id":382773,"asset_id":508001,"created_at":"2022-05-24T15:31:11.830+08:00","updated_at":"2022-05-24T15:31:11.830+08:00"},{"id":8548681,"file_name":"enemy_0.png","project_id":382773,"asset_id":508002,"created_at":"2022-05-24T15:31:11.835+08:00","updated_at":"2022-05-24T15:31:11.835+08:00"},{"id":8548682,"file_name":"bg.png","project_id":382773,"asset_id":508003,"created_at":"2022-05-24T15:31:11.840+08:00","updated_at":"2022-05-24T15:31:11.840+08:00"},{"id":8548683,"file_name":"fail.png","project_id":382773,"asset_id":508004,"created_at":"2022-05-24T15:31:11.846+08:00","updated_at":"2022-05-24T15:31:11.846+08:00"},{"id":8548684,"file_name":"bgm.mp3","project_id":382773,"asset_id":508005,"created_at":"2022-05-24T15:31:11.989+08:00","updated_at":"2022-05-24T15:31:11.989+08:00"},{"id":8548685,"file_name":"laser.mp3","project_id":382773,"asset_id":508006,"created_at":"2022-05-24T15:31:11.995+08:00","updated_at":"2022-05-24T15:31:11.995+08:00"},{"id":8548686,"file_name":"boom.mp3","project_id":382773,"asset_id":508007,"created_at":"2022-05-24T15:31:12.000+08:00","updated_at":"2022-05-24T15:31:12.000+08:00"},{"id":8548687,"file_name":"success.png","project_id":382773,"asset_id":508008,"created_at":"2022-05-24T15:31:12.006+08:00","updated_at":"2022-05-24T15:31:12.006+08:00"},{"id":8548688,"file_name":"master_2.png","project_id":382773,"asset_id":508009,"created_at":"2022-05-24T15:31:12.011+08:00","updated_at":"2022-05-24T15:31:12.011+08:00"},{"id":8548689,"file_name":"master_1.png","project_id":382773,"asset_id":508010,"created_at":"2022-05-24T15:31:12.017+08:00","updated_at":"2022-05-24T15:31:12.017+08:00"},{"id":8548690,"file_name":"info.png","project_id":382773,"asset_id":508011,"created_at":"2022-05-24T15:31:12.023+08:00","updated_at":"2022-05-24T15:31:12.023+08:00"},{"id":8548691,"file_name":"laser_b.png","project_id":382773,"asset_id":508012,"created_at":"2022-05-24T15:31:12.028+08:00","updated_at":"2022-05-24T15:31:12.028+08:00"},{"id":8548692,"file_name":"laser_r.png","project_id":382773,"asset_id":508013,"created_at":"2022-05-24T15:31:12.033+08:00","updated_at":"2022-05-24T15:31:12.033+08:00"},{"id":8548693,"file_name":"player.png","project_id":382773,"asset_id":508014,"created_at":"2022-05-24T15:31:12.038+08:00","updated_at":"2022-05-24T15:31:12.038+08:00"},{"id":8548694,"file_name":"master_0.png","project_id":382773,"asset_id":508015,"created_at":"2022-05-24T15:31:12.044+08:00","updated_at":"2022-05-24T15:31:12.044+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦