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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
import pygame
import sys
from mazeSetup import mazeSetup
class basicMovement(pygame.sprite.Sprite):
def __init__(self, position):
pygame.sprite.Sprite.__init__(self)
self.moving = False
def getMoving(self):
#for moving until the character reaches an intersection
return self.moving
def update(self, screen, character, amount, MAZE_SIZE, mazeObj):
pacmanEvent = 0
# Make a copy of the current rectangle for use in erasing
character.old = character.rect
# Move the rectangle by the specified amount
character.rect = character.rect.move(amount)
#check to see which direction the char is heading
dx = character.rect.x - character.old.x
dy = character.rect.y - character.old.y
#variable for subtracting or adding (depending on the headin)
#to the position so we are at the front of the rect
headingDiffX = 0
headingDiffY = 0
#so the ghost can leave their starting place but neither they or
#pacman can get back in
up = False
#if self.moving == False:
if dx != 0:
if dx > 0:
#going right
headingDiffX = character.rect.width - 1
#headingDiffY = character.rect.height/2
elif dx < 0:
#going left
headingDiffX = 1 #because we're already using the top left
#headingDiffY = character.rect.height/2
elif dy != 0:
if dy > 0:
#going down
headingDiffY = character.rect.height - 1
#headingDiffX = character.rect.width/2
elif dy < 0:
#going up
up = True
headingDiffY = 1 #because we're already using the top left
#headingDiffX = character.rect.width/2
gridX = int(round( ( (character.rect.x+headingDiffX)/MAZE_SIZE), 0) )
gridY = int(round( ( (character.rect.y+headingDiffY)/MAZE_SIZE), 0) )
#for redrawing the grid positions the ghost went over
ghostRedraw = False
# Check to see if we are heading into an invlaid grid cell
grid = mazeObj.maze.getGrid()
if grid[gridX][gridY] == mazeObj.maze.EMPTY:
#0
#it's able to be moved into
#check to see if the player should get points for collecting
#a regular pellet or if the pellet has already been collected
placeHolder = 0
elif grid[gridX][gridY] == mazeObj.maze.SOLID:
#1
#wall
character.rect.x = character.old.x
character.rect.y = character.old.y
#wall, stop moving
self.moving = False
elif grid[gridX][gridY] == mazeObj.maze.OFFL:
#2
#off limits, essentially a wall
if up == False:
character.rect.x = character.old.x
character.rect.y = character.old.y
#off limits, stop moving
self.moving = False
elif grid[gridX][gridY] == mazeObj.maze.PELLET:
#3
#regular pellet
#get points (enought points, then extra life, maybe check elsewhere)
if character.name == 'PacMath':
#change the grid to empty
grid[gridX][gridY] = mazeObj.maze.EMPTY
pacmanEvent = 1
else:
placeHolder = 0
ghostRedraw = True
elif grid[gridX][gridY] == mazeObj.maze.PPL:
#4
#power pellet
#show question and blink screen (or something)
if character.name == 'PacMath':
#if pacmath has eaten a power pellet
character.ppl = True
#change the grid to empty
grid[gridX][gridY] = mazeObj.maze.EMPTY
#check how many power pellets pacman has eaten
pacmanEvent = 2
else:
placeHolder = 0
ghostRedraw = True
elif grid[gridX][gridY] == mazeObj.maze.PELLET_INT:
#5
if character.name == 'PacMath':
#change the grid to empty
grid[gridX][gridY] = mazeObj.maze.EMPTY_INT
else:
placeHolder = 0
ghostRedraw = True
#intersection, stop moving
self.moving = False
elif grid[gridX][gridY] == mazeObj.maze.EMPTY_INT:
#6
#intersection, stop moving
self.moving = False
else:
#anything else
#for now this should be off limits so don't move
character.rect.x = character.old.x
character.rect.y = character.old.y
#off limits, stop moving
self.moving = False
return pacmanEvent
|