This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # move o segmento final, na ordem reversa | |
| for index in range(len(segments)-1, 0, -1): | |
| x = segments[index-1].xcor() | |
| y = segments[index-1].ycor() | |
| segments[index].goto(x, y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # adicionar um segmento | |
| new_segment = turtle.Turtle() | |
| new_segment.speed(0) | |
| new_segment.shape("square") | |
| new_segment.color("grey") | |
| new_segment.penup() | |
| segments.append(new_segment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| segments = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if head.distance(food) < 15: | |
| # Move a comida para uma posição aleatória na tela | |
| x = random.randint(-290, 290) | |
| y = random.randint(-290, 290) | |
| food.goto(x, y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Comida para a Cobra | |
| food = turtle.Turtle() | |
| food.speed(0) | |
| food.shape("circle") | |
| food.color("red") | |
| food.penup() | |
| food.shapesize(0.50, 0.50) | |
| food.goto(0, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # observador do teclado | |
| win.listen() | |
| win.onkey(go_up, "w") | |
| win.onkey(go_down, "s") | |
| win.onkey(go_right, "d") | |
| win.onkey(go_left, "a") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def go_up(): | |
| if head.direction != "down": | |
| head.direction = "up" | |
| def go_down(): | |
| if head.direction != "up": | |
| head.direction = "down" | |
| def go_right(): | |
| if head.direction != "left": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import turtle | |
| import time | |
| delay=0.1 | |
| # Loop Principal | |
| while True: | |
| wn.update() | |
| move() | |
| time.sleep(delay) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Loop Principal | |
| while: True | |
| win.update() | |
| move() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def move(): | |
| if head.direction == "up": | |
| y = head.ycor() # coordenada y da turtle | |
| head.sety(y + 20) | |
| if head.direction == "down": | |
| y = head.ycor() # coordenada y da turtle | |
| head.sety(y - 20) | |
| if head.direction == "right": |