{"id":280093,"student_id":1981,"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\n\n\nspeed = 10 #球的速度\np1_score = 0 #左邊玩家分數\np2_score = 0 #右邊玩家分數\n\ngame.create_sound(\"bgm.mp3\", True)\n\n\n#遊戲主迴圈\ndef loop ():\n global p1_score, p2_score, speed\n \n #上下移動左邊檔板\n if game.key.w == True and p1.y \u003e0:\n p1.y -= 20\n \n if game.key.s == True and p1.y \u003c900:\n p1.y += 20\n \n #上下移動右邊檔板\n if game.key.o == True and p2.y \u003e 0:\n p2.y -= 20\n \n if game.key.l == True and p2.y \u003c900:\n p2.y += 20\n \n \n if info.hidden == True:#讓球不斷向前移動\n ball.step_forward(speed) #讓球向前移動10步\n \n # #左右檔板反彈\n # if ball.touched(p1) or ball.touched(p2):\n # ball.direction = ball.direction * -1 + random.randrange(0,15)\n # speed = speed +1\n \n if ball.touched(p1) and ball.direction \u003e 180:\n ball.direction = ball.direction * -1 + random.randrange(0,15)\n speed = speed +1\n game.create_sound(\"hit.mp3\")\n \n if ball.touched(p2) and ball.direction \u003c 180:\n ball.direction = ball.direction * -1 + random.randrange(0,15)\n speed = speed +1\n game.create_sound(\"hit.mp3\")\n \n #上下邊界反彈\n if ball.y \u003c 50 or ball.y \u003e 850:\n ball.direction = ball.direction * -1 + 180\n \n \n #超過左右,從新開始\n if ball.x \u003c 0:\n ball.move_to(600,450)\n ball.direction = 90\n speed = 10\n p2_score += 1\n game.create_sound(\"\tlose.ogg\")\n \n \n if ball.x \u003e 1200:\n ball.move_to(600,450)\n ball.direction = 270\n speed = 10\n p1_score += 1\n game.create_sound(\"\tlose.ogg\")\n \n #分數到5分,遊戲暫停/換背景\n if p1_score == 5:\n game.stop()\n info.hidden = False\n info.costume_id = 2\n \n if p2_score == 5:\n game.stop()\n info.hidden = False\n info.costume_id = 1\n \n \n if game.key.space == True:\n info.hidden = True\n \n \n \n game.draw_text(p1_score, 30, 20, 'white', 80) #印出 p1 分數\n game.draw_text(p2_score, 1140, 20, 'white', 80) #印出 p2 分數\n \n\n\nforever(loop) #重複不斷執行遊戲迴圈","created_at":"2021-07-25T16:04:51.420+08:00","updated_at":"2022-05-07T16:49:12.275+08:00","name":"彈力球大賽(預設版) 副本","language":"python","screenshot":{"url":"https://cdn4.koding.school/uploads/project/screenshot/280093/d5d8d90c50346241ad10934a3bdaf682.jpg"},"parent_id":183420,"plugin":"game.set({'width': 1200, 'height': 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":28,"hashid":"kdms63wj2","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":5487390,"file_name":"p2.png","project_id":280093,"asset_id":251890,"created_at":"2021-07-25T16:04:51.425+08:00","updated_at":"2021-07-25T16:04:51.425+08:00"},{"id":5487391,"file_name":"ball_1.png","project_id":280093,"asset_id":251891,"created_at":"2021-07-25T16:04:51.426+08:00","updated_at":"2021-07-25T16:04:51.426+08:00"},{"id":5487392,"file_name":"bg.jpg","project_id":280093,"asset_id":251892,"created_at":"2021-07-25T16:04:51.427+08:00","updated_at":"2021-07-25T16:04:51.427+08:00"},{"id":5487393,"file_name":"hit.mp3","project_id":280093,"asset_id":251893,"created_at":"2021-07-25T16:04:51.428+08:00","updated_at":"2021-07-25T16:04:51.428+08:00"},{"id":5487394,"file_name":"lose.ogg","project_id":280093,"asset_id":251894,"created_at":"2021-07-25T16:04:51.428+08:00","updated_at":"2021-07-25T16:04:51.428+08:00"},{"id":5487395,"file_name":"bg_1.jpg","project_id":280093,"asset_id":251895,"created_at":"2021-07-25T16:04:51.429+08:00","updated_at":"2021-07-25T16:04:51.429+08:00"},{"id":5487396,"file_name":"p1.png","project_id":280093,"asset_id":251896,"created_at":"2021-07-25T16:04:51.430+08:00","updated_at":"2021-07-25T16:04:51.430+08:00"},{"id":5487397,"file_name":"info.png","project_id":280093,"asset_id":251897,"created_at":"2021-07-25T16:04:51.431+08:00","updated_at":"2021-07-25T16:04:51.431+08:00"},{"id":5487398,"file_name":"bgm.mp3","project_id":280093,"asset_id":251898,"created_at":"2021-07-25T16:04:51.432+08:00","updated_at":"2021-07-25T16:04:51.432+08:00"},{"id":5487399,"file_name":"bg_2.jpg","project_id":280093,"asset_id":251899,"created_at":"2021-07-25T16:04:51.433+08:00","updated_at":"2021-07-25T16:04:51.433+08:00"},{"id":5487400,"file_name":"ball_3.png","project_id":280093,"asset_id":251900,"created_at":"2021-07-25T16:04:51.433+08:00","updated_at":"2021-07-25T16:04:51.433+08:00"},{"id":5487401,"file_name":"ball_0.png","project_id":280093,"asset_id":251901,"created_at":"2021-07-25T16:04:51.434+08:00","updated_at":"2021-07-25T16:04:51.434+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦