{"id":697377,"student_id":10,"content":"window.dispatchEvent(new Event('resize'));\n\nlet 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('info.png', 'win.png', 'gameover.png'); //遊戲說明\n// let gamoverInfo = createSprite('gameover.png'); //遊戲結束\n\nlet godVX = 10; //財神水平速度\nlet playerVX = 10; //玩家水平速度\nlet score = 0; //玩家分數\nlet timer = 3600; //遊戲時間\nlet items = []; //存放寶物角色\n\n// let isGameOver = false;\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) {\n gameover(1); //結束遊戲\n info.costumeId = 1;\n }\n if (timer % 20 == 0) createItems();\n devil.y += 1;\n }\n updateItems(); //更新物件\n \n if (info.hidden || info.costumeId != 0) {\n drawTexts(); //顯示時間分數 \n }\n\n // 按下右鍵或左鍵\n if (key.right || key.left) {\n if (info.costumeId === 0 \u0026\u0026 !info.hidden) {\n info.hidden = true\n }\n }\n \n // gamoverInfo.hidden = timer \u003e 0\n}\n\n// 玩家移動\nfunction updatePlayer () {\n player.x += playerVX; // 根據 playerVX 改變水平位置\n if (player.x \u003e 1200) player.x = 1200;\n if (player.x \u003c 0) player.x = 0;\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_3.png', 'item_4.png', 'item_5.png', 'item_6.png', 'item_7.png', 'item_8.png', 'item_9.png', 'item_11.png');\n item.moveTo(god); //將寶物移動到財神爺位置\n item.costumeId = Math.floor(Math.random() * 10); //隨機切換造型\n if (item.costumeId \u003e= 8) {\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.scale = 0.2;\n item.direction += 3;\n if (item.touched(player)) {\n item.hidden = true;\n score += 1\n if (item.costumeId \u003e= 8) {\n gameover(2);\n timer = 0;\n info.costumeId = 2;\n player.costumeId = 3;\n createSound('bomb.mp3');\n } else {\n createSound('coin.mp3');\n }\n }\n }\n}\n\n// 遊戲結束\nfunction gameover(costumeId = 1) {\n info.costumeId = costumeId;\n info.hidden = false;\n god.costumeId = 0; //切換面向前造型\n player.costumeId = 0; //切換面向前造型\n bgm.pause(); //停止背景音樂\n}\n\n// 重新開始\nfunction onClick() {\n if (info.costumeId !== 0) {\n window.top.postMessage({ event: 'SET_SCORE', data: { score } }, \"*\")\n stop();\n }\n}\n\ninfo.on('click', onClick); //重新開始\nforever(gameloop); // 不斷執行遊戲迴圈","created_at":"2024-02-23T10:19:19.192+08:00","updated_at":"2024-03-19T11:51:10.505+08:00","name":"需要與想要的財神挑戰","language":"javascript","screenshot":{"url":"https://cdn5.koding.school/uploads/project/screenshot/697377/43ed91ec89dadc0689d0ff4062ed1011.jpg"},"parent_id":428186,"plugin":"Game.set({width: 1200, height: 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":59,"hashid":"9ygs5edg9","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":15702030,"file_name":"god_1.png","project_id":697377,"asset_id":723437,"created_at":"2024-02-25T23:08:00.765+08:00","updated_at":"2024-02-25T23:08:00.765+08:00"},{"id":15702031,"file_name":"p_1.png","project_id":697377,"asset_id":723438,"created_at":"2024-02-25T23:08:00.769+08:00","updated_at":"2024-02-25T23:08:00.769+08:00"},{"id":15702032,"file_name":"bgm1.mp3","project_id":697377,"asset_id":723439,"created_at":"2024-02-25T23:08:00.790+08:00","updated_at":"2024-02-25T23:08:00.790+08:00"},{"id":15702035,"file_name":"bomb.mp3","project_id":697377,"asset_id":723442,"created_at":"2024-02-25T23:08:00.804+08:00","updated_at":"2024-02-25T23:08:00.804+08:00"},{"id":15702036,"file_name":"coin.mp3","project_id":697377,"asset_id":723443,"created_at":"2024-02-25T23:08:00.808+08:00","updated_at":"2024-02-25T23:08:00.808+08:00"},{"id":15702040,"file_name":"god_0.png","project_id":697377,"asset_id":723447,"created_at":"2024-02-25T23:08:00.889+08:00","updated_at":"2024-02-25T23:08:00.889+08:00"},{"id":15702041,"file_name":"god_2.png","project_id":697377,"asset_id":723448,"created_at":"2024-02-25T23:08:00.893+08:00","updated_at":"2024-02-25T23:08:00.893+08:00"},{"id":15702042,"file_name":"devil.png","project_id":697377,"asset_id":723449,"created_at":"2024-02-25T23:08:00.897+08:00","updated_at":"2024-02-25T23:08:00.897+08:00"},{"id":15702044,"file_name":"bg_0.png","project_id":697377,"asset_id":723451,"created_at":"2024-02-25T23:08:00.905+08:00","updated_at":"2024-02-25T23:08:00.905+08:00"},{"id":15702045,"file_name":"bg_1.png","project_id":697377,"asset_id":723452,"created_at":"2024-02-25T23:08:00.909+08:00","updated_at":"2024-02-25T23:08:00.909+08:00"},{"id":15702046,"file_name":"p_3.png","project_id":697377,"asset_id":723453,"created_at":"2024-02-25T23:08:00.913+08:00","updated_at":"2024-02-25T23:08:00.913+08:00"},{"id":15702047,"file_name":"p_2.png","project_id":697377,"asset_id":723454,"created_at":"2024-02-25T23:08:00.917+08:00","updated_at":"2024-02-25T23:08:00.917+08:00"},{"id":15702048,"file_name":"p_0.png","project_id":697377,"asset_id":723455,"created_at":"2024-02-25T23:08:00.921+08:00","updated_at":"2024-02-25T23:08:00.921+08:00"},{"id":15702053,"file_name":"item_3.png","project_id":697377,"asset_id":723459,"created_at":"2024-02-25T23:10:37.177+08:00","updated_at":"2024-02-25T23:10:37.177+08:00"},{"id":15702054,"file_name":"item_4.png","project_id":697377,"asset_id":723460,"created_at":"2024-02-25T23:10:37.178+08:00","updated_at":"2024-02-25T23:10:37.178+08:00"},{"id":15702051,"file_name":"item_1.png","project_id":697377,"asset_id":723457,"created_at":"2024-02-25T23:10:36.562+08:00","updated_at":"2024-02-25T23:10:36.562+08:00"},{"id":15702052,"file_name":"item_2.png","project_id":697377,"asset_id":723458,"created_at":"2024-02-25T23:10:36.564+08:00","updated_at":"2024-02-25T23:10:36.564+08:00"},{"id":15702059,"file_name":"item_9.png","project_id":697377,"asset_id":723465,"created_at":"2024-02-25T23:10:38.721+08:00","updated_at":"2024-02-25T23:10:38.721+08:00"},{"id":15702060,"file_name":"item_10.png","project_id":697377,"asset_id":723466,"created_at":"2024-02-25T23:10:38.723+08:00","updated_at":"2024-02-25T23:10:38.723+08:00"},{"id":15702050,"file_name":"item_0.png","project_id":697377,"asset_id":723456,"created_at":"2024-02-25T23:10:36.088+08:00","updated_at":"2024-02-25T23:10:36.088+08:00"},{"id":15702055,"file_name":"item_5.png","project_id":697377,"asset_id":723461,"created_at":"2024-02-25T23:10:37.791+08:00","updated_at":"2024-02-25T23:10:37.791+08:00"},{"id":15702056,"file_name":"item_6.png","project_id":697377,"asset_id":723462,"created_at":"2024-02-25T23:10:37.793+08:00","updated_at":"2024-02-25T23:10:37.793+08:00"},{"id":15702061,"file_name":"item_11.png","project_id":697377,"asset_id":723467,"created_at":"2024-02-25T23:10:39.129+08:00","updated_at":"2024-02-25T23:10:39.129+08:00"},{"id":15702057,"file_name":"item_7.png","project_id":697377,"asset_id":723463,"created_at":"2024-02-25T23:10:38.302+08:00","updated_at":"2024-02-25T23:10:38.302+08:00"},{"id":15702058,"file_name":"item_8.png","project_id":697377,"asset_id":723464,"created_at":"2024-02-25T23:10:38.303+08:00","updated_at":"2024-02-25T23:10:38.303+08:00"},{"id":15820178,"file_name":"win.png","project_id":697377,"asset_id":725052,"created_at":"2024-03-07T10:07:12.548+08:00","updated_at":"2024-03-07T10:07:12.548+08:00"},{"id":15820179,"file_name":"gameover.png","project_id":697377,"asset_id":725051,"created_at":"2024-03-07T10:20:02.675+08:00","updated_at":"2024-03-07T10:20:02.675+08:00"},{"id":15926448,"file_name":"info.png","project_id":697377,"asset_id":726544,"created_at":"2024-03-15T11:06:18.852+08:00","updated_at":"2024-03-15T11:06:18.852+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦