{"id":237913,"student_id":10,"content":"setBackdrop(\"black\")\n\nlet bg = createSprite(\"bg.png\"); //背景圖\nlet masterLife = 10; //魔王血量\nlet playerLife = 10; //玩家血量\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\"); //遊戲說明\nlet lasers = []; //存放敵人的子彈\nlet enemies = []; //存放敵人的小兵\nlet clock = 0; //遊戲迴圈的執行是數\nlet level = 0; //目前關卡\nlet count = 0; //紀錄多少小兵被打死\nlet vx = 3; //魔王水平移動速度\n\nmaster.moveTo(600, 100);\nplayer.moveTo(600, 750);\nlaser.direction = 0;\nlaser.hidden = true;\n\nbgm = createSound('bgm.mp3');\nbgm.setVolume(0.5)\n\nplayer.scale = 0.8;\nmaster.scale = 1.2;\nbg.opacity = 0;\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(\"enemy_0.png\", \"enemy_1.png\", \"enemy_2.png\");\n e.x = x * 100 + 50;\n e.y = y * 100 + 200;\n e.costumeId = level - 1;\n enemies.push(e);\n }\n }\n level += 1;\n count = 0;\n clock = 0;\n master.x = 100;\n master.costumeId = level - 1;\n master.hidden = false;\n masterLife = 10;\n playerLife = 10;\n}\n\nfunction gameloop () {\n if (info.hidden) {\n updateInfo();\n updatePlayer();\n updatePlayerLaser();\n updateMaster();\n updateMasterLaser();\n updateEnemise();\n updateBackgroud();\n }\n if (key.space \u0026\u0026 info.hidden == false) {\n info.hidden = true;\n initLevel();\n }\n if (info.opacity \u003c 1) {\n info.opacity += 0.03;\n if (info.opacity \u003e= 1) stop();\n }\n}\n\n//更新遊戲資訊\nfunction updateInfo () {\n clock++;\n drawText('count: ' + count, 150, 850, 'white', 30);\n drawText('level: ' + level, 310, 850, 'white', 30);\n if (master.hidden \u0026\u0026 count == level*8) {\n if (level == 3) {\n info.hidden = false;\n info.opacity = 0;\n info.costumeId = 2;\n }\n else {\n initLevel();\n }\n }\n if (playerLife \u003c= 0) {\n info.hidden = false;\n info.opacity = 0;\n info.costumeId = 1;\n }\n \n drawLife(master, masterLife)\n drawLife(player, playerLife)\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.hidden) {\n laser.moveTo(player);\n laser.hidden = false;\n createSound('laser.mp3')\n }\n}\n\n// 移動玩家的子彈\nfunction updatePlayerLaser () {\n laser.stepForward(15);\n if (laser.y \u003c 0) {\n laser.hidden = true;\n }\n if (laser.touched(master)) {\n masterLife -= 1;\n masterFlashing = 30;\n laser.hidden = true;\n createSound('boom.mp3');\n if (masterLife \u003c= 0) {\n master.hidden = true;\n }\n }\n}\n\n//更新魔王\nfunction updateMaster() {\n master.x += vx;\n if (master.x \u003e 1200 || master.x \u003c 0) vx = -vx;\n if (Math.random() \u003c 0.02 \u0026\u0026 master.hidden == false) {\n enemyFire(master);\n if (level \u003e= 2) enemyFire(master).x += 50;\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 if (e.touched(laser)) {\n e.destroy();\n laser.hidden = true;\n diffusionFire(e);\n count += 1;\n createSound('boom.mp3')\n }\n }\n}\n\n// 敵人發射子彈\nfunction enemyFire (enemy) {\n let laser = createSprite('laser_r.png');\n laser.moveTo(enemy);\n laser.direction = 180;\n lasers.push(laser);\n return laser;\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\nfunction updateBackgroud() {\n bg.y += 0.5;\n if (bg.y \u003e 900) bg.y -= 900;\n}\n\nfunction drawLife (sprite, life) {\n // drawText('life: ' + masterLife, 10, 10, 'red', 30);\n // drawText('life: ' + playerLife, 10, 850, 'lightblue', 30);\n \n pen.fillColor = '#333';\n pen.drawRect(sprite.x - 50, sprite.y + 100, 100, 5);\n pen.fillColor = 'red';\n pen.drawRect(sprite.x - 50, sprite.y + 100, life * 10, 5);\n}\n\nforever(gameloop);","created_at":"2021-03-22T15:57:16.316+08:00","updated_at":"2021-05-14T10:14:55.388+08:00","name":"太空侵略者 副本","language":"javascript","screenshot":{"url":"https://cdn5.koding.school/uploads/project/screenshot/237913/f1ecbf72cc6d524756d0334716a7caec.jpg"},"parent_id":233753,"plugin":"Game.set({\n width: 1200, height: 900\n})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":205,"hashid":"6rps9rwzr","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":4339839,"file_name":"laser_r.png","project_id":237913,"asset_id":329773,"created_at":"2021-03-22T15:57:16.322+08:00","updated_at":"2021-03-22T15:57:16.322+08:00"},{"id":4339840,"file_name":"laser_b.png","project_id":237913,"asset_id":329772,"created_at":"2021-03-22T15:57:16.323+08:00","updated_at":"2021-03-22T15:57:16.323+08:00"},{"id":4339841,"file_name":"player.png","project_id":237913,"asset_id":329771,"created_at":"2021-03-22T15:57:16.324+08:00","updated_at":"2021-03-22T15:57:16.324+08:00"},{"id":4339842,"file_name":"master_2.png","project_id":237913,"asset_id":329770,"created_at":"2021-03-22T15:57:16.325+08:00","updated_at":"2021-03-22T15:57:16.325+08:00"},{"id":4339843,"file_name":"master_1.png","project_id":237913,"asset_id":329769,"created_at":"2021-03-22T15:57:16.326+08:00","updated_at":"2021-03-22T15:57:16.326+08:00"},{"id":4339844,"file_name":"master_0.png","project_id":237913,"asset_id":329768,"created_at":"2021-03-22T15:57:16.327+08:00","updated_at":"2021-03-22T15:57:16.327+08:00"},{"id":4339845,"file_name":"info.png","project_id":237913,"asset_id":329765,"created_at":"2021-03-22T15:57:16.327+08:00","updated_at":"2021-03-22T15:57:16.327+08:00"},{"id":4339846,"file_name":"failed.png","project_id":237913,"asset_id":329764,"created_at":"2021-03-22T15:57:16.328+08:00","updated_at":"2021-03-22T15:57:16.328+08:00"},{"id":4339847,"file_name":"enemy_2.png","project_id":237913,"asset_id":329763,"created_at":"2021-03-22T15:57:16.329+08:00","updated_at":"2021-03-22T15:57:16.329+08:00"},{"id":4339848,"file_name":"enemy_1.png","project_id":237913,"asset_id":329762,"created_at":"2021-03-22T15:57:16.330+08:00","updated_at":"2021-03-22T15:57:16.330+08:00"},{"id":4339849,"file_name":"enemy_0.png","project_id":237913,"asset_id":329761,"created_at":"2021-03-22T15:57:16.331+08:00","updated_at":"2021-03-22T15:57:16.331+08:00"},{"id":4339850,"file_name":"completed.png","project_id":237913,"asset_id":329760,"created_at":"2021-03-22T15:57:16.332+08:00","updated_at":"2021-03-22T15:57:16.332+08:00"},{"id":4339851,"file_name":"bg.png","project_id":237913,"asset_id":329759,"created_at":"2021-03-22T15:57:16.333+08:00","updated_at":"2021-03-22T15:57:16.333+08:00"},{"id":4339852,"file_name":"bgm.mp3","project_id":237913,"asset_id":280651,"created_at":"2021-03-22T15:57:16.334+08:00","updated_at":"2021-03-22T15:57:16.334+08:00"},{"id":4339853,"file_name":"laser.mp3","project_id":237913,"asset_id":280652,"created_at":"2021-03-22T15:57:16.335+08:00","updated_at":"2021-03-22T15:57:16.335+08:00"},{"id":4339854,"file_name":"boom.mp3","project_id":237913,"asset_id":280653,"created_at":"2021-03-22T15:57:16.336+08:00","updated_at":"2021-03-22T15:57:16.336+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦