Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import turtle as t
- #Creating the snake
- caterpillar = t.Turtle()
- caterpillar.shape('square')
- caterpillar.color('red')
- caterpillar.speed(0)
- caterpillar.penup()
- caterpillar.hideturtle()
- # Creating the powerup
- leaf = t.Turtle()
- leaf_shape = ((0,0), (14,2), (18,6), (20,20), (6,18), (2,14))
- t.register_shape('leaf', leaf_shape)
- leaf.shape('leaf')
- leaf.color('green')
- leaf.penup()
- leaf.hideturtle()
- leaf.speed(0)
- # Settling our score
- game_started = False
- text_turtle = t.Turtle()
- text_turtle.write('Press SPACE to start', align = 'center', font ('Arial',16,'bold'))
- text_turtle.hideturtle()
- score_turtle - t.Turtle()
- score_turtle.hideturtle()
- score_turtle.speed(0)
- # Game functions
- def outside_window():
- pass
- def game_over():
- pass
- def display_score(current_score):
- pass
- def place_leaf():
- pass
- def start_game():
- global game_started
- if game_started:
- return
- game_started = true
- score = 0
- text_turtle.clear()
- caterpillar_speed = 2
- caterpillar_length = 3
- caterpillar.shapesize(1, caterpillar_length, 1)
- caterpillar.showturtle()
- display_score(score)
- place_leaf()
- # Game Drivers
- while True:
- caterpillar.forward(caterpillar_speed)
- if caterpillar.distance(leaf) < 20:
- place_leaf()
- caterpillar_length = caterpillar_length + 1
- caterpillar_speed = caterpillar_speed + 1
- score = score + 10
- display_score(score)
- if outside_window():
- game_over()
- break
- t.onkey(start_game, 'space')
- t.listen()
- t.mainloop()
- score_turtle - t.Turtle()
- text_turtle.write('Press SPACE to start', align = 'center', font ('Arial',16,'bold'))
- score_turtle = t.Turtle()
- text_turtle.write('Press SPACE to start', align='center', font=('Arial',16,'bold'))
- from turtle import Turtle, Screen
- # Game functions
- def outside_window():
- return False # implement this for real
- def game_over():
- pass # implement this for real
- def display_score(current_score):
- pass # implement this for real
- def place_leaf():
- leaf.hideturtle()
- leaf.goto(100, 100) # implement this for real
- leaf.showturtle()
- def start_game():
- global score
- global caterpillar_speed
- global caterpillar_length
- screen.onkey(None, 'space')
- score = 0
- text_turtle.clear()
- caterpillar_speed = 2
- caterpillar_length = 3
- caterpillar.shapesize(1, caterpillar_length, 1)
- caterpillar.showturtle()
- display_score(score)
- place_leaf()
- crawl()
- # Game Drivers
- def crawl():
- global score
- global caterpillar_speed
- global caterpillar_length
- caterpillar.forward(caterpillar_speed)
- if caterpillar.distance(leaf) < 20:
- place_leaf()
- caterpillar_speed = caterpillar_speed + 1
- caterpillar_length = caterpillar_length + 1
- caterpillar.shapesize(1, caterpillar_length, 1)
- score = score + 10
- display_score(score)
- if outside_window():
- game_over()
- else:
- screen.ontimer(crawl, 100)
- screen = Screen()
- # Creating the powerup
- leaf_shape = ((0, 0), (14, 2), (18, 6), (20, 20), (6, 18), (2, 14))
- screen.register_shape('leaf', leaf_shape)
- leaf = Turtle('leaf', visible=False)
- leaf.color('green')
- leaf.speed('fastest')
- leaf.penup()
- # Creating the caterpillar
- caterpillar = Turtle('square', visible=False)
- caterpillar.color('red')
- caterpillar.speed('fastest')
- caterpillar.penup()
- # Settling our score
- text_turtle = Turtle(visible=False)
- text_turtle.write('Press SPACE to start', align='center', font=('Arial', 16, 'bold'))
- score_turtle = Turtle(visible=False)
- screen.onkey(start_game, 'space')
- screen.listen()
- screen.mainloop()
Add Comment
Please, Sign In to add comment