Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- from turtle import *
- sc = Screen()
- sc.setup(500, 620)
- can_shoot = True
- alien_speed = 5;
- delay(0)
- t = Turtle()
- t.up()
- t.shapesize(2)
- t.tilt(90)
- t.speed(0)
- t.goto(0, -280)
- bullets = []
- enemies = []
- def create_aliens():
- for j in range(3):
- for i in range(8):
- bad = Turtle()
- bad.speed(0)
- bad.up()
- bad.goto(-250 + i * 40, 250 -40*j)
- bad.color("green")
- bad.shape("square")
- enemies.append(bad)
- create_aliens()
- counter = 0
- def move():
- global alien_speed, counter
- counter += 1
- if counter > 20:
- counter = 0
- if counter %2 == 0:
- for i in bullets:
- i.fd(15) # forward = fd
- if i.ycor() > 300:
- i.hideturtle()
- bullets.remove(i)
- # proverka za sblusuk
- for y in enemies:
- if (y.xcor() - 10) < i.xcor() < (y.xcor() + 10) and (y.ycor() - 13) < i.ycor() < (y.ycor() + 13):
- y.hideturtle()
- enemies.remove(y)
- i.hideturtle()
- bullets.remove(i)
- # boom
- if len(enemies)<1:
- if alien_speed > 1:
- alien_speed -= 1
- create_aliens()
- # aliens movement
- if counter %alien_speed == 0:
- for bad in enemies:
- if bad.xcor() > 250 or bad.xcor() < -250:
- for badx in enemies:
- badx.sety(badx.ycor() - 20)
- badx.left(180)
- break
- for bad in enemies:
- bad.fd(5)
- ontimer(move, 5)
- def move_left():
- t.bk(10)
- def move_right():
- t.fd(10)
- def allow_shoot():
- global can_shoot
- can_shoot = True
- def shoot():
- global can_shoot
- if can_shoot:
- s = Turtle()
- s.shape("circle")
- s.speed(0)
- s.shapesize(0.5)
- s.up()
- s.left(90)
- s.goto(t.xcor(), t.ycor())
- bullets.append(s)
- can_shoot = False
- ontimer(allow_shoot, 100)
- sc.onkeypress(move_left, "Left")
- sc.onkeypress(move_right, "Right")
- sc.onkey (shoot, "space")
- sc.listen()
- move()
- done()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement