{"id":183381,"student_id":3760,"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', True)\n\n#初始化階梯\nfor i in range(0, 9, 1):\n s = game.create_sprite(\"s1.png\", \"s2.png\", \"s3.png\", \n \"s4.png\", \"s5.png\", \"s6.png\")\n s.costume_id = 3 # random.randint(0, 5)\n s.x = random.randint(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_info()\n gameover_check()\n update_costume()\n update_background()\n\n# 偵測玩家操控並更新角色位置\ndef update_player ():\n global vy\n if key.left and not player.touched(left_wall):\n player.x -= 12\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# 讓所有階梯向上捲動\ndef update_stairs():\n global floor\n for s in stairs:\n s.y -= 3\n if s.y \u003c -30:\n s.y += 1350\n s.x = random.randint(350, 850)\n if random.randint(1, 100)\u003c=20 and floor\u003e20:\n s.costume_id = random.randint(0, 5)\n else:\n s.costume_id = 3\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 if s.costume_id == 1:\n player.x += 6\n if s.costume_id == 2:\n vy = -16\n game.create_sound(\"jump.mp3\")\n if s.costume_id == 3 and s.id != touch_on:\n life += 1\n if s.costume_id == 4 and s.id != touch_on:\n life -= 3\n game.create_sound(\"hit.mp3\")\n if s.costume_id == 5:\n s.hidden = True\n \n touch_on = s.id\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# 判斷遊戲是否結束\ndef gameover_check():\n if life\u003c=0 or player.y\u003e1000 or player.touched(ceiling):\n bg.costume_id = 1\n game.stop()\n 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\n# 玩家走路動畫\ndef update_costume():\n global clock\n \n clock += 1\n if clock%4 == 0:\n if key.left:\n if player.costume_id == 3:\n player.costume_id = 4\n else:\n player.costume_id = 3\n elif key.right:\n if player.costume_id == 1:\n player.costume_id = 2\n else:\n player.costume_id = 1\n else:\n player.costume_id = 0\n\nplayer.on('touch', stairs, on_touch_stair)\ngame.forever(loop) #重複不斷執行遊戲迴圈\n\n\n","created_at":"2020-08-21T11:38:02.947+08:00","updated_at":"2020-08-21T14:48:35.864+08:00","name":"小朋友下樓梯_S 副本 副本","language":"python","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/183381/a536fae2da8eb323b579d19516407729.jpg"},"parent_id":183380,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":84,"hashid":"2pdsg8nw","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3118079,"file_name":"wall.png","project_id":183381,"asset_id":218306,"created_at":"2020-08-21T11:38:02.953+08:00","updated_at":"2020-08-21T11:38:02.953+08:00"},{"id":3118080,"file_name":"w.png","project_id":183381,"asset_id":218294,"created_at":"2020-08-21T11:38:02.954+08:00","updated_at":"2020-08-21T11:38:02.954+08:00"},{"id":3118081,"file_name":"s6.png","project_id":183381,"asset_id":218305,"created_at":"2020-08-21T11:38:02.955+08:00","updated_at":"2020-08-21T11:38:02.955+08:00"},{"id":3118082,"file_name":"s5.png","project_id":183381,"asset_id":218304,"created_at":"2020-08-21T11:38:02.956+08:00","updated_at":"2020-08-21T11:38:02.956+08:00"},{"id":3118083,"file_name":"s4.png","project_id":183381,"asset_id":218303,"created_at":"2020-08-21T11:38:02.957+08:00","updated_at":"2020-08-21T11:38:02.957+08:00"},{"id":3118084,"file_name":"s3.png","project_id":183381,"asset_id":218302,"created_at":"2020-08-21T11:38:02.958+08:00","updated_at":"2020-08-21T11:38:02.958+08:00"},{"id":3118085,"file_name":"s2.png","project_id":183381,"asset_id":218301,"created_at":"2020-08-21T11:38:02.959+08:00","updated_at":"2020-08-21T11:38:02.959+08:00"},{"id":3118086,"file_name":"s1.png","project_id":183381,"asset_id":218300,"created_at":"2020-08-21T11:38:02.960+08:00","updated_at":"2020-08-21T11:38:02.960+08:00"},{"id":3118087,"file_name":"p5.png","project_id":183381,"asset_id":218313,"created_at":"2020-08-21T11:38:02.961+08:00","updated_at":"2020-08-21T11:38:02.961+08:00"},{"id":3118088,"file_name":"p4.png","project_id":183381,"asset_id":218312,"created_at":"2020-08-21T11:38:02.962+08:00","updated_at":"2020-08-21T11:38:02.962+08:00"},{"id":3118089,"file_name":"p3.png","project_id":183381,"asset_id":218311,"created_at":"2020-08-21T11:38:02.963+08:00","updated_at":"2020-08-21T11:38:02.963+08:00"},{"id":3118090,"file_name":"p2.png","project_id":183381,"asset_id":218310,"created_at":"2020-08-21T11:38:02.964+08:00","updated_at":"2020-08-21T11:38:02.964+08:00"},{"id":3118091,"file_name":"p1.png","project_id":183381,"asset_id":218309,"created_at":"2020-08-21T11:38:02.965+08:00","updated_at":"2020-08-21T11:38:02.965+08:00"},{"id":3118092,"file_name":"jump.mp3","project_id":183381,"asset_id":36478,"created_at":"2020-08-21T11:38:02.966+08:00","updated_at":"2020-08-21T11:38:02.966+08:00"},{"id":3118093,"file_name":"hit.mp3","project_id":183381,"asset_id":36476,"created_at":"2020-08-21T11:38:02.967+08:00","updated_at":"2020-08-21T11:38:02.967+08:00"},{"id":3118094,"file_name":"gg.mp3","project_id":183381,"asset_id":36479,"created_at":"2020-08-21T11:38:02.968+08:00","updated_at":"2020-08-21T11:38:02.968+08:00"},{"id":3118095,"file_name":"bgm.mp3","project_id":183381,"asset_id":36477,"created_at":"2020-08-21T11:38:02.969+08:00","updated_at":"2020-08-21T11:38:02.969+08:00"},{"id":3118096,"file_name":"bg_1.jpg","project_id":183381,"asset_id":218308,"created_at":"2020-08-21T11:38:02.969+08:00","updated_at":"2020-08-21T11:38:02.969+08:00"},{"id":3118097,"file_name":"bg_0.jpg","project_id":183381,"asset_id":218307,"created_at":"2020-08-21T11:38:02.970+08:00","updated_at":"2020-08-21T11:38:02.970+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
繁中
简中
English
日本語
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦