{"id":239917,"student_id":10,"content":"setBackdrop(\"black\")\nlet bg = createSprite(\"bg.png\"); //背景圖\nlet player = createSprite(\"player.png\"); //玩家飛船\nlet laser = createSprite(\"laser_b.png\"); //玩家的子彈\nlet master = createSprite(\"master_0.png\", \"master_1.png\", \"master_2.png\"); //魔王\nlet info = createSprite(\"info.png\", \"failed.png\", \"completed.png\"); //遊戲說明\n\nlet clock = 0; //遊戲迴圈的執行是數\nlet level = 1; //目前關卡\nlet count = 0; //紀錄多少小兵被打死\nlet vx = 3; //魔王水平移動速度\nlet masterLife = 10; //魔王血量\nlet playerLife = 10; //玩家血量\nlet lasers = []; //存放敵人的子彈\nlet enemies = []; //存放敵人的小兵\n\nmaster.moveTo(600, 100);\nplayer.moveTo(600, 800);\nlaser.direction = 0;\nlaser.hidden = true;\n// info.hidden = true;\ninfo.layer = 1;\n\nlet bgm = createSound('bgm.mp3');\nplayer.scale = 0.7;\nmaster.scale = 1.3;\n\ninitLevel();\n\n// 初始化關卡\nfunction initLevel () {\n for (let y = 0; y \u003c level; y++) {\n for (let x = 0; x \u003c 8; x++) {\n let e = createSprite(\"e_0.png\", \"e_1.png\", \"e_2.png\");\n e.x = x * 100 + 50;\n e.y = y * 100 + 250;\n e.costumeId = level - 1;\n enemies.push(e);\n }\n }\n count = 0;\n clock = 0;\n masterLife = 10;\n playerLife = 10;\n master.moveTo(600, 100);\n master.costumeId = level - 1;\n master.hidden = false;\n}\n\nfunction gameloop () {\n if (info.hidden) {\n clock++;\n updatePlayer(); //更新玩家飛船\n updatePlayerLaser(); //更新玩家的子彈\n updateMaster(); //更新魔王\n updateMasterLaser(); //更新的子彈\n updateEnemise(); //更新小兵\n updateBackgroud(); //捲動背景圖\n drawLife();\n gameoverCheck();\n }\n if (key.space) {\n info.hidden = true;\n }\n if (info.costumeId != 0) {\n info.opacity += 0.03;\n if (info.opacity \u003e= 1) stop();\n }\n}\n\n// 更新玩家\nfunction updatePlayer () {\n if (key.right \u0026\u0026 player.x \u003c 1200) player.x += 10;\n if (key.left \u0026\u0026 player.x \u003e 0) player.x -= 10;\n if (key.up \u0026\u0026 laser.y \u003c 0) {\n laser.moveTo(player);\n laser.hidden = false;\n createSound('laser.mp3');\n }\n}\n\n// 移動玩家的子彈\nfunction updatePlayerLaser () {\n laser.stepForward(20);\n if (laser.touched(master)) {\n masterLife -= 1;\n laser.hidden = true;\n if (masterLife \u003c= 0) {\n master.hidden = true;\n }\n createSound('boom.mp3');\n }\n for (let i = 0; i \u003c enemies.length; i++) {\n let e = enemies[i];\n if (e.touched(laser)) {\n e.destroy();\n laser.hidden = true;\n count += 1;\n diffusionFire(e);\n createSound('boom.mp3');\n }\n }\n}\n\n//更新魔王\nfunction updateMaster() {\n if (clock % 800 \u003c 200) master.x += 3;\n else if (clock % 800 \u003c 600) master.x -= 3;\n else master.x += 3;\n\n if (Math.random() \u003c 0.02 \u0026\u0026 master.hidden == false) {\n enemyFired(master.x, master.y);\n if (level \u003e= 2) {\n enemyFired(master.x + 50, master.y);\n }\n if (level \u003e= 3) {\n enemyFired(master.x - 50, master.y);\n }\n }\n if (level \u003e= 3 \u0026\u0026 Math.random() \u003c 0.01) {\n diffusionFire(master);\n }\n}\n\n\n// 更新敵人的子彈\nfunction updateMasterLaser () {\n for (let i = 0; i \u003c lasers.length; i++) {\n let laser = lasers[i];\n laser.stepForward(5);\n if (laser.touched(player)) {\n laser.destroy();\n playerLife -= 1;\n createSound('boom.mp3');\n }\n }\n}\n\n// 更新敵人的位置\nfunction updateEnemise () {\n for (let i = 0; i \u003c enemies.length; i++) {\n let e = enemies[i];\n if (clock % 840 \u003c 400) e.x += 1;\n else if (clock % 840 \u003c 420) e.y += 1;\n else if (clock % 840 \u003c 820) e.x -= 1;\n else e.y += 1;\n }\n}\n\n// 敵人發射發散的子彈\nfunction diffusionFire (enemy) {\n for (let i = 0; i \u003c 8; i++) {\n let laser = createSprite('laser_r.png');\n laser.moveTo(enemy);\n laser.direction = i * 45;\n lasers.push(laser);\n }\n}\n\n// 遊戲成功失敗判斷\nfunction gameoverCheck () {\n if (playerLife \u003c= 0) {\n info.costumeId = 1;\n info.hidden = false;\n info.opacity = 0;\n }\n if (count == level * 8 \u0026\u0026 masterLife == 0) {\n level++;\n if (level \u003c= 3) initLevel();\n else {\n info.costumeId = 2;\n info.hidden = false;\n info.opacity = 0; \n }\n }\n}\n\nfunction enemyFired (x, y) {\n let laser = createSprite('laser_r.png');\n laser.y = y;\n laser.x = x;\n laser.direction = 180;\n lasers.push(laser);\n return laser;\n}\n\nfunction drawLife () {\n drawText('masterLife: ' + masterLife, 10, 10, 'red', 30);\n drawText('playerLife: ' + playerLife, 10, 850, 'lightblue', 30);\n // pen.fillColor = '#333';\n // pen.drawRect(master.x - 50, master.y + 80, 100, 5);\n // pen.fillColor = 'red';\n // pen.drawRect(master.x - 50, master.y + 80, masterLife * 10, 5);\n // pen.fillColor = '#333';\n // pen.drawRect(player.x - 50, player.y + 80, 100, 5);\n // pen.fillColor = 'red';\n // pen.drawRect(player.x - 50, player.y + 80, playerLife * 10, 5);\n}\n\n// 捲動背景圖\nfunction updateBackgroud() {\n bg.y += 0.5;\n if (bg.y \u003e 900) bg.y -= 900;\n}\n\nforever(gameloop);","created_at":"2021-03-29T11:19:30.214+08:00","updated_at":"2022-05-24T15:30:28.619+08:00","name":"太空侵略者 完整版","language":"javascript","screenshot":{"url":"https://cdn6.koding.school/uploads/project/screenshot/239917/41dae8d00a8a8df4a23ce46d320267f8.jpg"},"parent_id":237913,"plugin":"Game.set({\n width: 1200, height: 900\n})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":223,"hashid":"jzmsezgyj","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":4400331,"file_name":"boom.mp3","project_id":239917,"asset_id":280653,"created_at":"2021-03-29T11:19:30.220+08:00","updated_at":"2021-03-29T11:19:30.220+08:00"},{"id":4400332,"file_name":"laser.mp3","project_id":239917,"asset_id":280652,"created_at":"2021-03-29T11:19:30.222+08:00","updated_at":"2021-03-29T11:19:30.222+08:00"},{"id":4400333,"file_name":"bgm.mp3","project_id":239917,"asset_id":280651,"created_at":"2021-03-29T11:19:30.223+08:00","updated_at":"2021-03-29T11:19:30.223+08:00"},{"id":4400334,"file_name":"bg.png","project_id":239917,"asset_id":329759,"created_at":"2021-03-29T11:19:30.223+08:00","updated_at":"2021-03-29T11:19:30.223+08:00"},{"id":4400335,"file_name":"completed.png","project_id":239917,"asset_id":329760,"created_at":"2021-03-29T11:19:30.225+08:00","updated_at":"2021-03-29T11:19:30.225+08:00"},{"id":4400339,"file_name":"failed.png","project_id":239917,"asset_id":329764,"created_at":"2021-03-29T11:19:30.228+08:00","updated_at":"2021-03-29T11:19:30.228+08:00"},{"id":4400340,"file_name":"info.png","project_id":239917,"asset_id":329765,"created_at":"2021-03-29T11:19:30.229+08:00","updated_at":"2021-03-29T11:19:30.229+08:00"},{"id":4400341,"file_name":"master_0.png","project_id":239917,"asset_id":329768,"created_at":"2021-03-29T11:19:30.230+08:00","updated_at":"2021-03-29T11:19:30.230+08:00"},{"id":4400342,"file_name":"master_1.png","project_id":239917,"asset_id":329769,"created_at":"2021-03-29T11:19:30.232+08:00","updated_at":"2021-03-29T11:19:30.232+08:00"},{"id":4400343,"file_name":"master_2.png","project_id":239917,"asset_id":329770,"created_at":"2021-03-29T11:19:30.232+08:00","updated_at":"2021-03-29T11:19:30.232+08:00"},{"id":4400344,"file_name":"player.png","project_id":239917,"asset_id":329771,"created_at":"2021-03-29T11:19:30.233+08:00","updated_at":"2021-03-29T11:19:30.233+08:00"},{"id":4400345,"file_name":"laser_b.png","project_id":239917,"asset_id":329772,"created_at":"2021-03-29T11:19:30.234+08:00","updated_at":"2021-03-29T11:19:30.234+08:00"},{"id":4400346,"file_name":"laser_r.png","project_id":239917,"asset_id":329773,"created_at":"2021-03-29T11:19:30.235+08:00","updated_at":"2021-03-29T11:19:30.235+08:00"},{"id":4400338,"file_name":"e_2.png","project_id":239917,"asset_id":329763,"created_at":"2021-03-29T11:19:30.228+08:00","updated_at":"2021-03-29T11:28:58.889+08:00"},{"id":4400337,"file_name":"e_1.png","project_id":239917,"asset_id":329762,"created_at":"2021-03-29T11:19:30.227+08:00","updated_at":"2021-03-29T11:29:02.822+08:00"},{"id":4400336,"file_name":"e_0.png","project_id":239917,"asset_id":329761,"created_at":"2021-03-29T11:19:30.226+08:00","updated_at":"2021-03-29T11:29:10.646+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦