{"id":196930,"student_id":2589,"content":"","created_at":"2020-10-19T16:57:26.645+08:00","updated_at":"2023-03-14T14:38:53.424+08:00","name":"彈力球大戰 - 開始後用滑鼠點擊舞台以啟用按鍵,重整畫面即可重新遊戲。","language":"python","screenshot":{"url":null},"parent_id":4,"plugin":"game.set({'width': 1200, 'height': 900})\n\nimport math #載入數學工具包\nimport random #載入產生隨機數的模組\n\nsetBackdrop('bg.jpg') #設定背景圖\nball = createSprite( 'ball_0.png', 'ball_1.png') #球\np1 = createSprite('p1.png') #左邊玩家擋板\np2 = createSprite('p2.png') #右邊玩家擋板\ninfo = createSprite('info.png', 'bg_1.jpg', 'bg_2.jpg') #遊戲開始、結束提示圖\n\np1.x = 30\np2.x = 1170\nball.rotationStyle = 'fixed' #球的圖片永遠保持水平,不會隨著角度改變而旋轉\n# info.hidden = True\n\np1_score = 0 #左邊玩家分數\np2_score = 0 #右邊玩家分數\nspeed = 10 #球的速度\n \ncreateSound('bgm.mp3', True)\n\n#遊戲主迴圈\ndef loop ():\n global p1_score, p2_score, speed\n \n if key.o and p2.y \u003e 120:\n p2.y -= 20\n \n if key.l and p2.y \u003c 780:\n p2.y += 20\n \n if key.w and p1.y \u003e 120:\n p1.y -= 20\n \n if key.s and p1.y \u003c 780:\n p1.y += 20\n\n #如果開始示意圖隱藏時表示遊戲開始,球才可以開始移動\n if info.hidden:\n ball.stepForward(speed)\n \n if key.space: #按下空白按鍵隱藏開始示意圖\n info.hidden = True\n \n if ball.y \u003c 0 or ball.y \u003e 900:\n ball.direction = -ball.direction - 180\n \n if ball.touched(p2) and ball.direction \u003c 180:\n ball.direction = -ball.direction + random.random()*15\n speed += 1\n createSound('hit.mp3')\n \n if ball.touched(p1) and ball.direction \u003e 180:\n ball.direction = -ball.direction + random.random()*15\n speed += 1\n createSound('hit.mp3')\n \n #左邊玩家得分\n if ball.x \u003c 0:\n ball.moveTo(600, 450)\n ball.direction = 270\n speed = 10\n p1_score += 1\n createSound('lose.ogg')\n \n #右邊玩家得分\n if ball.x \u003e 1200:\n ball.moveTo(600, 450)\n ball.direction = 90\n speed = 10\n p2_score += 1\n createSound('lose.ogg')\n \n\n drawText(p1_score, 1140, 20, '#23B0DB', 80)\n drawText(p2_score, 30, 20, '#F46F25', 80)\n\n #左邊玩家獲勝\n if p1_score == 5:\n info.costumeId = 1\n info.hidden = False\n stop()\n \n #右邊玩家獲勝\n if p2_score == 5:\n info.costumeId = 2\n info.hidden = False\n stop()\n \n if speed \u003c 15:\n ball.costumeId = 0\n else:\n ball.costumeId = 1\n\n\nforever(loop) #重複不斷執行遊戲迴圈","description":null,"note":null,"status":"public","like_student_ids":[12141,11901,13868,13032,12215,11799,13943,8417,15249,12736,23805,9874,10439,18108,27631,9254,21138,12466,20767,16672,22222,11645,5135,15101,23949,16968,26955,45732,30022,17119,12003,16209,10801,26482,26650,21076,34617,33563,47495,22355,24143,26704,9899,37235,54059,39398,20758,38994,18345,37763,40231,42999,37770,35917,41868,33676,42279,46547,45534,42070,40009,61577,48039,38877,19053,43021,66952,42184],"is_featured":false,"views":2752,"hashid":"vngsywv8d","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3377955,"file_name":"p2.png","project_id":196930,"asset_id":270862,"created_at":"2020-10-19T16:57:43.790+08:00","updated_at":"2020-10-19T16:57:43.790+08:00"},{"id":3377956,"file_name":"ball_1.png","project_id":196930,"asset_id":270863,"created_at":"2020-10-19T16:57:43.796+08:00","updated_at":"2020-10-19T16:57:43.796+08:00"},{"id":3377957,"file_name":"bg.jpg","project_id":196930,"asset_id":270864,"created_at":"2020-10-19T16:57:43.805+08:00","updated_at":"2020-10-19T16:57:43.805+08:00"},{"id":3377958,"file_name":"hit.mp3","project_id":196930,"asset_id":270865,"created_at":"2020-10-19T16:57:43.810+08:00","updated_at":"2020-10-19T16:57:43.810+08:00"},{"id":3377959,"file_name":"lose.ogg","project_id":196930,"asset_id":270866,"created_at":"2020-10-19T16:57:43.815+08:00","updated_at":"2020-10-19T16:57:43.815+08:00"},{"id":3377960,"file_name":"bg_1.jpg","project_id":196930,"asset_id":270867,"created_at":"2020-10-19T16:57:43.825+08:00","updated_at":"2020-10-19T16:57:43.825+08:00"},{"id":3377961,"file_name":"p1.png","project_id":196930,"asset_id":270868,"created_at":"2020-10-19T16:57:43.830+08:00","updated_at":"2020-10-19T16:57:43.830+08:00"},{"id":3377962,"file_name":"info.png","project_id":196930,"asset_id":270869,"created_at":"2020-10-19T16:57:43.835+08:00","updated_at":"2020-10-19T16:57:43.835+08:00"},{"id":3377963,"file_name":"bgm.mp3","project_id":196930,"asset_id":270870,"created_at":"2020-10-19T16:57:43.995+08:00","updated_at":"2020-10-19T16:57:43.995+08:00"},{"id":3377964,"file_name":"bg_2.jpg","project_id":196930,"asset_id":270871,"created_at":"2020-10-19T16:57:44.013+08:00","updated_at":"2020-10-19T16:57:44.013+08:00"},{"id":3377965,"file_name":"ball_3.png","project_id":196930,"asset_id":270872,"created_at":"2020-10-19T16:57:44.018+08:00","updated_at":"2020-10-19T16:57:44.018+08:00"},{"id":3377966,"file_name":"ball_0.png","project_id":196930,"asset_id":270873,"created_at":"2020-10-19T16:57:44.023+08:00","updated_at":"2020-10-19T16:57:44.023+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦