{"id":162857,"student_id":2589,"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\n\nlife = 10 #玩家血量\nfloor = 0 #階梯數\nstairs = [] #存放階梯角色\nvy = 0 #玩家墜落的速度\ntouch_on = None #當前踩著的階梯 id\nclock = 0 #計時器\n\ngame.create_sound('bgm.mp3')\n\n#初始化階梯\nfor i in range(9):\n s = game.create_sprite('s1.png', 's2.png', 's3.png', 's4.png', 's5.png', 's6.png')\n s.costume_id = random.randrange(6)\n s.x = random.randrange(350, 850)\n s.y = i*150 + 550\n s.id = i\n stairs.append(s)\n\n#遊戲主迴圈\ndef loop ():\n update_player() #偵測玩家操控並更新角色位置\n update_stairs() #讓所有階梯向上捲動\n update_costume() #玩家走路動畫\n update_info() #更新遊戲分數\n update_background() #捲動更新背景圖\n gameover_check() #判斷遊戲是否結束\n\n#偵測玩家操控並更新角色位置\ndef update_player():\n global vy\n \n if key.left and not player.touched(left_wall):\n player.x -= 12\n \n if key.right and not player.touched(right_wall):\n player.x += 12\n \n vy += 0.6\n player.y += vy\n\n\n#讓所有階梯向上捲動\ndef update_stairs():\n global floor\n \n for s in stairs:\n s.y -= 3\n if s.y \u003c -30:\n s.x = random.randrange(350, 850)\n s.y += 1350\n s.costume_id = random.randrange(6)\n s.hidden = False\n floor += 1\n\n#玩家踩到階梯時執行階梯對應的功能\ndef on_touch_stair(s):\n global touch_on, life, vy\n \n vy = 0\n player.y = s.y - 50\n\n if s.costume_id == 0:\n player.x -= 6\n \n if s.costume_id == 1:\n player.x += 6\n \n if s.costume_id == 2:\n vy = -16\n game.create_sound('jump.mp3')\n \n if s.costume_id == 3 and s.id != touch_on:\n life += 1\n \n if s.costume_id == 4 and s.id != touch_on:\n life -= 3\n game.create_sound('hit.mp3')\n \n if s.costume_id == 5:\n s.hidden = True\n \n touch_on = s.id\n\n\n#更新遊戲分數\ndef update_info():\n game.draw_text('分數:' + str(floor), 10, 10, 'white', 30)\n game.draw_text('生命:' + str(life), 10, 40, 'white', 30)\n\n\n#判斷遊戲是否結束\ndef gameover_check():\n if life \u003c= 0 or player.y \u003e 1000 or player.touched(ceiling):\n bg.costume_id = 1\n game.stop()\n game.create_sound('gg.mp3')\n\n\n#捲動更新背景圖\ndef update_background():\n bg.y -= 1\n if bg.y \u003c 400:\n bg.y += 100\n\n#玩家走路動畫\ndef update_costume():\n global clock\n\n clock += 1\n if clock%4 == 0:\n if key.right:\n if player.costume_id == 1:\n player.costume_id = 2\n else:\n player.costume_id = 1\n \n elif key.left:\n if player.costume_id == 3:\n player.costume_id = 4\n else:\n player.costume_id = 3\n else:\n player.costume_id = 0\n\n\nplayer.on('touch', stairs, on_touch_stair)\ngame.forever(loop) #重複不斷執行遊戲迴圈\n\n\n","created_at":"2020-07-06T01:54:51.615+08:00","updated_at":"2020-07-12T17:20:05.869+08:00","name":"小朋友下樓梯_T ","language":"python","screenshot":{"url":"https://cdn2.koding.school/uploads/project/screenshot/162857/e5cdcbc9253d8514dce7ef024f983c51.jpg"},"parent_id":160698,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":302,"hashid":"2pdsne3r","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2832729,"file_name":"bg_0.jpg","project_id":162857,"asset_id":218307,"created_at":"2020-07-06T01:54:51.621+08:00","updated_at":"2020-07-06T01:54:51.621+08:00"},{"id":2832730,"file_name":"bg_1.jpg","project_id":162857,"asset_id":218308,"created_at":"2020-07-06T01:54:51.623+08:00","updated_at":"2020-07-06T01:54:51.623+08:00"},{"id":2832731,"file_name":"bgm.mp3","project_id":162857,"asset_id":36477,"created_at":"2020-07-06T01:54:51.624+08:00","updated_at":"2020-07-06T01:54:51.624+08:00"},{"id":2832732,"file_name":"gg.mp3","project_id":162857,"asset_id":36479,"created_at":"2020-07-06T01:54:51.625+08:00","updated_at":"2020-07-06T01:54:51.625+08:00"},{"id":2832733,"file_name":"hit.mp3","project_id":162857,"asset_id":36476,"created_at":"2020-07-06T01:54:51.626+08:00","updated_at":"2020-07-06T01:54:51.626+08:00"},{"id":2832734,"file_name":"jump.mp3","project_id":162857,"asset_id":36478,"created_at":"2020-07-06T01:54:51.627+08:00","updated_at":"2020-07-06T01:54:51.627+08:00"},{"id":2832735,"file_name":"p1.png","project_id":162857,"asset_id":218309,"created_at":"2020-07-06T01:54:51.628+08:00","updated_at":"2020-07-06T01:54:51.628+08:00"},{"id":2832736,"file_name":"p2.png","project_id":162857,"asset_id":218310,"created_at":"2020-07-06T01:54:51.629+08:00","updated_at":"2020-07-06T01:54:51.629+08:00"},{"id":2832737,"file_name":"p3.png","project_id":162857,"asset_id":218311,"created_at":"2020-07-06T01:54:51.630+08:00","updated_at":"2020-07-06T01:54:51.630+08:00"},{"id":2832738,"file_name":"p4.png","project_id":162857,"asset_id":218312,"created_at":"2020-07-06T01:54:51.631+08:00","updated_at":"2020-07-06T01:54:51.631+08:00"},{"id":2832739,"file_name":"p5.png","project_id":162857,"asset_id":218313,"created_at":"2020-07-06T01:54:51.632+08:00","updated_at":"2020-07-06T01:54:51.632+08:00"},{"id":2832740,"file_name":"s1.png","project_id":162857,"asset_id":218300,"created_at":"2020-07-06T01:54:51.633+08:00","updated_at":"2020-07-06T01:54:51.633+08:00"},{"id":2832741,"file_name":"s2.png","project_id":162857,"asset_id":218301,"created_at":"2020-07-06T01:54:51.634+08:00","updated_at":"2020-07-06T01:54:51.634+08:00"},{"id":2832742,"file_name":"s3.png","project_id":162857,"asset_id":218302,"created_at":"2020-07-06T01:54:51.635+08:00","updated_at":"2020-07-06T01:54:51.635+08:00"},{"id":2832743,"file_name":"s4.png","project_id":162857,"asset_id":218303,"created_at":"2020-07-06T01:54:51.636+08:00","updated_at":"2020-07-06T01:54:51.636+08:00"},{"id":2832744,"file_name":"s5.png","project_id":162857,"asset_id":218304,"created_at":"2020-07-06T01:54:51.637+08:00","updated_at":"2020-07-06T01:54:51.637+08:00"},{"id":2832745,"file_name":"s6.png","project_id":162857,"asset_id":218305,"created_at":"2020-07-06T01:54:51.638+08:00","updated_at":"2020-07-06T01:54:51.638+08:00"},{"id":2832746,"file_name":"w.png","project_id":162857,"asset_id":218294,"created_at":"2020-07-06T01:54:51.639+08:00","updated_at":"2020-07-06T01:54:51.639+08:00"},{"id":2832747,"file_name":"wall.png","project_id":162857,"asset_id":218306,"created_at":"2020-07-06T01:54:51.640+08:00","updated_at":"2020-07-06T01:54:51.640+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦