-
Notifications
You must be signed in to change notification settings - Fork 0
/
movement.py
67 lines (49 loc) · 2.13 KB
/
movement.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
import settings
import sys,pygame
scalar_speed = settings.scalar_speed
Directions = {"Left": [-1*scalar_speed,0], "Right": [scalar_speed,0], "Up":[0,-1*scalar_speed], "Down": [0,scalar_speed]}
def edges(width,height,headrect,ghost,justJumped):
if headrect.left < 0 - justJumped:
#ghost = head.get_rect()
ghost.top = headrect.top
ghost.left = headrect.left
headrect.left = width + headrect.left
justJumped = headrect.width
if headrect.right > width + justJumped:
# ghost = head.get_rect()
ghost.top = headrect.top
ghost.left = headrect.left
headrect.right = headrect.right - width
justJumped = headrect.width
if headrect.top <0 - justJumped:
# ghost = head.get_rect()
ghost.top = headrect.top
ghost.left = headrect.left
headrect.top = height + headrect.top
justJumped = headrect.height
if headrect.bottom > height +justJumped:
# ghost = head.get_rect()
ghost.top = headrect.top
ghost.left = headrect.left
headrect.bottom = headrect.bottom - height
justJumped = headrect.height
if justJumped > 0 and headrect.left >= 0 and headrect.top >= 0 and headrect.right <= width and headrect.bottom <= height:
justJumped = 0
return ghost, justJumped
def getFacing(movementDirection):
for thisDirection in Directions:
if movementDirection == Directions[thisDirection]:
return thisDirection
def checkTurn(itemx, itemy ,turningPoints, oldSpeed):
turningpoint = turningPoints[0]
if abs(itemx - turningpoint[0]) < 2 and abs(itemy - turningpoint[1]) < 2 :
try:
if len(turningPoints) > 1 :
return turningPoints[1:], oldSpeed[1:]
else:
return list(), list() # when deleting the last turning point it returns this
except:
print("somewhere else")
return list(), list()
else:
return turningPoints, oldSpeed