{"id":43861,"student_id":70,"content":"import game\n\n##=== Lesson 1\n## 1. 修改初始位置\n## 2. 当按键按下时,让战机移动位置\n## 2. 打印名称\n## 3. 将数字转为字符串,印出生命值\n# fighter.life = 3\n# fighter.y = 440\n# def update():\n# game.print(\"叩叮战斗机\", 20, 20, \"white\")\n# game.print(\"生命值: \"+str(fighter.life), 20, 40, \"white\")\n# if game.key.right==True:\n# fighter.x = fighter.x + 4\n# if game.key.left==True:\n# fighter.x = fighter.x - 4\n# if game.key.up==True:\n# fighter.y = fighter.y - 4\n# if game.key.down==True:\n# fighter.y = fighter.y + 4\n# game.forever(update)\n##=== 挑战题:\n## 1. 为你的名字换一个特别的颜色吧!\n## 2. 更改一下战机的速度,让他飞得更快或更慢一点!\n\n##=== Lesson 2 \n## 1. 找出画面的范围\n## 2. 学习比较运算以及 if 的语法,当 fighter 超出界限时能够留在范围内\n## 3. 如果空白鍵被按下,發射子彈\n# fighter.life = 3\n# fighter.y = 440\n# def update():\n# game.print(\"叩叮战斗机\", 20, 20, \"white\")\n# game.print(\"生命值: \"+str(fighter.life), 20, 40, \"white\")\n# if game.key.right==True:\n# fighter.x = fighter.x + 4\n# if fighter.x\u003e640:\n# fighter.x=640\n# if game.key.left==True:\n# fighter.x = fighter.x - 4\n# if fighter.x\u003c0:\n# fighter.x=0\n# if game.key.up==True:\n# fighter.y = fighter.y - 4\n# if fighter.y\u003c0:\n# fighter.y=0\n# if game.key.down==True:\n# fighter.y = fighter.y + 4\n# if fighter.y\u003e480:\n# fighter.y=480\n# if game.key.space==True:\n# fighter_shoot()\n# game.forever(update)\n##=== 挑战题:\n## 1. 如果生命值剩下1,将生命值的文字换为红色\n\n##=== Lesson 3\n## 1. 找出一個代表絕招的按鍵,當這個按鍵被按下時,會朝四面八方發射子彈\n## 2. 將創造出來的子彈加到 bullets 清單中\n# fighter.life = 3\n# fighter.y = 440\n# def update():\n# game.print(\"叩叮战斗机\", 20, 20, \"white\")\n# game.print(\"生命值: \"+str(fighter.life), 20, 40, \"white\")\n# if game.key.right==True:\n# fighter.x = fighter.x + 4\n# if fighter.x\u003e640:\n# fighter.x=640\n# if game.key.left==True:\n# fighter.x = fighter.x - 4\n# if fighter.x\u003c0:\n# fighter.x=0\n# if game.key.up==True:\n# fighter.y = fighter.y - 4\n# if fighter.y\u003c0:\n# fighter.y=0\n# if game.key.down==True:\n# fighter.y = fighter.y + 4\n# if fighter.y\u003e480:\n# fighter.y=480\n# if game.key.space==True:\n# fighter_shoot()\n# if game.key.c==True:\n# angle=0\n# while i\u003c360:\n# fighter_shoot( angle )\n# angle += 45\n# game.forever(update)\n##=== 挑战题:\n## 1. 修改循環的次數以及旋轉的角度,讓子彈更密集\n\n##=== Lesson 4\n## 1. 新增一个变量,用来存储剩下「几次技能」,每发动一次技能,就减少1\n## 2. 将还剩下几次技能给打印出来\n## 3. 新增一个变量,用来倒数下一次能够发动技能的时间,每发动一次就变为特定的数值,会随时间不断减少\nfighter.life = 3\nfighter.y = 440\nskill_count = 3\nskill_loading = 0\n\ndef update():\n \n global skill_count, skill_loading\n \n skill_loading = skill_loading-1\n \n game.print(\"叩叮战斗机\", 20, 20, \"white\")\n game.print(\"生命值: \"+str(fighter.life), 20, 40, \"white\")\n game.print(\"绝招数: \"+str(skill_count), 20, 60, \"white\")\n if game.key.right==True:\n fighter.x = fighter.x + 4\n if fighter.x\u003e640:\n fighter.x=640\n if game.key.left==True:\n fighter.x = fighter.x - 4\n if fighter.x\u003c0:\n fighter.x=0\n if game.key.up==True:\n fighter.y = fighter.y - 4\n if fighter.y\u003c0:\n fighter.y=0\n if game.key.down==True:\n fighter.y = fighter.y + 4\n if fighter.y\u003e480:\n fighter.y=480\n if game.key.space==True:\n fighter_shoot()\n if game.key.c==True:\n if skill_loading\u003c=0 and skill_count\u003e0:\n skill_loading = 50\n skill_count = skill_count-1\n angle = 0\n while angle\u003c360:\n fighter_shoot( angle )\n angle += 30\ngame.forever(update)\n\n##=== 挑战题:\n## 1. 当不能施展绝招时,将显示绝招数的那行字改为红色\n\n\n","created_at":"2018-09-30T21:25:50.359+08:00","updated_at":"2019-10-16T23:39:17.993+08:00","name":"space_hawk","language":"python","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/43861/fd1ac05835b665cf0d7e3c5532c7c2d7.jpg"},"parent_id":null,"plugin":"import game\nimport math\nimport random\nimport time\n\n_time = time\nSTART_AT = _time.time()\n\n_timer = 0\n_explode_at = START_AT\ngame.setBackdrop(\"bg.jpg\",0,0,640,480)\ngame.sound.play('Arcade-Fantasy.mp3',True)\nfighter = game.createSprite([\"fighter_1.png\",\"fighter_2.png\",\"fighter_damaged.png\"])\nfighter.scale = 0.6\nfighter.y = 200\nfighter.layer = 999\nfighter._last_shot_at = 0\nfighter.life = 3\nfighter.damage_countdown = 0\n\nenemies = []\nlights = []\nbullets = []\n\ndef clear_dead_enemies_and_bullets():\n global enemies, bullets\n enemies = [e for e in enemies if e._deleted != True]\n bullets = [b for b in bullets if b._deleted != True]\n\ndef update():\n global _timer\n _timer = _timer+1\n fighter._last_shot_at-=1\n \n game.print(int(_time.time()-START_AT), 600, 20, \"white\", 18)\n if (fighter.damage_countdown\u003e0):\n fighter.costumeId = int(_timer/4)%2+1\n fighter.damage_countdown-=1\n else:\n fighter.costumeId = int(_timer/6)%2\n \n if (_timer%20==0):\n clear_dead_enemies_and_bullets()\n \n if (_timer%20==0):\n e = game.createSprite([\"enemy_1.png\",\"enemy_2.png\"])\n e.rotationStyle = \"fixed\"\n e.scale = 0.6\n e.x = random.randint(0,640)\n e.y = -20\n e.toward(fighter)\n enemies.append(e)\n if (_timer%10==0):\n l = game.createSprite(\"star_light.png\")\n l.x = random.randint(0,640)\n l.y = -20\n l.layer = 0\n l.scale = 0.2+random.random()*0.4\n lights.append(l)\n for e in enemies:\n e.stepForward(4)\n e.costumeId = int(_timer/6)%2\n if e._deleted==False:\n if(e.y\u003e660):\n e.destroy()\n if e.touched(fighter):\n e.destroy()\n fighter.life-=1\n if(fighter.life\u003c=0):\n fighter_explode()\n game.sound.play('fighter_explode.wav')\n else:\n fighter.damage_countdown=30\n game.sound.play('damage.wav')\n \n for l in lights:\n if l._deleted==False:\n l.y += 18\n if(l.y\u003e660):\n l.destroy()\n for b in bullets:\n if b._deleted:\n continue\n b.stepForward(20)\n if (b.y\u003c0 or b.y\u003e480 or b.x\u003e640 or b.x\u003c0):\n b.destroy()\n for b in bullets:\n for e in enemies:\n if b.touched(e):\n game.sound.play('enemy_destroy.wav')\n e.destroy()\n b.destroy()\n \ndef fighter_shoot( angle=0 ):\n if _timer==fighter._last_shot_at or _timer\u003e=fighter._last_shot_at+12 :\n game.sound.play('laser.wav')\n fighter._last_shot_at = _timer\n bullet = game.createSprite(\"bullet.png\")\n bullet.x = fighter.x\n bullet.y = fighter.y\n bullet.direction = angle\n bullets.append(bullet)\n\ndef fighter_explode():\n _explode_at = _time.time()\n fighter.destroy()\n sparks = []\n for i in range(18):\n s = game.createSprite(\"spark.png\")\n s.scale = 0.4\n s.r = 0\n s.x = fighter.x\n s.y = fighter.y\n s.direction = i*20\n sparks.append(s)\n def sparks_expand():\n for s in sparks:\n s.stepForward(2)\n s.scale = 0.4 * (1 + 0.5*math.sin(s.r))\n s.r+=0.8\n s.opacity -= 0.02\n if s.opacity\u003c=0:\n game.stop() \n game.print(\"你存活了 \"+str(int(_explode_at-START_AT))+\" 秒\", 200, 200, \"white\", 40)\n return\n game.forever(sparks_expand)\ngame.forever(update)\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":223,"hashid":"p93s38q5","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":770576,"file_name":"Arcade-Fantasy.mp3","project_id":43861,"asset_id":88343,"created_at":"2018-09-30T21:26:41.403+08:00","updated_at":"2018-09-30T21:26:41.403+08:00"},{"id":770579,"file_name":"lootbox.png","project_id":43861,"asset_id":88352,"created_at":"2018-09-30T21:44:50.302+08:00","updated_at":"2018-09-30T21:44:50.302+08:00"},{"id":770600,"file_name":"star_light.png","project_id":43861,"asset_id":88358,"created_at":"2018-09-30T22:24:11.784+08:00","updated_at":"2018-09-30T22:24:11.784+08:00"},{"id":770708,"file_name":"laser.png","project_id":43861,"asset_id":88369,"created_at":"2018-10-02T00:25:23.285+08:00","updated_at":"2018-10-02T00:25:27.289+08:00"},{"id":825572,"file_name":"spark.png","project_id":43861,"asset_id":92350,"created_at":"2018-10-24T17:14:53.418+08:00","updated_at":"2018-10-24T17:14:53.418+08:00"},{"id":825573,"file_name":"fighter_1.png","project_id":43861,"asset_id":92351,"created_at":"2018-10-24T17:14:59.717+08:00","updated_at":"2018-10-24T17:14:59.717+08:00"},{"id":825574,"file_name":"fighter_2.png","project_id":43861,"asset_id":92352,"created_at":"2018-10-24T17:15:04.975+08:00","updated_at":"2018-10-24T17:15:04.975+08:00"},{"id":825575,"file_name":"bg.jpg","project_id":43861,"asset_id":92353,"created_at":"2018-10-24T17:15:10.301+08:00","updated_at":"2018-10-24T17:15:10.301+08:00"},{"id":825579,"file_name":"bullet.png","project_id":43861,"asset_id":92357,"created_at":"2018-10-24T19:13:20.420+08:00","updated_at":"2018-10-24T19:13:20.420+08:00"},{"id":825638,"file_name":"enemy_2.png","project_id":43861,"asset_id":92399,"created_at":"2018-10-25T11:53:39.204+08:00","updated_at":"2018-10-25T11:53:39.204+08:00"},{"id":825639,"file_name":"enemy_1.png","project_id":43861,"asset_id":92400,"created_at":"2018-10-25T11:53:39.209+08:00","updated_at":"2018-10-25T11:53:39.209+08:00"},{"id":825640,"file_name":"laser.wav","project_id":43861,"asset_id":92401,"created_at":"2018-10-25T12:15:05.288+08:00","updated_at":"2018-10-25T12:17:25.246+08:00"},{"id":825641,"file_name":"damage.wav","project_id":43861,"asset_id":92402,"created_at":"2018-10-25T12:26:12.450+08:00","updated_at":"2018-10-25T12:26:18.381+08:00"},{"id":825643,"file_name":"fighter_explode.wav","project_id":43861,"asset_id":92404,"created_at":"2018-10-25T12:27:21.151+08:00","updated_at":"2018-10-25T12:27:28.314+08:00"},{"id":825642,"file_name":"enemy_destroy.wav","project_id":43861,"asset_id":92403,"created_at":"2018-10-25T12:26:46.431+08:00","updated_at":"2018-10-25T12:29:09.888+08:00"},{"id":825662,"file_name":"fighter_damaged.png","project_id":43861,"asset_id":92406,"created_at":"2018-10-25T12:35:33.730+08:00","updated_at":"2018-10-25T12:35:33.730+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦