{"id":485201,"student_id":2589,"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'); //遊戲說明\nlet gamoverInfo = createSprite('gameover.png'); //遊戲結束\n\nlet godVX = 10; //財神水平速度\nlet playerVX = 10; //玩家水平速度\nlet score = 0; //玩家分數\nlet timer = 3600; //遊戲時間\nlet items = []; //存放寶物角色\nlet scoreTable = [1, 5, 10, 30, 0]; //分數對照表\n\ngod.y = 210; //財神初始化在場景上方\nplayer.y = 700; //叩叮初始化在場景下方\n\nplayer.rotationStyle = 'flipped'; //玩家圖片水平翻轉\ngod.rotationStyle = 'flipped'; //財神圖片水平翻轉\n\nlet bgm = createSound('bgm1.mp3'); //背景音樂\n\n//遊戲迴圈\nfunction gameloop () {\n // 遊戲說明隱藏而且遊戲時間還沒到\n if (info.hidden \u0026\u0026 timer \u003e 0) {\n timer--; //剩餘時間減少 1\n updatePlayer(); //更新玩家\n updateGod(); //更新財神\n animation(); //走路動畫\n if (timer == 0) gameover(); //結束遊戲\n if (timer % 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 gamoverInfo.hidden = timer \u003e 0\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(timer / 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; // 30% 機率為寶石\n else if (rand \u003c 0.8) item.costumeId = 2; // 20% 機率為錢袋\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 if (item.y \u003e 1000) continue\n item.y += item.vy;\n item.vy += 0.5;\n item.direction += 3;\n if (item.touched(player)) {\n item.hidden = true;\n score += scoreTable[item.costumeId];\n \n if (item.costumeId == 4) {\n gameover();\n timer = 0;\n player.costumeId = 3;\n createSound('bomb.mp3');\n } else {\n createSound('coin.mp3');\n }\n }\n }\n}\n\n// 遊戲結束\nfunction gameover() {\n god.costumeId = 0; //切換面向前造型\n player.costumeId = 0; //切換面向前造型\n bgm.pause(); //停止背景音樂\n}\n\n// 重新開始\nfunction restart() {\n timer = 3600; //設定 60 秒遊戲時間\n score = 0; //重置分數\n godVX = 10; //起始向右速度\n playerVX = 0; //起始向右速度\n player.x = 600; //重置水平位置\n god.x = 600; //重置水平位置\n bgm.play(); //播放聲音\n items.forEach(item =\u003e item.destroy()); //刪除舊角色\n items = []; //清空陣列\n}\n\ngamoverInfo.on('click', restart); //重新開始\nforever(gameloop); // 不斷執行遊戲迴圈","created_at":"2023-01-16T19:14:20.025+08:00","updated_at":"2024-01-30T14:15:14.892+08:00","name":"財神叩叮到(完整版)","language":"javascript","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/485201/80e04e4340894576f0e1fe709b43acb4.jpg"},"parent_id":485174,"plugin":"Game.set({width: 1200, height: 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":79,"hashid":"5j3s3e48y","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":11042593,"file_name":"item_0.png","project_id":485201,"asset_id":591468,"created_at":"2023-01-16T19:14:20.030+08:00","updated_at":"2023-01-16T19:14:20.030+08:00"},{"id":11042594,"file_name":"god_1.png","project_id":485201,"asset_id":591464,"created_at":"2023-01-16T19:14:20.032+08:00","updated_at":"2023-01-16T19:14:20.032+08:00"},{"id":11042595,"file_name":"p_1.png","project_id":485201,"asset_id":591465,"created_at":"2023-01-16T19:14:20.033+08:00","updated_at":"2023-01-16T19:14:20.033+08:00"},{"id":11042596,"file_name":"bgm1.mp3","project_id":485201,"asset_id":597563,"created_at":"2023-01-16T19:14:20.034+08:00","updated_at":"2023-01-16T19:14:20.034+08:00"},{"id":11042597,"file_name":"gameover.png","project_id":485201,"asset_id":597560,"created_at":"2023-01-16T19:14:20.034+08:00","updated_at":"2023-01-16T19:14:20.034+08:00"},{"id":11042598,"file_name":"item_4.png","project_id":485201,"asset_id":591467,"created_at":"2023-01-16T19:14:20.035+08:00","updated_at":"2023-01-16T19:14:20.035+08:00"},{"id":11042599,"file_name":"bomb.mp3","project_id":485201,"asset_id":591460,"created_at":"2023-01-16T19:14:20.036+08:00","updated_at":"2023-01-16T19:14:20.036+08:00"},{"id":11042600,"file_name":"coin.mp3","project_id":485201,"asset_id":591461,"created_at":"2023-01-16T19:14:20.037+08:00","updated_at":"2023-01-16T19:14:20.037+08:00"},{"id":11042601,"file_name":"item_1.png","project_id":485201,"asset_id":591462,"created_at":"2023-01-16T19:14:20.038+08:00","updated_at":"2023-01-16T19:14:20.038+08:00"},{"id":11042602,"file_name":"item_3.png","project_id":485201,"asset_id":591463,"created_at":"2023-01-16T19:14:20.039+08:00","updated_at":"2023-01-16T19:14:20.039+08:00"},{"id":11042603,"file_name":"item_2.png","project_id":485201,"asset_id":591469,"created_at":"2023-01-16T19:14:20.040+08:00","updated_at":"2023-01-16T19:14:20.040+08:00"},{"id":11042604,"file_name":"god_0.png","project_id":485201,"asset_id":591470,"created_at":"2023-01-16T19:14:20.041+08:00","updated_at":"2023-01-16T19:14:20.041+08:00"},{"id":11042605,"file_name":"god_2.png","project_id":485201,"asset_id":591471,"created_at":"2023-01-16T19:14:20.042+08:00","updated_at":"2023-01-16T19:14:20.042+08:00"},{"id":11042606,"file_name":"devil.png","project_id":485201,"asset_id":591472,"created_at":"2023-01-16T19:14:20.043+08:00","updated_at":"2023-01-16T19:14:20.043+08:00"},{"id":11042607,"file_name":"infoo.png","project_id":485201,"asset_id":591473,"created_at":"2023-01-16T19:14:20.044+08:00","updated_at":"2023-01-16T19:14:20.044+08:00"},{"id":11042608,"file_name":"bg_0.png","project_id":485201,"asset_id":591474,"created_at":"2023-01-16T19:14:20.045+08:00","updated_at":"2023-01-16T19:14:20.045+08:00"},{"id":11042609,"file_name":"bg_1.png","project_id":485201,"asset_id":591475,"created_at":"2023-01-16T19:14:20.046+08:00","updated_at":"2023-01-16T19:14:20.046+08:00"},{"id":11042610,"file_name":"p_3.png","project_id":485201,"asset_id":591476,"created_at":"2023-01-16T19:14:20.047+08:00","updated_at":"2023-01-16T19:14:20.047+08:00"},{"id":11042611,"file_name":"p_2.png","project_id":485201,"asset_id":591477,"created_at":"2023-01-16T19:14:20.048+08:00","updated_at":"2023-01-16T19:14:20.048+08:00"},{"id":11042612,"file_name":"p_0.png","project_id":485201,"asset_id":591478,"created_at":"2023-01-16T19:14:20.048+08:00","updated_at":"2023-01-16T19:14:20.048+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦