{"id":449623,"student_id":10,"content":"from game import set_backdrop, create_sprite, stop\nfrom random import randrange\nset_backdrop('bg.png') \nsuperman = create_sprite('koding.png') #超人\nflash = create_sprite('flash.png') #閃光燈\ncover = create_sprite('cover.png') #相機外框\n\nflying = True #是否正在飛行\nspeed = 20 #飛行速度\nsuccess = False #取締是否成功\nsuperman.x = -300 #初始化超人位置\n\ndef gameloop():\n if flying: #如果正在飛行,就根據速度改變位置\n superman.x += speed \n else: #如果停止飛行,就顯示取締結果和當前速度\n color = 'white' if success else 'red'\n text = '取締成功' if success else '取締失敗'\n drawText(str(speed * 10) + 'km/h ' + text, 50, 50, color, 50)\n \n if flash.opacity \u003e= 0.01: flash.opacity -= 0.01 #閃光燈不斷變透明\n \n if flying:\n cover.hidden = False\n else:\n cover.hidden = True\n \ndef keydown():\n global flying, speed, success\n if flying: #如果正在飛行\n flash.opacity = 1 #顯示閃光燈\n success = superman.x \u003e 100 and superman.x \u003c 1100 #判斷是否取締成功\n speed += 5 if success else -5 #取締成功下次速度 +5 否則 -5\n else: #如果停止飛行\n superman.x = -(300 + randrange(300)) * speed #重新開始重置超人位置\n \n if flying:\n flying = False\n else:\n flying = True\nforever(gameloop) #不斷執行遊戲迴圈\non('keydown', 'space', keydown) #空白鍵拍照","created_at":"2022-10-19T15:59:49.617+08:00","updated_at":"2023-12-07T12:12:57.020+08:00","name":"取締超人超速_反轉布林值","language":"python","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/449623/287fbf8f3cc5c43ea4d999ce7f9e128e.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":118,"hashid":"zpesrqee2","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":10168693,"file_name":"koding.png","project_id":449623,"asset_id":574339,"created_at":"2022-10-19T16:09:02.280+08:00","updated_at":"2022-10-19T16:09:02.280+08:00"},{"id":10168691,"file_name":"bg.png","project_id":449623,"asset_id":574337,"created_at":"2022-10-19T16:00:28.940+08:00","updated_at":"2022-10-19T16:00:28.940+08:00"},{"id":10168692,"file_name":"flash.png","project_id":449623,"asset_id":574338,"created_at":"2022-10-19T16:02:13.821+08:00","updated_at":"2022-10-19T16:02:13.821+08:00"},{"id":10168698,"file_name":"cover.png","project_id":449623,"asset_id":574342,"created_at":"2022-10-19T17:31:29.042+08:00","updated_at":"2022-10-19T17:31:29.042+08:00"},{"id":10174037,"file_name":"bg.png","project_id":449623,"asset_id":574577,"created_at":"2022-10-21T18:26:20.386+08:00","updated_at":"2022-10-21T18:26:20.386+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦