-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedudefs.py
More file actions
44 lines (35 loc) · 954 Bytes
/
Copy pathedudefs.py
File metadata and controls
44 lines (35 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#Snake Head
import turtle
import random
head = turtle.Turtle()
head.speed(0)
head.shape("square")
head.color("black")
head.penup()
head.goto(0, 100)
head.direction = "stop"
def move():
if head.direction == "up":
y = head.ycor() #y coordinate of the turtle
head.sety(y + 20)
if head.direction == "down":
y = head.ycor() #y coordinate of the turtle
head.sety(y - 20)
if head.direction == "right":
x = head.xcor() #y coordinate of the turtle
head.setx(x + 20)
if head.direction == "left":
x = head.xcor() #y coordinate of the turtle
head.setx(x - 20)
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":
head.direction = "right"
def go_left():
if head.direction != "right":
head.direction = "left"