Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- import time
- import random
- wn = turtle.Screen()
- wn.title("They fall, @Pissa6947, code my by Christian Thompson")
- wn.bgcolor("green")
- wn.setup(width=800, height=600)
- wn.tracer(0)
- # Add the player
- player = turtle.Turtle()
- player.speed(0)
- player.shape("square")
- player.color("white")
- player.penup()
- player.goto(0, -250)
- player.direction = "stop"
- # create a list for Charlie's
- Charlies = []
- # Add the Charlie
- for _ in range(20):
- Charlie = turtle.Turtle()
- Charlie.speed(0)
- Charlie.shape("circle")
- Charlie.color("pink")
- Charlie.penup()
- Charlie.goto(0, 250)
- Charlies.append(Charlies)
- # Functions
- def go_left():
- player.direction = "left"
- def go_right():
- player.direction = "right"
- wn.listen()
- wn.onkeypress(go_left, "Left")
- wn.onkeypress(go_right, "Right")
- # Main game loop
- while True:
- time.sleep(0.1)
- # Update screen
- wn.update()
- # Move the player
- if player.direction == "left":
- x = player.xcor()
- x -= 3
- player.setx(x)
- if player.direction == "right":
- x = player.xcor()
- x += 3
- player.setx(x)
- # move Charlie
- for Charlie in Charlies:
- y = Charlie.ycor()
- y -= 3
- Charlie.sety(y)
- # check if Charlie is of screen
- if y < -300:
- x = random.randint(-380, 380)
- y = random.randint(-300, 400)
- Charlie.goto(0, 250)
- # check for a collision with the player
- if Charlie.distance(player) < 20:
- x = random.randint(-380, 380)
- y = random.randint(-300, 400)
- Charlie.goto(x, y)
- wn.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement