{"id":150127,"student_id":10,"content":"import game #載入遊戲框架\nimport random #載入產生隨機數的模組\n\ngame.set_backdrop('bg.jpg') #設定背景圖\nball = game.create_sprite( 'ball_0.png', 'ball_1.png') #球\np1 = game.create_sprite('p1.png') #左邊玩家擋板\np2 = game.create_sprite('p2.png') #右邊玩家擋板\ninfo = game.create_sprite('info.png', 'bg_1.jpg', 'bg_2.jpg') #遊戲開始、結束提示圖\n\np1.x = 30\np2.x = 1170\nball.rotation_style = 'fixed' #球的圖片永遠保持水平,不會隨著角度改變而旋轉\n# info.hidden = True\n\np1_score = 0 #左邊玩家分數\np2_score = 0 #右邊玩家分數\nspeed = 10 #球的速度\n \ngame.create_sound('bgm.mp3', True)\n\n#遊戲主迴圈\ndef loop ():\n global p1_score, p2_score, speed\n \n if game.key.o and p2.y \u003e 120:\n p2.y -= 20\n \n if game.key.l and p2.y \u003c 780:\n p2.y += 20\n \n if game.key.w and p1.y \u003e 120:\n p1.y -= 20\n \n if game.key.s and p1.y \u003c 780:\n p1.y += 20\n\n #如果開始示意圖隱藏時表示遊戲開始,球才可以開始移動\n if info.hidden:\n ball.step_forward(speed)\n \n if key.space: #按下空白按鍵隱藏開始示意圖\n info.hidden = True\n \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.randrange(15)\n speed += 1\n game.create_sound('hit.mp3')\n \n if ball.touched(p1) and ball.direction \u003e 180:\n ball.direction = -ball.direction + random.randrange(15)\n speed += 1\n game.create_sound('hit.mp3')\n \n #左邊玩家得分\n if ball.x \u003c 0:\n ball.move_to(600, 450)\n ball.direction = 270 #朝向左邊發球\n speed = 10\n p1_score += 1\n game.create_sound('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 game.create_sound('lose.ogg')\n\n game.draw_text(p1_score, 1140, 20, '#23B0DB', 80)\n game.draw_text(p2_score, 30, 20, '#F46F25', 80)\n\n #左邊玩家獲勝\n if p1_score == 5:\n info.costume_id = 1\n info.hidden = False\n game.stop()\n \n #右邊玩家獲勝\n if p2_score == 5:\n info.costume_id = 2\n info.hidden = False\n game.stop()\n \n if speed \u003c 15:\n ball.costume_id = 0\n else:\n ball.costume_id = 1\n\n\ngame.forever(loop) #重複不斷執行遊戲迴圈","created_at":"2020-05-20T19:53:47.209+08:00","updated_at":"2020-08-19T11:48:02.886+08:00","name":"彈力球大賽(完整版)","language":"python","screenshot":{"url":"https://cdn8.koding.school/uploads/project/screenshot/150127/e4605a7bf0759c31f4531175b276596c.jpg"},"parent_id":148147,"plugin":"game.set({'width': 1200, 'height': 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":285,"hashid":"kdms2y9q","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2605818,"file_name":"p2.png","project_id":150127,"asset_id":197971,"created_at":"2020-05-20T19:53:47.214+08:00","updated_at":"2020-05-20T19:53:47.214+08:00"},{"id":2605819,"file_name":"ball_1.png","project_id":150127,"asset_id":198067,"created_at":"2020-05-20T19:53:47.216+08:00","updated_at":"2020-05-20T19:53:47.216+08:00"},{"id":2605820,"file_name":"bg.jpg","project_id":150127,"asset_id":197970,"created_at":"2020-05-20T19:53:47.217+08:00","updated_at":"2020-05-20T19:53:47.217+08:00"},{"id":2605821,"file_name":"hit.mp3","project_id":150127,"asset_id":17858,"created_at":"2020-05-20T19:53:47.218+08:00","updated_at":"2020-05-20T19:53:47.218+08:00"},{"id":2605822,"file_name":"lose.ogg","project_id":150127,"asset_id":192734,"created_at":"2020-05-20T19:53:47.220+08:00","updated_at":"2020-05-20T19:53:47.220+08:00"},{"id":2605823,"file_name":"bg_1.jpg","project_id":150127,"asset_id":197995,"created_at":"2020-05-20T19:53:47.221+08:00","updated_at":"2020-05-20T19:53:47.221+08:00"},{"id":2605824,"file_name":"p1.png","project_id":150127,"asset_id":197969,"created_at":"2020-05-20T19:53:47.222+08:00","updated_at":"2020-05-20T19:53:47.222+08:00"},{"id":2605825,"file_name":"info.png","project_id":150127,"asset_id":197997,"created_at":"2020-05-20T19:53:47.223+08:00","updated_at":"2020-05-20T19:53:47.223+08:00"},{"id":2605826,"file_name":"bgm.mp3","project_id":150127,"asset_id":172560,"created_at":"2020-05-20T19:53:47.224+08:00","updated_at":"2020-05-20T19:53:47.224+08:00"},{"id":2605827,"file_name":"bg_2.jpg","project_id":150127,"asset_id":197996,"created_at":"2020-05-20T19:53:47.227+08:00","updated_at":"2020-05-20T19:53:47.227+08:00"},{"id":2605828,"file_name":"ball_3.png","project_id":150127,"asset_id":198068,"created_at":"2020-05-20T19:53:47.228+08:00","updated_at":"2020-05-20T19:53:47.228+08:00"},{"id":2605829,"file_name":"ball_0.png","project_id":150127,"asset_id":197998,"created_at":"2020-05-20T19:53:47.229+08:00","updated_at":"2020-05-20T19:53:47.229+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦