{"id":428186,"student_id":10,"content":"let bg0 = createSprite('bg_0.png'); //背景1\nlet devil = createSprite('devil.png'); //惡魔\nlet bg1 = createSprite('bg_1.png'); //背景2\nlet god = createSprite('god_0.png', 'god_1.png', 'god_2.png'); //財神\nlet player = createSprite('p_0.png', 'p_1.png', 'p_2.png', 'p_3.png'); //玩家\nlet info = createSprite('infoo.png'); //遊戲說明\n\nlet godVX = 10; //財神水平速度\nlet playerVX = 10; //玩家水平速度\nlet score = 0; //玩家分數\nlet clock = 3600; //遊戲時間\nlet items = []; //存放寶物角色\nlet scoreTable = [1, 5, 10, 30, 0]; //分數對照表\n\nlet bgm = createSound('bgm.mp3'); //背景音樂\n\ngod.y = 210; //財神初始化在場景上方\nplayer.y = 700; //叩叮初始化在場景下方\n\nplayer.rotationStyle = 'flipped'; //玩家圖片水平翻轉\ngod.rotationStyle = 'flipped'; //財神圖片水平翻轉\n\n//遊戲迴圈\nfunction gameloop () {\n // 遊戲說明隱藏而且遊戲時間還沒到\n if (info.hidden \u0026\u0026 clock \u003e 0) {\n clock--; //剩餘時間減少 1\n updatePlayer(); //更新玩家\n updateGod(); //更新財神\n animation(); //走路動畫\n if (clock == 0) gameover(); //結束遊戲\n if (clock % 20 == 0) createItems(); //創造物件\n devil.y += 1; //惡魔不斷往下移動\n }\n updateItems(); //更新物件\n drawTexts(); //顯示時間分數\n\n // 按下右鍵或左鍵\n if (key.right || key.left) {\n info.hidden = true; //隱藏說明圖\n }\n}\n\n// 玩家移動\nfunction updatePlayer () {\n player.x += playerVX; // 根據 playerVX 改變水平位置\n if (key.right) playerVX = 10; //按下右鍵速度向右\n if (key.left) playerVX = -10; //按下左鍵速度向左\n}\n\n// 財神移動\nfunction updateGod () {\n god.x += godVX; // 根據 godVX 改變水平位置\n if (god.x \u003e 1100) godVX = -10; //超過右邊就速度向左\n if (god.x \u003c 100) godVX = 10; //超過右邊就速度向右\n if (Math.random() \u003c 0.02) godVX = -godVX; //隨機轉向\n}\n\n// 走路動畫\nfunction animation() {\n player.costumeId = player.x % 100 \u003c 50 ? 1: 2; //玩家走路動畫\n god.costumeId = god.x % 100 \u003c 50 ? 1: 2; //財神走路動畫\n god.direction = godVX \u003e 0 ? 90: 270; //財神圖片水平翻轉\n player.direction = playerVX \u003e 0 ? 90: 270; //玩家圖片水平翻轉\n}\n\n// 顯示文字\nfunction drawTexts() {\n drawText(Math.floor(clock / 60), 110, 825, 'white', 40); //顯示剩餘時間\n drawText(score, 340, 825, 'white', 40); //顯示分數\n}\n\n//創造財寶\nfunction createItems () {\n let item = createSprite('item_0.png', 'item_1.png', 'item_2.png', 'item_3.png', 'item_4.png');\n item.moveTo(god); //將寶物移動到財神爺位置\n item.costumeId = Math.floor(Math.random() * 5); //隨機切換造型\n let rand = Math.random(); //產生一個隨機數\n if (rand \u003c 0.3) item.costumeId = 0; // 30% 機率為金幣\n else if (rand \u003c 0.6) item.costumeId = 1; // 20% 機率為寶石\n else if (rand \u003c 0.8) item.costumeId = 2; // 30% 機率為錢袋\n else if (rand \u003c 0.9) item.costumeId = 3; // 10% 機率為寶箱\n else {\n item.costumeId = 4; // 10% 機率為炸彈\n devil.moveTo(god);\n }\n item.vy = -10; //初始墜落速度\n items.push(item);\n}\n\n// 更新財寶的位置\nfunction updateItems () {\n for (let i = 0; i \u003c items.length; i++) {\n let item = items[i];\n item.y += item.vy;\n item.vy += 0.5;\n item.direction += 5;\n if (player.touched(item)) {\n score += scoreTable[item.costumeId];\n item.destroy();\n createSound('e1.mp3');\n if (item.costumeId == 4) {\n clock = 0;\n gameover();\n player.costumeId = 3;\n createSound('e4.mp3');\n }\n }\n }\n}\n\n// 遊戲結束\nfunction gameover() {\n createSprite('timesup.png'); //創造時間暫停圖\n god.costumeId = 0; //切換面向前造型\n player.costumeId = 0; //切換面向前造型\n bgm.pause(); //停止背景音樂\n}\n\nforever(gameloop); // 不斷執行遊戲迴圈","created_at":"2022-08-25T15:05:19.531+08:00","updated_at":"2022-08-25T15:18:42.924+08:00","name":"財神叩叮到(完整版) (3)","language":"javascript","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/428186/5a13869fe2e2db7ac955534de35534ad.jpg"},"parent_id":2,"plugin":"Game.set({width: 1200, height: 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":135,"hashid":"882s4jj6p","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":9621176,"file_name":"bgm.mp3","project_id":428186,"asset_id":558632,"created_at":"2022-08-25T15:05:40.254+08:00","updated_at":"2022-08-25T15:05:40.254+08:00"},{"id":9621177,"file_name":"e4.mp3","project_id":428186,"asset_id":558633,"created_at":"2022-08-25T15:05:40.402+08:00","updated_at":"2022-08-25T15:05:40.402+08:00"},{"id":9621178,"file_name":"e3.mp3","project_id":428186,"asset_id":558634,"created_at":"2022-08-25T15:05:40.410+08:00","updated_at":"2022-08-25T15:05:40.410+08:00"},{"id":9621179,"file_name":"e1.mp3","project_id":428186,"asset_id":558635,"created_at":"2022-08-25T15:05:40.414+08:00","updated_at":"2022-08-25T15:05:40.414+08:00"},{"id":9621180,"file_name":"e2.mp3","project_id":428186,"asset_id":558636,"created_at":"2022-08-25T15:05:40.419+08:00","updated_at":"2022-08-25T15:05:40.419+08:00"},{"id":9621181,"file_name":"item_1.png","project_id":428186,"asset_id":558637,"created_at":"2022-08-25T15:05:40.425+08:00","updated_at":"2022-08-25T15:05:40.425+08:00"},{"id":9621182,"file_name":"item_3.png","project_id":428186,"asset_id":558638,"created_at":"2022-08-25T15:05:40.429+08:00","updated_at":"2022-08-25T15:05:40.429+08:00"},{"id":9621183,"file_name":"god_1.png","project_id":428186,"asset_id":558639,"created_at":"2022-08-25T15:05:40.437+08:00","updated_at":"2022-08-25T15:05:40.437+08:00"},{"id":9621184,"file_name":"p_1.png","project_id":428186,"asset_id":558640,"created_at":"2022-08-25T15:05:40.443+08:00","updated_at":"2022-08-25T15:05:40.443+08:00"},{"id":9621185,"file_name":"timesup.png","project_id":428186,"asset_id":558641,"created_at":"2022-08-25T15:05:40.448+08:00","updated_at":"2022-08-25T15:05:40.448+08:00"},{"id":9621186,"file_name":"item_4.png","project_id":428186,"asset_id":558642,"created_at":"2022-08-25T15:05:40.455+08:00","updated_at":"2022-08-25T15:05:40.455+08:00"},{"id":9621187,"file_name":"item_0.png","project_id":428186,"asset_id":558643,"created_at":"2022-08-25T15:05:40.460+08:00","updated_at":"2022-08-25T15:05:40.460+08:00"},{"id":9621188,"file_name":"item_2.png","project_id":428186,"asset_id":558644,"created_at":"2022-08-25T15:05:40.464+08:00","updated_at":"2022-08-25T15:05:40.464+08:00"},{"id":9621189,"file_name":"god_0.png","project_id":428186,"asset_id":558645,"created_at":"2022-08-25T15:05:40.469+08:00","updated_at":"2022-08-25T15:05:40.469+08:00"},{"id":9621190,"file_name":"god_2.png","project_id":428186,"asset_id":558646,"created_at":"2022-08-25T15:05:40.474+08:00","updated_at":"2022-08-25T15:05:40.474+08:00"},{"id":9621191,"file_name":"devil.png","project_id":428186,"asset_id":558647,"created_at":"2022-08-25T15:05:40.479+08:00","updated_at":"2022-08-25T15:05:40.479+08:00"},{"id":9621192,"file_name":"infoo.png","project_id":428186,"asset_id":558648,"created_at":"2022-08-25T15:05:40.485+08:00","updated_at":"2022-08-25T15:05:40.485+08:00"},{"id":9621193,"file_name":"bg_0.png","project_id":428186,"asset_id":558649,"created_at":"2022-08-25T15:05:40.489+08:00","updated_at":"2022-08-25T15:05:40.489+08:00"},{"id":9621194,"file_name":"bg_1.png","project_id":428186,"asset_id":558650,"created_at":"2022-08-25T15:05:40.493+08:00","updated_at":"2022-08-25T15:05:40.493+08:00"},{"id":9621195,"file_name":"p_3.png","project_id":428186,"asset_id":558651,"created_at":"2022-08-25T15:05:40.499+08:00","updated_at":"2022-08-25T15:05:40.499+08:00"},{"id":9621196,"file_name":"p_2.png","project_id":428186,"asset_id":558652,"created_at":"2022-08-25T15:05:40.503+08:00","updated_at":"2022-08-25T15:05:40.503+08:00"},{"id":9621197,"file_name":"p_0.png","project_id":428186,"asset_id":558653,"created_at":"2022-08-25T15:05:40.520+08:00","updated_at":"2022-08-25T15:05:40.520+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦