{"id":889752,"student_id":2589,"content":"from game import *\n\nset_backdrop('bg.png') #設定背景圖\nstick = create_sprite('stick.png') #中網\nball = create_sprite('ball.png') #球\np1 = create_sprite('p1_0.png', 'p1_1.png', 'p1_2.png', 'p1_3.png') #左邊玩家\np2 = create_sprite('p2_0.png', 'p2_1.png', 'p2_2.png', 'p2_3.png') #右邊玩家\nboard = create_sprite(\"dashboard.png\") #計分板\n\nboard.move_to(150, 50)\nstick.move_to(600, 750)\np1.move_to(300, 750)\np2.move_to(900, 750)\n\nvx = 0 #球的水平速度\nvy = 0 #球的垂直速度\np1_vy = 0 #p1玩家墜落速度\np2_vy = 0 #p2玩家墜落速度\np1_score = 0 #p1玩家分數\np2_score = 0 #p2玩家分數\n\nball.move_to(p1.x, 0)\n\n# p1角色控制與更新\ndef update_p1():\n global p1_vy, vx, vy\n if key.d and p1.x \u003c 500: p1.x += 7\n if key.a and p1.x \u003e 0: p1.x -= 7\n if key.w and p1.y \u003e= 750: p1_vy = -30\n \n p1_vy += 2\n p1.y += p1_vy\n if p1.y \u003e 750: p1.y = 750\n \n if p1.y \u003c 750:\n p1.costume_id = 2\n elif key.s:\n p1.costume_id = 3\n else:\n p1.costume_id = int(p1.x / 50) % 2\n \n if ball.touched(p1):\n vx = ball.x - p1.x\n vy = ball.y - p1.y\n\n\n# p2角色控制與更新\ndef update_p2():\n global p2_vy, vx, vy\n if key.right and p2.x \u003c 1200: p2.x += 7\n if key.left and p2.x \u003e 700: p2.x -= 7\n if key.up and p2.y \u003e= 750: p2_vy = -30\n \n p2.y += p2_vy\n p2_vy += 2\n if p2.y \u003e 750: p2.y = 750\n\n if p2.y \u003c 750:\n p2.costume_id = 2\n elif key.down:\n p2.costume_id = 3\n else:\n p2.costume_id = int(p2.x / 50) % 2\n \n if ball.touched(p2):\n vx = ball.x - p2.x\n vy = ball.y - p2.y\n\n\n\n# 球的碰撞、反彈、玩家得分\ndef update_ball():\n global vy, vx, p1_score, p2_score\n \n ball.x += vx / 6\n ball.y += vy \n ball.direction += vx / 10\n vy += 4\n \n if ball.x \u003c 0 and vx \u003c 0: vx = -vx\n if ball.x \u003e 1200 and vx \u003e 0: vx = -vx\n if ball.y \u003c 0 and vy \u003c 0: vy = -vy\n if ball.y \u003e 900 and vy \u003e 0:\n vx = 0\n vy = 0\n ball.y = 0\n if ball.x \u003c 600:\n ball.x = p2.x\n p2_score += 1\n else:\n ball.x = p1.x\n p1_score += 1\n \n if ball.touched(stick):\n if ball.x \u003e 600 and vx \u003c 0: vx = -vx\n if ball.x \u003c 600 and vx \u003e 0: vx = -vx\n \n# 分數顯示\u0026輸贏判斷\ndef update_score():\n scores = str(p1_score) + ' : ' + str(p2_score)\n draw_text(scores, 70, 30, 'white', 60)\n \nforever(update_p1)\nforever(update_p2)\nforever(update_ball)\nforever(update_score)\n\n","created_at":"2024-11-19T14:55:25.238+08:00","updated_at":"2024-11-19T15:01:51.481+08:00","name":"叩叮打排球(完整版) ","language":"python","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/889752/a2321103d923e5fa800a749a197f6160.jpg"},"parent_id":210507,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":1,"hashid":"rdvsdr6rv","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":34599243,"file_name":"bgm_1.mp3","project_id":889752,"asset_id":291354,"created_at":"2024-11-19T14:55:25.254+08:00","updated_at":"2024-11-19T14:55:25.254+08:00"},{"id":34599244,"file_name":"dashboard.png","project_id":889752,"asset_id":291355,"created_at":"2024-11-19T14:55:25.257+08:00","updated_at":"2024-11-19T14:55:25.257+08:00"},{"id":34599245,"file_name":"stick.png","project_id":889752,"asset_id":291356,"created_at":"2024-11-19T14:55:25.258+08:00","updated_at":"2024-11-19T14:55:25.258+08:00"},{"id":34599246,"file_name":"bg.png","project_id":889752,"asset_id":291365,"created_at":"2024-11-19T14:55:25.260+08:00","updated_at":"2024-11-19T14:55:25.260+08:00"},{"id":34599247,"file_name":"ball.png","project_id":889752,"asset_id":291366,"created_at":"2024-11-19T14:55:25.261+08:00","updated_at":"2024-11-19T14:55:25.261+08:00"},{"id":34599248,"file_name":"bgm_0.mp3","project_id":889752,"asset_id":291367,"created_at":"2024-11-19T14:55:25.262+08:00","updated_at":"2024-11-19T14:55:25.262+08:00"},{"id":34599249,"file_name":"p2_2.png","project_id":889752,"asset_id":793336,"created_at":"2024-11-19T14:55:25.263+08:00","updated_at":"2024-11-19T14:55:25.263+08:00"},{"id":34599250,"file_name":"p2_3.png","project_id":889752,"asset_id":284955,"created_at":"2024-11-19T14:55:25.264+08:00","updated_at":"2024-11-19T14:55:25.264+08:00"},{"id":34599251,"file_name":"p1_0.png","project_id":889752,"asset_id":793331,"created_at":"2024-11-19T14:55:25.265+08:00","updated_at":"2024-11-19T14:55:25.265+08:00"},{"id":34599252,"file_name":"p1_1.png","project_id":889752,"asset_id":793332,"created_at":"2024-11-19T14:55:25.266+08:00","updated_at":"2024-11-19T14:55:25.266+08:00"},{"id":34599253,"file_name":"p2_0.png","project_id":889752,"asset_id":793334,"created_at":"2024-11-19T14:55:25.267+08:00","updated_at":"2024-11-19T14:55:25.267+08:00"},{"id":34599254,"file_name":"p2_1.png","project_id":889752,"asset_id":793335,"created_at":"2024-11-19T14:55:25.267+08:00","updated_at":"2024-11-19T14:55:25.267+08:00"},{"id":34599255,"file_name":"p1_2.png","project_id":889752,"asset_id":793333,"created_at":"2024-11-19T14:55:25.268+08:00","updated_at":"2024-11-19T14:55:25.268+08:00"},{"id":34599256,"file_name":"p1_3.png","project_id":889752,"asset_id":284951,"created_at":"2024-11-19T14:55:25.269+08:00","updated_at":"2024-11-19T14:55:25.269+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦