-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacmanClass.py
75 lines (61 loc) · 2.29 KB
/
pacmanClass.py
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
65
66
67
68
69
70
71
72
73
74
import turtle as t
window = t.Screen()
window.addshape('pacman/right.gif')
window.addshape('pacman/left.gif')
window.addshape('pacman/up.gif')
window.addshape('pacman/down.gif')
class Pacman:
def __init__(self):
self.pacman = t.Turtle()
self.pacman.shape("pacman/right.gif")
self.pacman.color("yellow")
self.pacman.penup()
self.pacman.speed(0)
self.pacman.goto(-25, 140)
self.pacman.direction = "stop"
self.pacman.shapesize(2, 2)
self.moveSpeed = 3.5
self.pacman.width = 35
self.pacman.height = 35
def goDown(self):
self.pacman.direction = "down"
self.pacman.shape("pacman/down.gif")
def goUp(self):
self.pacman.direction = "up"
self.pacman.shape("pacman/up.gif")
def goLeft(self):
self.pacman.direction = "left"
self.pacman.shape("pacman/left.gif")
def goRight(self):
self.pacman.direction = "right"
self.pacman.shape("pacman/right.gif")
def move(self):
if self.pacman.direction == "up":
y = self.pacman.ycor()
self.pacman.sety(y + self.moveSpeed)
elif self.pacman.direction == "down":
y = self.pacman.ycor()
self.pacman.sety(y - self.moveSpeed)
elif self.pacman.direction == "left":
x = self.pacman.xcor()
self.pacman.setx(x - self.moveSpeed)
elif self.pacman.direction == "right":
x = self.pacman.xcor()
self.pacman.setx(x + self.moveSpeed)
def distance(self, object):
return self.pacman.distance(object)
def getDirection(self):
return self.pacman.direction
def setDirection(self, direction):
self.pacman.direction = direction
def wallColission(self):
# print(self.getDirection())
if self.getDirection() == "up":
self.pacman.sety(self.pacman.ycor() - self.moveSpeed*1.3)
elif self.getDirection() == "down":
self.pacman.sety(self.pacman.ycor() + self.moveSpeed*1.3)
elif self.getDirection() == "left":
self.pacman.setx(self.pacman.xcor() + self.moveSpeed*1.3)
elif self.getDirection() == "right":
self.pacman.setx(self.pacman.xcor() - self.moveSpeed*1.3)
self.setDirection("stop")