{"id":169659,"student_id":3232,"content":"import game\nimport random #載入產生隨機數套件\n\nbg = game.create_sprite('bg_0.jpg', 'bg_1.jpg') #背景圖\nceiling = game.create_sprite('w.png') #天花板的針刺\nleft_wall = game.create_sprite('wall.png') #左邊牆壁\nright_wall = game.create_sprite('wall.png') #右邊牆壁\nplayer = game.create_sprite('p1.png', 'p2.png', 'p3.png', 'p4.png', 'p5.png') #玩家\n\n# 初始化角色位置\u0026圖層\nplayer.y = 100\nleft_wall.x -= 450\nright_wall.x += 450\nceiling.moveTo(600, 18)\nceiling.layer = 1\nlife = 10 #玩家血量\nfloor = 0 #階梯數\nstairs = [] #存放階梯角色\nvy = 0 #玩家墜落的速度\ntouchOn = None #當前踩著的階梯 id\nclock = 0 #計時器\n #創造角色\ngame.create_sound('bgm.mp3', True)\n #創造角色\n\n#初始化階梯\nfor i in range(0, 9):\n stair = game.create_sprite(\"s1.png\", \"s2.png\", \"s3.png\", \"s4.png\", \"s5.png\", \"s6.png\")\n stair.costume_id = random.randint(0, 5)\n stair.x = random.randint(350, 850)\n stair.y = i*150 + 550\n stair.id = i\n stairs.append(stair)\n# 遊戲主迴圈\ndef loop ():\n update_stairs()\n update_player()\n gameover_check()\n update_costume()\n update_background()\n game.draw_text(\"分數: \" + str(floor), 10, 10, \"white\", 30)\n game.draw_text(\"生命: \" + str(life), 10, 40, \"white\", 30)\n \n \n# # 偵測玩家操控並更新角色位置\ndef update_player ():\n global vy\n if key.left and player.touched(left_wall) == False:\n player.x -= 12\n if key.right and player.touched(right_wall) == False:\n player.x += 12\n vy += 0.6\n player.y += vy\n# # 讓所有階梯向上捲動\ndef update_stairs ():\n global floor\n for z in range(0, 9):\n stairs[z].y -= 3\n if stairs[z].y \u003c -30:\n stairs[z].y += 1350\n stairs[z].hidden = False\n stairs[z].costume_id = random.randint(0, 5)\n floor += 1\n \n# # 玩家踩到階梯時執行階梯對應的功能\ndef on_touch_stair (s):\n global touchOn, life, vy\n vy = 0\n player.y = s.y - 50\n if s.costume_id == 0:\n player.x -= 6\n if s.costume_id == 1:\n player.x += 6\n if s.costume_id == 2:\n vy -= 16\n jump = game.create_sound(\"jump.mp3\")\n if s.costume_id == 3 and s.id != touchOn:\n life += 1\n if s.costume_id == 4 and s.id != touchOn:\n life -= 3\n hit = game.create_sound(\"hit.mp3\")\n if s.costume_id == 5:\n s.hidden = True\n touchOn = s.id \n \n \n \n# def update_info ():\n\n# # 判斷遊戲是否結束\ndef gameover_check ():\n if life \u003c= 0 or player.y \u003e 950 or player.touched(ceiling):\n \n \n bg.costume_id = 1\n game.stop()\n gg = game.create_sound(\"gg.mp3\")\n \n# # 捲動更新背景圖\ndef update_background ():\n bg.y -= 1\n if bg.y \u003c 400:\n bg.y += 100\n# # 玩家走路動畫\ndef update_costume ():\n global clock\n \n \n clock += 1\n if clock % 5 == 0:\n if key.left:\n \n if player.costume_id != 3:\n player.costume_id = 3\n else:\n player.costume_id = 4 \n \n \n elif key.right:\n if player.costume_id != 1:\n player.costume_id = 1\n else:\n player.costume_id = 2\n else:\n player.costume_id = 0\n \n \n \ngame.forever(loop) #重複不斷執行遊戲迴圈\nplayer.on(\"touch\", stairs, on_touch_stair)\n\n","created_at":"2020-07-23T10:10:14.787+08:00","updated_at":"2020-07-23T16:06:13.035+08:00","name":"小朋友下樓梯_S 副本","language":"python","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/169659/7fec85bf699406295353e43b301745c8.jpg"},"parent_id":162856,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":42,"hashid":"ej9s38md","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2931028,"file_name":"bg_0.jpg","project_id":169659,"asset_id":218307,"created_at":"2020-07-23T10:10:14.792+08:00","updated_at":"2020-07-23T10:10:14.792+08:00"},{"id":2931029,"file_name":"bg_1.jpg","project_id":169659,"asset_id":218308,"created_at":"2020-07-23T10:10:14.793+08:00","updated_at":"2020-07-23T10:10:14.793+08:00"},{"id":2931030,"file_name":"bgm.mp3","project_id":169659,"asset_id":36477,"created_at":"2020-07-23T10:10:14.795+08:00","updated_at":"2020-07-23T10:10:14.795+08:00"},{"id":2931031,"file_name":"gg.mp3","project_id":169659,"asset_id":36479,"created_at":"2020-07-23T10:10:14.796+08:00","updated_at":"2020-07-23T10:10:14.796+08:00"},{"id":2931032,"file_name":"hit.mp3","project_id":169659,"asset_id":36476,"created_at":"2020-07-23T10:10:14.797+08:00","updated_at":"2020-07-23T10:10:14.797+08:00"},{"id":2931033,"file_name":"jump.mp3","project_id":169659,"asset_id":36478,"created_at":"2020-07-23T10:10:14.797+08:00","updated_at":"2020-07-23T10:10:14.797+08:00"},{"id":2931034,"file_name":"p1.png","project_id":169659,"asset_id":218309,"created_at":"2020-07-23T10:10:14.799+08:00","updated_at":"2020-07-23T10:10:14.799+08:00"},{"id":2931035,"file_name":"p2.png","project_id":169659,"asset_id":218310,"created_at":"2020-07-23T10:10:14.799+08:00","updated_at":"2020-07-23T10:10:14.799+08:00"},{"id":2931036,"file_name":"p3.png","project_id":169659,"asset_id":218311,"created_at":"2020-07-23T10:10:14.800+08:00","updated_at":"2020-07-23T10:10:14.800+08:00"},{"id":2931037,"file_name":"p4.png","project_id":169659,"asset_id":218312,"created_at":"2020-07-23T10:10:14.801+08:00","updated_at":"2020-07-23T10:10:14.801+08:00"},{"id":2931038,"file_name":"p5.png","project_id":169659,"asset_id":218313,"created_at":"2020-07-23T10:10:14.802+08:00","updated_at":"2020-07-23T10:10:14.802+08:00"},{"id":2931039,"file_name":"s1.png","project_id":169659,"asset_id":218300,"created_at":"2020-07-23T10:10:14.803+08:00","updated_at":"2020-07-23T10:10:14.803+08:00"},{"id":2931040,"file_name":"s2.png","project_id":169659,"asset_id":218301,"created_at":"2020-07-23T10:10:14.804+08:00","updated_at":"2020-07-23T10:10:14.804+08:00"},{"id":2931041,"file_name":"s3.png","project_id":169659,"asset_id":218302,"created_at":"2020-07-23T10:10:14.805+08:00","updated_at":"2020-07-23T10:10:14.805+08:00"},{"id":2931042,"file_name":"s4.png","project_id":169659,"asset_id":218303,"created_at":"2020-07-23T10:10:14.806+08:00","updated_at":"2020-07-23T10:10:14.806+08:00"},{"id":2931043,"file_name":"s5.png","project_id":169659,"asset_id":218304,"created_at":"2020-07-23T10:10:14.807+08:00","updated_at":"2020-07-23T10:10:14.807+08:00"},{"id":2931044,"file_name":"s6.png","project_id":169659,"asset_id":218305,"created_at":"2020-07-23T10:10:14.808+08:00","updated_at":"2020-07-23T10:10:14.808+08:00"},{"id":2931045,"file_name":"w.png","project_id":169659,"asset_id":218294,"created_at":"2020-07-23T10:10:14.808+08:00","updated_at":"2020-07-23T10:10:14.808+08:00"},{"id":2931046,"file_name":"wall.png","project_id":169659,"asset_id":218306,"created_at":"2020-07-23T10:10:14.809+08:00","updated_at":"2020-07-23T10:10:14.809+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦