{"id":320319,"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 clock = 0; //紀錄遊戲迴圈執行次數\nlet level = 0; //關卡等級\nlet vx = 3; //魔王水平移動速度\nlet playerLife = 10; //玩家血量\nlet masterLife = 10; //魔王血量\nlet count = 0; //每一關小兵消滅數\nlet enemies = []; //存放小兵角色\nlet lasers = []; //存放敵人雷射\n\nmaster.y = 100; //初始化魔王位置\nplayer.y = 800; //初始化玩家位置\nlaser.direction = 0; //玩家雷射朝向上方\nlaser.hidden = true; //隱藏玩家雷射\ninfo.layer = 1; //設定遊戲說明圖層\nplayer.layer = 2; //設定飛船圖層\ninfo.opacity = 0; //遊戲說明\n\ncreateSound('bgm.mp3', true); //播放背景音樂\n\n//初始化關卡\nfunction startLevel () {\n masterLife = 10; //恢復魔王血量\n playerLife = 10; //恢復玩家血量\n count = 0; //重新紀錄每關小兵消滅數\n enemies = []; //清空存放小兵角色陣列\n clock = -100; //重置計時器\n level += 1;\n for (let y = 0; y \u003c level; y++) {\n for (let x = 0; x \u003c 9; x++) {\n let e = createSprite('enemy_0.png', 'enemy_1.png', 'enemy_2.png');\n e.x = 50 + x * 100;\n e.y = 250 + y * 100;\n e.costumeId = level - 1;\n enemies.push(e);\n e.y -= 500;\n }\n }\n master.costumeId = level - 1;\n master.y -= 500;\n}\n\n//遊戲主迴圈\nfunction gameloop () {\n // 如果角色全透明消失就開始遊戲\n if (info.opacity \u003c 1) {\n clock++;\n updatePlayer(); //更新玩家\n updateMaster(); //更新魔王\n updateLasers(); //更新雷射\n enemies.forEach(updateEnemy); //更新小兵\n checkIsGameover(); //檢查遊戲是否結束\n drawTexts(); //顯示變數資訊\n updateBg(); //捲動背景圖\n }\n //按下空白按鍵開始遊戲\n if (key.space) {\n info.opacity = 0;\n }\n //如果遊戲結束就慢慢淡入\n if (info.costumeId != 0 \u0026\u0026 info.opacity \u003c 1) {\n info.opacity += 0.01;\n }\n}\n\n//更新玩家角色\nfunction updatePlayer () {\n // 按下右鍵且沒超出右邊邊界,就向右移動 5\n if (key.right \u0026\u0026 player.x \u003c 1100) player.x += 5;\n\n // 按下左鍵且沒超出左邊邊界,就向左移動 5\n if (key.left \u0026\u0026 player.x \u003e 100) player.x -= 5;\n\n // 按下上鍵且雷射已經隱藏或超出場景上方\n if (key.up \u0026\u0026 (laser.hidden || laser.y \u003c 0)) {\n laser.moveTo(player); //移動至玩家所在座標\n laser.hidden = false; //將隱藏的雷射重新顯示\n createSound('laser.mp3'); //播放發射音效\n }\n}\n\n//更新魔王角色\nfunction updateMaster () {\n \n if (clock \u003c 0) {\n master.y += 5;\n }\n\n master.x += vx;\n // 當魔王移動到左右邊界或 1/100 機率發生時\n if (master.x \u003e 1100 || master.x \u003c 100 || Math.random() \u003c 0.01) {\n vx = -vx; //轉向\n }\n\n // 如果魔王被玩家雷射打到\n if (master.touched(laser)) {\n masterLife -= 1; //血量減一\n laser.hidden = true; //隱藏玩家雷射\n createSound('boom.mp3'); //播放音效\n master.opacity = 0; //魔王變透明\n } else {\n master.opacity = 1; //魔王變不透明\n }\n\n master.hidden = masterLife \u003c= 0; //如果魔王血量低於 0 就隱藏\n\n // 魔王發射雷射\n if (Math.random() \u003c 0.01 * level \u0026\u0026 masterLife \u003e 0) {\n createLaser(master.x, master.y, 180);\n }\n}\n\n//更新小兵\nfunction updateEnemy(e) {\n\n // 如果小兵碰到雷射\n if (e.touched(laser)) {\n e.destroy(); //移除小兵角色\n laser.hidden = true; //隱藏玩家雷射\n count++; //小兵消滅數加一\n createSound('boom.mp3');\n for (let i = 0; i \u003c 8; i++) {\n createLaser(e.x, e.y, i * 45);\n }\n }\n\n // 如果小兵超過下方界線,就讓玩家生命歸零來結束遊戲\n if (e.y \u003e 800) playerLife = 0;\n\n // 更新小兵位置\n let c = clock % 700;\n if (clock \u003c 0) {\n e.y += 5;\n } else if (c \u003c 300) {\n e.x += 1;\n } else if (c \u003c 350) {\n e.y += 1;\n } else if (c \u003c 650) {\n e.x -= 1;\n } else {\n e.y += 1;\n }\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 laser.y -= 30; //玩家雷射以 30 速度向上移動\n for (let i = 0; i \u003c lasers.length; i++) {\n lasers[i].stepForward(5); //敵人雷射以 5 速度向前移動\n if (lasers[i].touched(player)) {\n lasers[i].destroy();\n playerLife -= 1;\n createSound('boom.mp3');\n player.opacity = 0;\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 // 如果是第三關就\n info.costumeId = 1; //結束遊戲\n } else {\n startLevel(); //重新下一關\n }\n }\n // 如果玩家血量低於 0 就結束遊戲\n if (playerLife \u003c= 0) info.costumeId = 2;\n}\n\n//捲動背景圖\nfunction updateBg () {\n bg.y += 3;\n if (bg.y \u003e 900) bg.y -= 900;\n}\n\n//顯示遊戲資訊\nfunction drawTexts () {\n drawText('masterLife: ' + masterLife, 10, 10, 'white', 20);\n drawText('playerLife: ' + playerLife, 10, 30, 'white', 20);\n drawText('level: ' + level, 10, 50, 'white', 20);\n drawText('count: ' + count, 10, 70, 'white', 20);\n drawText('clock: ' + count, 10, 90, 'white', 20);\n}\n\nforever(gameloop);\nstartLevel();","created_at":"2021-11-30T11:52:20.310+08:00","updated_at":"2022-09-22T19:35:58.213+08:00","name":"太空侵略者(預設版)","language":"javascript","screenshot":{"url":"https://cdn6.koding.school/uploads/project/screenshot/320319/b230fa3bcc0fafe3f75ee57f07ce202f.jpg"},"parent_id":2,"plugin":"Game.set({width: 1200, height: 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":157,"hashid":"p93sk5ymz","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":9863017,"file_name":"enemy_1.png","project_id":320319,"asset_id":565190,"created_at":"2022-09-22T11:39:28.693+08:00","updated_at":"2022-09-22T11:39:28.693+08:00"},{"id":9863018,"file_name":"enemy_2.png","project_id":320319,"asset_id":565191,"created_at":"2022-09-22T11:39:28.701+08:00","updated_at":"2022-09-22T11:39:28.701+08:00"},{"id":9863019,"file_name":"enemy_0.png","project_id":320319,"asset_id":565192,"created_at":"2022-09-22T11:39:28.705+08:00","updated_at":"2022-09-22T11:39:28.705+08:00"},{"id":9863020,"file_name":"bg.png","project_id":320319,"asset_id":565193,"created_at":"2022-09-22T11:39:28.710+08:00","updated_at":"2022-09-22T11:39:28.710+08:00"},{"id":9863021,"file_name":"fail.png","project_id":320319,"asset_id":565194,"created_at":"2022-09-22T11:39:28.718+08:00","updated_at":"2022-09-22T11:39:28.718+08:00"},{"id":9863022,"file_name":"bgm.mp3","project_id":320319,"asset_id":565195,"created_at":"2022-09-22T11:39:28.800+08:00","updated_at":"2022-09-22T11:39:28.800+08:00"},{"id":9863023,"file_name":"laser.mp3","project_id":320319,"asset_id":565196,"created_at":"2022-09-22T11:39:28.806+08:00","updated_at":"2022-09-22T11:39:28.806+08:00"},{"id":9863024,"file_name":"boom.mp3","project_id":320319,"asset_id":565197,"created_at":"2022-09-22T11:39:28.810+08:00","updated_at":"2022-09-22T11:39:28.810+08:00"},{"id":9863025,"file_name":"success.png","project_id":320319,"asset_id":565198,"created_at":"2022-09-22T11:39:28.815+08:00","updated_at":"2022-09-22T11:39:28.815+08:00"},{"id":9863026,"file_name":"master_2.png","project_id":320319,"asset_id":565199,"created_at":"2022-09-22T11:39:28.820+08:00","updated_at":"2022-09-22T11:39:28.820+08:00"},{"id":9863027,"file_name":"master_1.png","project_id":320319,"asset_id":565200,"created_at":"2022-09-22T11:39:28.825+08:00","updated_at":"2022-09-22T11:39:28.825+08:00"},{"id":9863028,"file_name":"info.png","project_id":320319,"asset_id":565201,"created_at":"2022-09-22T11:39:28.830+08:00","updated_at":"2022-09-22T11:39:28.830+08:00"},{"id":9863029,"file_name":"laser_b.png","project_id":320319,"asset_id":565202,"created_at":"2022-09-22T11:39:28.835+08:00","updated_at":"2022-09-22T11:39:28.835+08:00"},{"id":9863030,"file_name":"laser_r.png","project_id":320319,"asset_id":565203,"created_at":"2022-09-22T11:39:28.840+08:00","updated_at":"2022-09-22T11:39:28.840+08:00"},{"id":9863031,"file_name":"player.png","project_id":320319,"asset_id":565204,"created_at":"2022-09-22T11:39:28.845+08:00","updated_at":"2022-09-22T11:39:28.845+08:00"},{"id":9863032,"file_name":"master_0.png","project_id":320319,"asset_id":565205,"created_at":"2022-09-22T11:39:28.850+08:00","updated_at":"2022-09-22T11:39:28.850+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦