{"id":168972,"student_id":3232,"content":"import game\nimport random #載入產生隨機數的套件\n\n# 建立角色及初始化設定\nbg = game.create_sprite(\"bg.jpg\")\np1 = game.create_sprite(\"p1.png\")\np2 = game.create_sprite(\"p2.png\")\nball = game.create_sprite(\"ball_1.png\")\nbgm = game.create_sound(\"bgm.mp3\")\n\n\ninfo = game.create_sprite(\"info.png\", \"bg_1.jpg\", \"bg_2.jpg\") #創造角色\np1.x = 30\np1.y = 450\np2.x = 1170\np2.y = 450\nball.x = 600\nball.y = 450\na = -1\n# ball.rotationStyle = 'fixed'\n #球的圖片永遠保持水平,不會隨著角度改變而旋轉\n\np1_score = 0 #左邊玩家分數\np2_score = 0 #右邊玩家分數\nspeed = 10 #球的速度\nstart = 0\n#遊戲主迴圈\ndef loop ():\n global p1_score, p2_score, speed, start, a\n hit = game.create_sound(\"hit.mp3\")\n lose = game.create_sound(\"lose.ogg\")\n hit.mute(True)\n lose.mute(True)\n # 擋板移動\n if p1.y \u003e 0 and key.w:\n p1.y -= 20\n if p1.y \u003c 900 and key.s:\n p1.y += 20\n if p2.y \u003e 0 and key.o:\n p2.y -= 20\n if p2.y \u003c 900 and key.l:\n p2.y += 20 \n # 遊戲開始\n if key.space:\n info.hidden = True\n start = 1\n if start == 1:\n ball.step_forward(speed)\n # 球碰到擋板\n if a == 1:\n if ball.touched(p1):\n hit.mute(False)\n ball.direction *= -1\n speed += 1\n ball.direction += random.randint(0, 15)\n a *= -1\n if a == -1:\n if ball.touched(p2):\n hit.mute(False)\n ball.direction *= -1\n speed += 1\n ball.direction += random.randint(0, 15)\n a *= -1 \n \n # 球碰到上下邊界\n if ball.y \u003c 60 or ball.y \u003e 840:\n ball.direction = (ball.direction * -1) + 180\n # 玩家得分\n if ball.x \u003e 1200 or ball.x \u003c 0:\n if ball.x \u003e 1200:\n ball.direction = 90\n p1_score += 1\n lose.mute(False)\n a = -1\n else:\n ball.direction = 270\n p2_score += 1\n lose.mute(False)\n a = 1\n speed = 10\n ball.x = 600\n ball.y = 450\n \n \n \n # 顯示分數\n game.draw_text(p1_score, 30, 20, \"#ff9d00\", 90)\n game.draw_text(p2_score, 1140, 20, \"#17a2ff\", 90)\n # 遊戲結束\n if p1_score == 5:\n info.costume_id = 2\n info.hidden = False\n game.stop()\n if p2_score == 5:\n info.costume_id = 1\n info.hidden = False\n game.stop()\n \ngame.forever(loop) #重複不斷執行遊戲迴圈","created_at":"2020-07-21T13:04:41.187+08:00","updated_at":"2020-07-21T17:13:22.707+08:00","name":"彈力球大賽_S 副本","language":"python","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/168972/c428f59cdba555a6a2651e07e06edb63.jpg"},"parent_id":162874,"plugin":"game.set({'width': 1200, 'height': 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":41,"hashid":"6rpspdqe","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2923171,"file_name":"bg_2.jpg","project_id":168972,"asset_id":197996,"created_at":"2020-07-21T13:04:41.192+08:00","updated_at":"2020-07-21T13:04:41.192+08:00"},{"id":2923172,"file_name":"bgm.mp3","project_id":168972,"asset_id":172560,"created_at":"2020-07-21T13:04:41.193+08:00","updated_at":"2020-07-21T13:04:41.193+08:00"},{"id":2923173,"file_name":"info.png","project_id":168972,"asset_id":197997,"created_at":"2020-07-21T13:04:41.194+08:00","updated_at":"2020-07-21T13:04:41.194+08:00"},{"id":2923174,"file_name":"p1.png","project_id":168972,"asset_id":197969,"created_at":"2020-07-21T13:04:41.195+08:00","updated_at":"2020-07-21T13:04:41.195+08:00"},{"id":2923175,"file_name":"bg_1.jpg","project_id":168972,"asset_id":197995,"created_at":"2020-07-21T13:04:41.196+08:00","updated_at":"2020-07-21T13:04:41.196+08:00"},{"id":2923176,"file_name":"lose.ogg","project_id":168972,"asset_id":192734,"created_at":"2020-07-21T13:04:41.197+08:00","updated_at":"2020-07-21T13:04:41.197+08:00"},{"id":2923177,"file_name":"hit.mp3","project_id":168972,"asset_id":17858,"created_at":"2020-07-21T13:04:41.198+08:00","updated_at":"2020-07-21T13:04:41.198+08:00"},{"id":2923178,"file_name":"bg.jpg","project_id":168972,"asset_id":197970,"created_at":"2020-07-21T13:04:41.199+08:00","updated_at":"2020-07-21T13:04:41.199+08:00"},{"id":2923179,"file_name":"ball_1.png","project_id":168972,"asset_id":198067,"created_at":"2020-07-21T13:04:41.200+08:00","updated_at":"2020-07-21T13:04:41.200+08:00"},{"id":2923180,"file_name":"p2.png","project_id":168972,"asset_id":197971,"created_at":"2020-07-21T13:04:41.201+08:00","updated_at":"2020-07-21T13:04:41.201+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦