{"id":262647,"student_id":34,"content":"import game\nimport random\n\ngame.set_backdrop('bg.jpg')\nswing = game.create_sprite('swing_0.png', 'swing_1.png') #盪鞦韆與叩叮\napple = game.create_sprite('apple.png') #蘋果\narcher = game.create_sprite('archer.png') #弓箭手\nbow = game.create_sprite('bow.png') #弓\narrow = game.create_sprite('arrow_0.png', 'arrow_1.png') #箭\nlive = game.create_sprite(\"0.png\",\"1.png\",\"2.png\",\"3.png\",\"4.png\",\"5.png\") #創造角色\n\nlive.x = 200\nlive.y = 75\nswing.x = 900\napple.x = 900\nswing.y = 400\napple.y = 400\narcher.x = 300\narcher.y = 600\nbow.x = 300\nbow.y = 600\narrow.x = 300\narrow.y = 600\nbow.direction = 135\narrow.direction = 135\nlive.costume_id = 5\n\nactive = False #紀錄是否拉過弓\nactive2 = False #紀錄箭是否拉出去\nscore = 0 #玩家得分\nvy = 5 #目標移動速度\n\n# state maachine\nstate = 0 # 0: 初始, 1: 拉弓, 2: 放箭, 3: 重置 ,4: 射中\n\n#遊戲主迴圈\ndef loop ():\n global active, score, vy, state\n \n # if state = 某種狀態:\n # 先做該狀態內要做的處理\n # if 是否有改變狀態的事件發生:\n # 改變狀態\n # elif state = 下一個狀態:\n # 先做該狀態內要做的處理\n # if 是否有改變狀態的事件發生:\n # 改變狀態\n #\n \n if state == 0:\n if game.cursor.is_down:\n state = 1 # 進入拉弓狀態\n elif state == 1:\n if bow.direction \u003e 30 and arrow.x == 300:\n arrow.direction -= 2\n bow.direction -= 2\n if not game.cursor.is_down:\n state = 2 # 進入放箭狀態\n elif state == 2:\n arrow.step_forward(25)\n arrow.direction += 1\n if arrow.x \u003e 1200 or arrow.y \u003e 900:\n state = 3\n elif arrow.touched(apple) == True:\n state = 4\n elif state == 3:\n arrow.x = 300\n arrow.y = 600\n apple.hidden = False\n bow.direction = 135\n arrow.direction = 135\n if arrow.costume_id == 0:\n live.costume_id -= 1\n if live.costume_id == 0:\n game.create_sprite(\"gameover.png\") #創造角色\n game.stop()\n \n if arrow.costume_id == 1:\n swing.y = random.randrange(200,701)\n apple.y = swing.y\n arrow.costume_id = 0\n live.costume_id = 5\n state = 0\n elif state == 4:\n apple.hidden = True\n arrow.costume_id = 1\n score += 1\n \n state = 2\n \n game.draw_text(score,1080,50,'white',60)\n if swing.y \u003c 200 or swing.y \u003e 700 :\n vy = -vy\n \n if score \u003e 10:\n swing.y += vy\n apple.y += vy\n if arrow.touched(swing) == True:\n swing.costume_id = 1\n \n else:\n swing.costume_id = 0\n \n \n \ndef loop2 ():\n global active, score, vy, active2\n \n\n if game.cursor.is_down == True and bow.direction \u003e 30 and arrow.x == 300:\n arrow.direction -= 2\n bow.direction -= 2\n active = True\n \n if game.cursor.is_down == False and active == True:\n active2 = True\n \n if active2 == True:\n arrow.step_forward(25)\n arrow.direction += 1\n\n \n if arrow.touched(apple) == True:\n apple.hidden = True\n arrow.costume_id = 1\n score += 1\n \n if arrow.x \u003e 1200 or arrow.y \u003e 900:\n arrow.x = 300\n arrow.y = 600\n active = False\n active2 = False\n apple.hidden = False\n bow.direction = 135\n arrow.direction = 135\n \n if arrow.costume_id == 0:\n live.costume_id -= 1\n if live.costume_id == 0:\n game.create_sprite(\"gameover.png\") #創造角色\n game.stop()\n \n if arrow.costume_id == 1:\n swing.y = random.randrange(200,701)\n apple.y = swing.y\n arrow.costume_id = 0\n live.costume_id = 5\n \n if arrow.touched(swing) == True:\n swing.costume_id = 1\n \n else:\n swing.costume_id = 0\n \n game.draw_text(score,1080,50,'white',60)\n \n if swing.y \u003c 200 or swing.y \u003e 700 :\n vy = -vy\n \n if score \u003e 10:\n swing.y += vy\n apple.y += vy\n \n \ngame.forever(loop) #重複不斷執行\n","created_at":"2021-06-17T19:06:44.978+08:00","updated_at":"2021-07-01T11:26:56.441+08:00","name":"射箭遊戲(預設版) 副本","language":"python","screenshot":{"url":"https://cdn4.koding.school/uploads/project/screenshot/262647/4a6405336885bad90e8041853180d361.jpg"},"parent_id":194470,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":96,"hashid":"882sq559y","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":5039375,"file_name":"gameover.png","project_id":262647,"asset_id":267838,"created_at":"2021-06-17T19:06:44.983+08:00","updated_at":"2021-06-17T19:06:44.983+08:00"},{"id":5039376,"file_name":"bg.jpg","project_id":262647,"asset_id":267839,"created_at":"2021-06-17T19:06:44.984+08:00","updated_at":"2021-06-17T19:06:44.984+08:00"},{"id":5039377,"file_name":"swing_1.png","project_id":262647,"asset_id":267840,"created_at":"2021-06-17T19:06:44.985+08:00","updated_at":"2021-06-17T19:06:44.985+08:00"},{"id":5039378,"file_name":"swing_0.png","project_id":262647,"asset_id":267841,"created_at":"2021-06-17T19:06:44.986+08:00","updated_at":"2021-06-17T19:06:44.986+08:00"},{"id":5039379,"file_name":"0.png","project_id":262647,"asset_id":267842,"created_at":"2021-06-17T19:06:44.986+08:00","updated_at":"2021-06-17T19:06:44.986+08:00"},{"id":5039380,"file_name":"1.png","project_id":262647,"asset_id":267843,"created_at":"2021-06-17T19:06:44.987+08:00","updated_at":"2021-06-17T19:06:44.987+08:00"},{"id":5039381,"file_name":"2.png","project_id":262647,"asset_id":267844,"created_at":"2021-06-17T19:06:44.988+08:00","updated_at":"2021-06-17T19:06:44.988+08:00"},{"id":5039382,"file_name":"3.png","project_id":262647,"asset_id":267845,"created_at":"2021-06-17T19:06:44.989+08:00","updated_at":"2021-06-17T19:06:44.989+08:00"},{"id":5039383,"file_name":"4.png","project_id":262647,"asset_id":267846,"created_at":"2021-06-17T19:06:44.990+08:00","updated_at":"2021-06-17T19:06:44.990+08:00"},{"id":5039384,"file_name":"5.png","project_id":262647,"asset_id":267847,"created_at":"2021-06-17T19:06:44.991+08:00","updated_at":"2021-06-17T19:06:44.991+08:00"},{"id":5039385,"file_name":"arrow_1.png","project_id":262647,"asset_id":267848,"created_at":"2021-06-17T19:06:44.992+08:00","updated_at":"2021-06-17T19:06:44.992+08:00"},{"id":5039386,"file_name":"archer.png","project_id":262647,"asset_id":267849,"created_at":"2021-06-17T19:06:44.993+08:00","updated_at":"2021-06-17T19:06:44.993+08:00"},{"id":5039387,"file_name":"arrow_0.png","project_id":262647,"asset_id":267850,"created_at":"2021-06-17T19:06:44.994+08:00","updated_at":"2021-06-17T19:06:44.994+08:00"},{"id":5039388,"file_name":"bow.png","project_id":262647,"asset_id":267851,"created_at":"2021-06-17T19:06:44.994+08:00","updated_at":"2021-06-17T19:06:44.994+08:00"},{"id":5039389,"file_name":"apple.png","project_id":262647,"asset_id":267852,"created_at":"2021-06-17T19:06:44.995+08:00","updated_at":"2021-06-17T19:06:44.995+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
繁中
简中
English
日本語
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦