Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- import time
- delay = 0.1
- # setup screen
- wn = turtle.Screen()
- wn.title("Shooter Co-op")
- wn.bgcolor("black")
- wn.setup(width=600, height=600)
- wn.tracer(0)
- head = turtle.Turtle()
- head.speed(0.1)
- head.shape("square")
- head.color("blue")
- head.penup()
- head.goto(0, -200)
- head.direction = "stop"
- head2 = turtle.Turtle()
- head2.speed(0.1)
- head2.shape("square")
- head2.color("yellow")
- head2.penup()
- head2.goto(0, 200)
- head2.direction = "stop"
- new_wall = turtle.Turtle()
- new_wall.speed(0)
- new_wall.color("grey")
- new_wall.goto(-300, 0)
- new_wall.shape("triangle")
- new_wall2 = turtle.Turtle()
- new_wall2.speed(0)
- new_wall2.color("grey")
- new_wall2.shape("triangle")
- new_wall2.goto(300, 0)
- bullet = turtle.Turtle()
- bullet.speed(0)
- bullet.shape("triangle")
- bullet.setheading(90)
- bullet.color("red")
- bullet.hideturtle()
- bullet.penup()
- bulletspeed = 30
- bullet.shapesize(0.5, 0.5)
- bullet2 = turtle.Turtle()
- bullet2.speed(0)
- bullet2.shape("triangle")
- bullet2.setheading(270)
- bullet2.color("red")
- bullet2.hideturtle()
- bullet2.penup()
- bullet2speed = - 30
- bullet2.shapesize(0.5, 0.5)
- bullet2state = "ready"
- def fire_bullet2():
- global bullet2state
- if bullet2state == "ready":
- bullet2state = "fire"
- x = head2.xcor()
- y = head2.ycor() - 10
- bullet2.setposition(x, y)
- bullet2.showturtle()
- wn.listen()
- wn.onkeypress(fire_bullet2, "space")
- bulletstate = "ready"
- def fire_bullet():
- global bulletstate
- if bulletstate == "ready":
- bulletstate = "fire"
- x = head.xcor()
- y = head.ycor() + 10
- bullet.setposition(x, y)
- bullet.showturtle()
- wn.listen()
- wn.onkeypress(fire_bullet, "p")
- def go_up():
- head.direction = "up"
- def go_down():
- head.direction = "down"
- def go_left():
- head.direction = "left"
- def go_right():
- head.direction = "right"
- def move():
- if head.direction == "up":
- y = head.ycor()
- head.sety(y + 20)
- if head.direction == "down":
- y = head.ycor()
- head.sety(y - 20)
- if head.direction == "left":
- x = head.xcor()
- head.setx(x - 20)
- if head.direction == "right":
- x = head.xcor()
- head.setx(x + 20)
- wn.listen()
- wn.onkeypress(go_up, "i")
- wn.onkeypress(go_down, "k")
- wn.onkeypress(go_left, "j")
- wn.onkeypress(go_right, "l")
- def go_up1():
- head2.direction = "up"
- def go_down1():
- head2.direction = "down"
- def go_left1():
- head2.direction = "left"
- def go_right1():
- head2.direction = "right"
- def move1():
- if head2.direction == "up":
- y = head2.ycor()
- head2.sety(y + 20)
- if head2.direction == "down":
- y = head2.ycor()
- head2.sety(y - 20)
- if head2.direction == "left":
- x = head2.xcor()
- head2.setx(x - 20)
- if head2.direction == "right":
- x = head2.xcor()
- head2.setx(x + 20)
- wn.listen()
- wn.onkeypress(go_up1, "w")
- wn.onkeypress(go_down1, "s")
- wn.onkeypress(go_left1, "a")
- wn.onkeypress(go_right1, "d")
- while True:
- wn.update()
- move()
- move1()
- time.sleep(delay)
- if bulletstate == "fire":
- y = bullet.ycor()
- y += bulletspeed
- bullet.sety(y)
- if bullet.ycor() > 300:
- bullet.hideturtle()
- bulletstate = "ready"
- if head.ycor() > 0:
- head.hideturtle()
- if head2.ycor() < 0:
- head2.hideturtle()
- if head.ycor() > 0:
- head.hideturtle()
- if bullet.distance(head2) < 20:
- head2.hideturtle()
- if bullet2state == "fire":
- y = bullet2.ycor()
- y += bullet2speed
- bullet2.sety(y)
- if bullet2.ycor() < -300:
- bullet2.hideturtle()
- bullet2state = "ready"
- if bullet2.distance(head) < 20:
- head.hideturtle()
- wn.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement