Advertisement
Aristarkh_Bakhirev

Untitled

Mar 20th, 2020
1,721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import turtle
  2. import math
  3.  
  4. window = turtle.Screen()
  5. window.setup(1015, 768)
  6. window.bgpic("images/background.png")
  7. window.screensize(1015, 768)
  8. # window.tracer(n=2)
  9.  
  10. BASE_X, BASE_Y = 0, -300
  11.  
  12. def calc_heading(x1, y1, x2, y2):
  13.     dx = x2 - x1
  14.     length = (dx ** 2 + (y2-y1) ** 2) ** 0.5
  15.     cos_alpha = dx / length
  16.     alpha = math.acos(cos_alpha)
  17.     alpha = math.degrees(alpha)
  18.     return alpha
  19.  
  20. def fire_missile(x, y):
  21.     missile = turtle.Turtle()
  22.     missile.speed(0)
  23.     missile.color('white')
  24.     missile.penup()
  25.     missile.setpos(x=BASE_X, y=BASE_Y)
  26.     missile.pendown()
  27.     heading = calc_heading(x1=BASE_X, y1=BASE_Y, x2=x, y2=y)
  28.     missile.setheading(heading)
  29.     missile.showturtle()
  30.     # missile.forward(500)
  31.     # missile.shape('circle')
  32.     # missile.shapesize(2)
  33.     # missile.shapesize(3)
  34.     # missile.shapesize(4)
  35.     # missile.shapesize(5)
  36.     # missile.clear()
  37.     # missile.hideturtle()
  38.     our_missiles.append(missile)
  39.     our_missiles_target.append(x, y)
  40.  
  41.  
  42. window.onclick(fire_missile)
  43.  
  44. our_missiles = []
  45. our_missiles_target = []
  46.  
  47. while True:
  48.     window.update()
  49.  
  50.     for num, missile in enumerate(our_missiles):
  51.         missile.forward(4)
  52.         target = our_missiles_target[num]
  53.         if missile.distance(x=target[0], y=target[1]) < 20:
  54.             missile.forward(500)
  55.             missile.shape('circle')
  56.             missile.shapesize(2)
  57.             missile.shapesize(3)
  58.             missile.shapesize(4)
  59.             missile.shapesize(5)
  60.             missile.clear()
  61.             missile.hideturtle()
  62.  
  63. Help me find the error in the code. Thanks in advance
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement