-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcatandmouse.py
More file actions
64 lines (48 loc) · 995 Bytes
/
catandmouse.py
File metadata and controls
64 lines (48 loc) · 995 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import turtle
cat = turtle.Pen()
mouse = turtle.Pen()
distance = 30
def move(player):
player.forward(distance)
if cat.distance(mouse) < 10:
mouse.hideturtle()
cat.circle(100)
def catright():
cat.setheading(0)
move(cat)
def catup():
cat.setheading(90)
move(cat)
def catleft():
cat.setheading(180)
move(cat)
def catdown():
cat.setheading(270)
move(cat)
def mouseright():
mouse.setheading(0)
move(mouse)
def mouseup():
mouse.setheading(90)
move(mouse)
def mouseleft():
mouse.setheading(180)
move(mouse)
def mousedown():
mouse.setheading(270)
move(mouse)
turtle.onkey(catup, "Up")
turtle.onkey(catdown, "Down")
turtle.onkey(catleft, "Left")
turtle.onkey(catright, "Right")
turtle.onkey(mouseup, "z")
turtle.onkey(mousedown, "s")
turtle.onkey(mouseleft, "q")
turtle.onkey(mouseright, "d")
cat.color("red")
cat.penup()
mouse.color("green")
mouse.penup()
mouse.forward(distance * 3)
turtle.listen()
turtle.mainloop()