{"id":252436,"student_id":10,"content":"import random #載入產生隨機數套件\nfrom game import * #載入所有遊戲語法\n\ngame.set_backdrop('#111111') #設定背景色碼\nbg = create_sprite('tower_0.png', 'tower_1.png') #背景圖\nceiling = create_sprite('ceiling.png') #天花板的針刺\np1 = create_sprite('p1_0.png', 'p1_1.png', 'p1_2.png', 'p1_3.png', 'p1_4.png') #玩家\np2 = create_sprite('p2_0.png', 'p2_1.png', 'p2_2.png', 'p2_3.png', 'p2_4.png') #玩家\n\n# 初始化角色位置\u0026圖層\np1.move_to(800, 100)\np2.move_to(400, 100)\nceiling.move_to(600, 18)\nceiling.layer = 1\n\n# 共同變數\nstairs = [] #存放階梯角色\nfloor = 0 #重置的階梯數\n\n# player 1 的變數\np1_vy = 0 #墜落的速度\np1_life = 10 #血量\np1_touch_on = None #當前踩著的階梯 id\n\n# player 2 的變數\np2_vy = 0 #墜落的速度\np2_life = 10 #血量\np2_touch_on = None #當前踩著的階梯 id\n\ncreate_sound('bgm.mp3', True)\n\n\n#初始化階梯\nfor i in range(7):\n s = create_sprite('s_0.png', 's_1.png', 's_2.png', 's_3.png', 's_4.png', 's_5.png')\n s.y = i*150 + 600\n s.x = random.randrange(200, 700)\n s.costume_id = random.randrange(6)\n stairs.append(s)\n s.id = i\n\n\n#遊戲主迴圈\ndef loop ():\n update_info() #捲動更新背景圖\n update_stairs() #讓所有階梯向上捲動\n update_position() #偵測玩家操控並更新角色位置\n update_costume() #玩家走路動畫\n update_background() #捲動更新背景圖\n gameover_check() #判斷遊戲是否結束\n p1p2_interaction() #雙方玩家推擠行為\n\n\n#更新遊戲分數\ndef update_info():\n draw_text('層數:' + str(floor), 10, 40, 'white', 30)\n draw_text('p1 生命:' + str(p1_life), 10, 70, 'white', 30)\n draw_text('p2 生命:' + str(p2_life), 10, 100, 'white', 30)\n\n\n#捲動更新背景圖\ndef update_background():\n bg.y -= 3\n if bg.y \u003c 0: bg.y += 2700\n \n\n#讓所有階梯向上捲動\ndef update_stairs():\n global floor\n \n for s in stairs:\n s.y -= 3\n if s.y \u003c -75:\n s.y += 1050 # 150 * 7\n s.x = random.randrange(100, 800)\n s.costume_id = random.randrange(6)\n s.hidden = False\n floor += 1\n \n if p1.y \u003c s.y and p1.touched(s):\n p1_touch_stair(s)\n if p2.y \u003c s.y and p2.touched(s):\n p2_touch_stair(s)\n\n\n#偵測玩家操控並更新角色位置\ndef update_position():\n global p1_vy, p2_vy\n \n p1_vy += 0.3\n p1.y += p1_vy\n if key.left: p1.x -= 6\n if key.right: p1.x += 6\n \n p2_vy += 0.3\n p2.y += p2_vy\n if key.a: p2.x -= 6\n if key.d: p2.x += 6\n \n\n#玩家踩到階梯時執行階梯對應的功能\ndef p1_touch_stair(s):\n global p1_touch_on, p1_life, p1_vy\n \n p1_vy = 0\n p1.y = s.y - 60\n\n if s.costume_id == 0: p1.x += 3\n if s.costume_id == 1: p1.x -= 3\n if s.costume_id == 2: p1_vy = -10\n if s.costume_id == 3: s.hidden = True\n if s.costume_id == 4 and s.id != p1_touch_on: p1_life += 1\n if s.costume_id == 5 and s.id != p1_touch_on: p1_life -= 3\n if p1_life \u003e 10: p1_life = 10\n p1_touch_on = s.id\n\n\n#玩家踩到階梯時執行階梯對應的功能\ndef p2_touch_stair(s):\n global p2_touch_on, p2_life, p2_vy\n \n p2_vy = 0\n p2.y = s.y - 60\n\n if s.costume_id == 0: p2.x += 3\n if s.costume_id == 1: p2.x -= 3\n if s.costume_id == 2: p2_vy = -10\n if s.costume_id == 3: s.hidden = True\n if s.costume_id == 4 and s.id != p2_touch_on: p2_life += 1\n if s.costume_id == 5 and s.id != p2_touch_on: p2_life -= 3\n if p2_life \u003e 10: p2_life = 10\n p2_touch_on = s.id\n\n\n#玩家走路動畫\ndef update_costume():\n if key.right:\n p1.costume_id = int(p1.x / 40) % 2 + 1\n elif key.left:\n p1.costume_id = int(p1.x / 40) % 2 + 3\n else:\n p1.costume_id = 0\n \n if key.d:\n p2.costume_id = int(p2.x / 40) % 2 + 1\n elif key.a:\n p2.costume_id = int(p2.x / 40) % 2 + 3\n else:\n p2.costume_id = 0\n\n#判斷遊戲是否結束\ndef gameover_check():\n if p1_life \u003c= 0 or p1.y \u003e 1000 or p1.y \u003c 0:\n stop()\n create_sound('gg.mp3')\n drawText('p1 死亡', 400, 400, 'white', 100)\n if p2_life \u003c= 0 or p2.y \u003e 1000 or p2.y \u003c 0:\n stop()\n create_sound('gg.mp3')\n drawText('p2 死亡', 400, 400, 'white', 100)\n\n\n# 雙方玩家推擠程式,記得移動的距離必須一樣!\ndef p1p2_interaction():\n if p1.touched(p2):\n if p1.x \u003c p2.x:\n if key.right and key.a == False: p2.x += 8\n if key.right == False and key.a: p1.x -= 8\n if key.right and key.a:\n p1.x -= 8\n p2.x += 8\n else:\n if key.left and key.d == False: p2.x -= 8\n if key.left == False and key.d: p1.x += 8\n if key.left and key.d:\n p1.x += 8\n p2.x -= 8\n\nforever(loop) #重複不斷執行遊戲迴圈\n","created_at":"2021-05-13T10:32:07.364+08:00","updated_at":"2024-05-02T12:38:37.001+08:00","name":"小朋友下樓梯_除錯模擬","language":"python","screenshot":{"url":"https://cdn4.koding.school/uploads/project/screenshot/252436/1a8751143ccad470d05353353d0c5c28.jpg"},"parent_id":151926,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":206,"hashid":"6rps9edn5","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":4776322,"file_name":"p2_4.png","project_id":252436,"asset_id":293225,"created_at":"2021-05-13T10:32:07.370+08:00","updated_at":"2021-05-13T10:32:07.370+08:00"},{"id":4776323,"file_name":"p2_3.png","project_id":252436,"asset_id":293226,"created_at":"2021-05-13T10:32:07.371+08:00","updated_at":"2021-05-13T10:32:07.371+08:00"},{"id":4776324,"file_name":"p2_2.png","project_id":252436,"asset_id":293227,"created_at":"2021-05-13T10:32:07.372+08:00","updated_at":"2021-05-13T10:32:07.372+08:00"},{"id":4776325,"file_name":"p2_1.png","project_id":252436,"asset_id":293228,"created_at":"2021-05-13T10:32:07.373+08:00","updated_at":"2021-05-13T10:32:07.373+08:00"},{"id":4776326,"file_name":"p2_0.png","project_id":252436,"asset_id":293229,"created_at":"2021-05-13T10:32:07.374+08:00","updated_at":"2021-05-13T10:32:07.374+08:00"},{"id":4776327,"file_name":"p1_2.png","project_id":252436,"asset_id":293230,"created_at":"2021-05-13T10:32:07.375+08:00","updated_at":"2021-05-13T10:32:07.375+08:00"},{"id":4776328,"file_name":"p1_0.png","project_id":252436,"asset_id":293231,"created_at":"2021-05-13T10:32:07.376+08:00","updated_at":"2021-05-13T10:32:07.376+08:00"},{"id":4776329,"file_name":"jump.mp3","project_id":252436,"asset_id":293232,"created_at":"2021-05-13T10:32:07.376+08:00","updated_at":"2021-05-13T10:32:07.376+08:00"},{"id":4776330,"file_name":"hit.mp3","project_id":252436,"asset_id":293233,"created_at":"2021-05-13T10:32:07.377+08:00","updated_at":"2021-05-13T10:32:07.377+08:00"},{"id":4776331,"file_name":"gg.mp3","project_id":252436,"asset_id":293234,"created_at":"2021-05-13T10:32:07.378+08:00","updated_at":"2021-05-13T10:32:07.378+08:00"},{"id":4776332,"file_name":"bgm.mp3","project_id":252436,"asset_id":293235,"created_at":"2021-05-13T10:32:07.379+08:00","updated_at":"2021-05-13T10:32:07.379+08:00"},{"id":4776333,"file_name":"ceiling.png","project_id":252436,"asset_id":293236,"created_at":"2021-05-13T10:32:07.380+08:00","updated_at":"2021-05-13T10:32:07.380+08:00"},{"id":4776334,"file_name":"p1_1.png","project_id":252436,"asset_id":293237,"created_at":"2021-05-13T10:32:07.380+08:00","updated_at":"2021-05-13T10:32:07.380+08:00"},{"id":4776335,"file_name":"p1_3.png","project_id":252436,"asset_id":293238,"created_at":"2021-05-13T10:32:07.381+08:00","updated_at":"2021-05-13T10:32:07.381+08:00"},{"id":4776336,"file_name":"p1_4.png","project_id":252436,"asset_id":293239,"created_at":"2021-05-13T10:32:07.382+08:00","updated_at":"2021-05-13T10:32:07.382+08:00"},{"id":4776337,"file_name":"s_0.png","project_id":252436,"asset_id":293240,"created_at":"2021-05-13T10:32:07.383+08:00","updated_at":"2021-05-13T10:32:07.383+08:00"},{"id":4776338,"file_name":"s_1.png","project_id":252436,"asset_id":293241,"created_at":"2021-05-13T10:32:07.384+08:00","updated_at":"2021-05-13T10:32:07.384+08:00"},{"id":4776339,"file_name":"s_2.png","project_id":252436,"asset_id":293242,"created_at":"2021-05-13T10:32:07.385+08:00","updated_at":"2021-05-13T10:32:07.385+08:00"},{"id":4776340,"file_name":"s_4.png","project_id":252436,"asset_id":293243,"created_at":"2021-05-13T10:32:07.386+08:00","updated_at":"2021-05-13T10:32:07.386+08:00"},{"id":4776341,"file_name":"s_5.png","project_id":252436,"asset_id":293244,"created_at":"2021-05-13T10:32:07.387+08:00","updated_at":"2021-05-13T10:32:07.387+08:00"},{"id":4776342,"file_name":"s_3.png","project_id":252436,"asset_id":293245,"created_at":"2021-05-13T10:32:07.388+08:00","updated_at":"2021-05-13T10:32:07.388+08:00"},{"id":4776343,"file_name":"sky_0.png","project_id":252436,"asset_id":293246,"created_at":"2021-05-13T10:32:07.389+08:00","updated_at":"2021-05-13T10:32:07.389+08:00"},{"id":4776344,"file_name":"sky_1.png","project_id":252436,"asset_id":293247,"created_at":"2021-05-13T10:32:07.389+08:00","updated_at":"2021-05-13T10:32:07.389+08:00"},{"id":4776345,"file_name":"tower_0.png","project_id":252436,"asset_id":293248,"created_at":"2021-05-13T10:32:07.390+08:00","updated_at":"2021-05-13T10:32:07.390+08:00"},{"id":4776346,"file_name":"tower_1.png","project_id":252436,"asset_id":293249,"created_at":"2021-05-13T10:32:07.391+08:00","updated_at":"2021-05-13T10:32:07.391+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦