{"id":163273,"student_id":1404,"content":"import random #載入產生隨機數的套件\nimport game\n\n# 建立角色及初始化設定\ngame.setBackdrop('bg.jpg') #設定背景圖\nball = game.create_sprite('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') #遊戲開始、結束提示圖\ncreateSound('bgm.mp3')\n\n# ball.rotationStyle = 'fixed' #球的圖片永遠保持水平,不會隨著角度改變而旋轉\np1.x, p1.y = 30, 450\np2.x, p2.y = 1170, 450\nball.x, ball.y = 600, 450\n# ball.direction = 45\np1_score = 0 #左邊玩家分數\np2_score = 0 #右邊玩家分數\nspeed = 10 #球的速度\n\n#遊戲主迴圈\ndef loop ():\n global p1_score, p2_score, speed\n \n # 擋板移動\n if key.o and p2.y \u003e 0:\n p2.y = p2.y - 20\n \n if key.l and p2.y \u003c 900:\n p2.y = p2.y + 20\n \n if key.w and p1.y \u003e 0:\n p1.y = p1.y - 20\n \n if key.s and p1.y \u003c 900:\n p1.y = p1.y + 20\n # 遊戲開始\n if key.space:\n info.hidden = True\n \n if info.hidden == True:\n ball.step_forward(speed);\n # 球碰到擋板\n if (ball.touched(p1) and ball.direction\u003e180) or (ball.touched(p2) and ball.direction \u003c 180):\n ball.direction = -ball.direction + random.randint(0, 15)\n game.create_sound('hit.mp3')\n \n # 球碰到上下邊界\n if ball.y \u003c 0 or ball.y \u003e 900:\n ball.direction = -ball.direction + 180\n \n # 玩家得分\n if ball.x \u003e 1200:\n p1_score = p1_score + 1\n game.create_sound('lose.ogg')\n ball.move_to(600 , 450)\n if ball.x \u003c 0:\n p2_score = p2_score + 1\n game.create_sound('lose.ogg')\n ball.move_to(600 , 450)\n \n # 顯示分數\n game.drawText(p1_score, 30, 20, 'white', 80)\n game.drawText(p2_score, 1140, 20, 'white', 80)\n \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 \nforever(loop) #重複不斷執行遊戲迴圈\n\n\n\n# import random #載入產生隨機數的套件\n\n# setBackdrop('bg.jpg') #設定背景圖\n# ball = createSprite('ball_1.png') #球\n# p1 = createSprite('p1.png') #左邊玩家擋板\n# p2 = createSprite('p2.png') #右邊玩家擋板\n# info = createSprite('info.png', 'bg_1.jpg', 'bg_2.jpg') #遊戲開始、結束提示圖\n# createSound('bgm.mp3')\n\n# p1.x = 30\n# p1.y = 450\n# p2.x = 1170\n# p2.y = 450\n# ball.x = 600\n# ball.y = 450\n\n# # ball.rotationStyle = 'fixed' #球的圖片永遠保持水平,不會隨著角度改變而旋轉\n\n# p1_score = 0 #左邊玩家分數\n# p2_score = 0 #右邊玩家分數\n# speed = 10 #球的速度\n\n# #遊戲主迴圈\n# def loop ():\n# global p1_score, p2_score, speed\n# if key.o and p2.y \u003e 0:\n# p2.y -= 20\n \n# if key.l and p2.y \u003c 900:\n# p2.y += 20\n \n# if key.w and p1.y \u003e 0:\n# p1.y -= 20\n \n# if key.s and p1.y \u003c 900:\n# p1.y += 20\n\n# if key.space:\n# info.hidden = True\n\n# if info.hidden:\n# ball.stepForward(speed)\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.x = 600\n# ball.y = 450\n# ball.direction = 270\n# p1_score += 1\n# speed = 10\n# createSound('lose.ogg')\n \n# #右邊玩家得分\n# if ball.x \u003e 1200:\n# ball.moveTo(600, 450)\n# ball.direction = 90\n# p2_score += 1\n# speed = 10\n# createSound('lose.ogg')\n \n \n# drawText(p1_score, 1140, 20, 'white', 80)\n# drawText(p2_score, 30, 20, 'white', 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# forever(loop) #重複不斷執行遊戲迴圈","created_at":"2020-07-09T11:22:15.639+08:00","updated_at":"2020-07-21T16:53:18.146+08:00","name":"彈力球大賽_S 副本","language":"python","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/163273/8b6324f9cb2c44c2dfadc4ab2d52dc2a.jpg"},"parent_id":162874,"plugin":"game.set({'width': 1200, 'height': 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":78,"hashid":"36ys89jv","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2836590,"file_name":"bg_2.jpg","project_id":163273,"asset_id":197996,"created_at":"2020-07-09T11:22:15.644+08:00","updated_at":"2020-07-09T11:22:15.644+08:00"},{"id":2836591,"file_name":"bgm.mp3","project_id":163273,"asset_id":172560,"created_at":"2020-07-09T11:22:15.645+08:00","updated_at":"2020-07-09T11:22:15.645+08:00"},{"id":2836592,"file_name":"info.png","project_id":163273,"asset_id":197997,"created_at":"2020-07-09T11:22:15.646+08:00","updated_at":"2020-07-09T11:22:15.646+08:00"},{"id":2836593,"file_name":"p1.png","project_id":163273,"asset_id":197969,"created_at":"2020-07-09T11:22:15.647+08:00","updated_at":"2020-07-09T11:22:15.647+08:00"},{"id":2836594,"file_name":"bg_1.jpg","project_id":163273,"asset_id":197995,"created_at":"2020-07-09T11:22:15.648+08:00","updated_at":"2020-07-09T11:22:15.648+08:00"},{"id":2836595,"file_name":"lose.ogg","project_id":163273,"asset_id":192734,"created_at":"2020-07-09T11:22:15.649+08:00","updated_at":"2020-07-09T11:22:15.649+08:00"},{"id":2836596,"file_name":"hit.mp3","project_id":163273,"asset_id":17858,"created_at":"2020-07-09T11:22:15.650+08:00","updated_at":"2020-07-09T11:22:15.650+08:00"},{"id":2836597,"file_name":"bg.jpg","project_id":163273,"asset_id":197970,"created_at":"2020-07-09T11:22:15.650+08:00","updated_at":"2020-07-09T11:22:15.650+08:00"},{"id":2836598,"file_name":"ball_1.png","project_id":163273,"asset_id":198067,"created_at":"2020-07-09T11:22:15.651+08:00","updated_at":"2020-07-09T11:22:15.651+08:00"},{"id":2836599,"file_name":"p2.png","project_id":163273,"asset_id":197971,"created_at":"2020-07-09T11:22:15.652+08:00","updated_at":"2020-07-09T11:22:15.652+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦