Advertisement
Guest User

nig

a guest
Dec 13th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. app.background = gradient('deepSkyBlue', 'skyBlue', start='top')
  2.  
  3. # clouds
  4. Circle(-10, 350, 60, fill='white', border='gainsboro', borderWidth=3)
  5. Circle(55, 380, 50, fill='white', border='gainsboro', borderWidth=3)
  6. Rect(0, 340, 30, 60, fill='white')
  7. Circle(340, 75, 50, fill='white', border='gainsboro', borderWidth=3)
  8. Circle(260, 120, 70, fill='white', border='gainsboro', borderWidth=3)
  9. Circle(410, 120, 60, fill='white', border='gainsboro', borderWidth=3)
  10. Circle(330, 150, 80, fill='white', border='gainsboro')
  11. Rect(295, 60, 20, 11, fill='white')
  12. Rect(365, 65, 20, 13, fill='white')
  13. Rect(245, 90, 155, 95, fill='white')
  14.  
  15. # bird wings
  16. leftWing = Polygon(175, 230, 185, 205, 145, 195, 130, 195, 155, 210,
  17. fill='violet')
  18. rightWing = Polygon(225, 230, 215, 205, 255, 195, 270, 195, 245, 210,
  19. fill='violet')
  20. app.wingsMovingUp = True
  21.  
  22. # bird body
  23. body = Oval(200, 250, 80, 65, fill='violet', align='bottom')
  24. belly = Oval(200, 250, 65, 40, fill='pink', align='bottom')
  25.  
  26. # bird eyes
  27. leftEye = Circle(190, 190, 12, border='white', borderWidth=7)
  28. rightEye = Circle(210, 190, 12, border='white', borderWidth=7)
  29.  
  30. # bird beak
  31. beak = Polygon(200, 195, 210, 200, 200, 215, 190, 200, fill='gold')
  32.  
  33. def moveBird(bodyX, bodyY):
  34. # Moves all the individual pieces of the bird (besides the body).
  35. belly.centerX = bodyX
  36. belly.bottom = body.bottom
  37.  
  38. leftEye.centerX = bodyX - 10
  39. rightEye.centerX = bodyX + 10
  40. leftEye.centerY = body.top + 5
  41. rightEye.centerY = body.top + 5
  42.  
  43. beak.centerX = bodyX
  44. beak.bottom = belly.top + 5
  45.  
  46. leftWing.centerX = body.left - 8
  47. rightWing.centerX = body.right + 8
  48. leftWing.centerY = bodyY - 5
  49. rightWing.centerY = bodyY - 5
  50.  
  51. def onKeyHold(keys):
  52. # Change the center of the body based on the 'w','a','s','d' keys.
  53. ### Place Your Code Here ###
  54. if('w' in keys):
  55. body.centerY -= 2
  56. moveBird(body.centerX, body.centerY)
  57. elif('s' in keys):
  58. body.centerY += 2
  59. moveBird(body.centerX, body.centerY)
  60. elif('a' in keys):
  61. body.centerX -= 2
  62. moveBird(body.centerX, body.centerY)
  63. elif('d' in keys):
  64. body.centerX += 2
  65. moveBird(body.centerX, body.centerY)
  66. # When moving up or down, flap the wings 5 degrees in the direction that
  67. # app.wingsMovingUp indicates. If the angle is less than -40 or larger
  68. # than 0, app.wingsMovingUp should change.
  69. ### Place Your Code Here ###
  70. if('s' in keys or 'w' in keys):
  71. if(app.wingsMovingUp == True):
  72. leftWing.rotateAngle += 5
  73. rightWing.rotateAngle -= 5
  74. if(app.wingsMovingUp == False):
  75. leftWing.rotateAngle -= 5
  76. rightWing.rotateAngle += 5
  77. if(leftWing.rotateAngle > 0):
  78. app.wingsMovingUp = False
  79. if(leftWing.rotateAngle < -40):
  80. app.wingsMovingup = True
  81.  
  82. ##### Place your code above this line, code below is for testing purposes #####
  83. # test case:
  84. onKeyHolds(['w'], 20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement