Advertisement
Vladkoheca

Galaxy Invaders

Feb 29th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from turtle import *
  2.  
  3. t = Turtle()
  4. t.up()
  5. t.shapesize(2)
  6. t.tilt(90)
  7. t.speed(0)
  8. t.goto(0, -240)
  9. delay(0)
  10. bullets = []
  11. aliens = []
  12. a1 = Turtle()
  13. a1.speed(0)
  14. a1.shape("square")
  15. a1.shapesize(1)
  16. a1.up()
  17. a1.goto(0,280)
  18. aliens.append(a1)
  19.  
  20.  
  21.  
  22. def move_left():
  23.     t.bk(10)
  24.  
  25. def move_right():
  26.     t.fd(10)
  27.  
  28. def shoot():
  29.     bullet = Turtle()
  30.     bullet.speed(0)
  31.     bullet.up()
  32.     bullet.shape("circle")
  33.     bullet.goto(t.xcor(), t.ycor())
  34.     bullet.setheading(90)
  35.     bullets.append(bullet)
  36.     bullet.shapesize(0.6)
  37.  
  38. def rozovo():
  39.     t.color("pink")
  40.  
  41. def gameplay():
  42.     for x in bullets:
  43.         x.fd(10)
  44.         if x.ycor() >300:
  45.             x.hideturtle()
  46.             bullets.remove(x)
  47.     for x in aliens:
  48.         x.fd(10)
  49.         if x.xcor()>450:
  50.             x.setx(-450)
  51.             x.sety(x.ycor()-30)
  52.  
  53.  
  54.     ontimer(gameplay,100 )
  55.  
  56. onkeypress(move_left, "Left")
  57. onkeypress(move_right, "Right")
  58. onkeypress(shoot, "space")
  59. onkeypress(rozovo,"q")
  60. listen()
  61. gameplay()
  62.  
  63. done()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement