@@ -50,8 +50,8 @@ class CharacterSprite(pygame.sprite.DirtySprite):
50
50
"""A sprite for moving character sprites."""
51
51
52
52
def __init__ (self , screen , width , height , start_direction , direction ,
53
- stopped , start_location , spritesheet , collide_size ,
54
- collide_offset , speed_animate , speed_walk ):
53
+ stopped , start_location , spritesheet , collide_size , collide_offset ,
54
+ speed_animate , speed_walk ):
55
55
pygame .sprite .DirtySprite .__init__ (self )
56
56
self .screen = screen
57
57
self .window = screen .window
@@ -135,10 +135,10 @@ def move_check(self):
135
135
"""Check for walls, terrain, region, and random encounters."""
136
136
137
137
directions = {
138
- 'up' : self .collide_rect .move (0 , - self .movement ),
139
- 'down' : self .collide_rect .move (0 , self .movement ),
140
- 'left' : self .collide_rect .move (- self .movement , 0 ),
141
- 'right' : self .collide_rect .move (self .movement , 0 ) }
138
+ 'up' : self .collide_rect .move (0 , - self .movement ),
139
+ 'down' : self .collide_rect .move (0 , self .movement ),
140
+ 'left' : self .collide_rect .move (- self .movement , 0 ),
141
+ 'right' : self .collide_rect .move (self .movement , 0 ) }
142
142
for key , rect in directions .iteritems ():
143
143
self .check_walls (key , rect )
144
144
self .check_terrain (rect )
@@ -150,10 +150,8 @@ def check_walls(self, key, rect):
150
150
151
151
if pygame .Rect (rect ).collidelistall (self .map .nowalk ) != []:
152
152
self .collide [key ] = True
153
- if self .collide [self .direction ]:
154
- self .stop = True
155
- else :
156
- self .collide [key ] = False
153
+ if self .collide [self .direction ]: self .stop = True
154
+ else : self .collide [key ] = False
157
155
158
156
def check_terrain (self , rect ):
159
157
"""Check the type of terrain the sprite moved to."""
@@ -171,18 +169,21 @@ def check_region(self, rect):
171
169
for region in self .map .map_regions :
172
170
if pygame .Rect (rect ).collidelistall (
173
171
self .map .regions [region ]) != []:
174
- self .current_region = region
172
+ self .current_region = region
175
173
176
174
177
175
class PartySprite (CharacterSprite ):
178
176
"""A sprite for party characters."""
179
177
180
178
def __init__ (self , screen , hero , char ):
179
+ start_direction = screen .map .start_direction
181
180
self .face_small = load_image ("char" , "faces" , char + "_small" )
181
+ self .hero = hero
182
182
hero_position = (hero .rect [0 ], hero .rect [1 ])
183
183
self .position = (hero_position [0 ],hero_position [1 ]+ 32 )
184
184
CharacterSprite .__init__ (self , screen , CHAR_WIDTH , CHAR_HEIGHT ,
185
- "down" , None , True , self .position , char , (32 ,32 ), (32 ,32 ), 3 , 3 )
185
+ start_direction , None , True , self .position , char , (32 ,32 ),
186
+ (32 ,32 ), 3 , 3 )
186
187
187
188
188
189
class PlayerSprite (CharacterSprite ):
@@ -209,44 +210,32 @@ def move(self):
209
210
self .dirty = 1
210
211
direction = self .direction
211
212
map_rect = self .map .layers ['terrain' ].rect
212
- party = self .screen .party
213
213
if not self .collide [direction ]:
214
+
214
215
if direction == "up" :
215
216
if self .rect .centery < PLAYER_SCROLL_TOP and (
216
217
self .scroll_pos [1 ] < 0 ):
217
218
self .scroll_pos [1 ] += self .movement
218
219
self .map .move ([0 , self .movement ])
219
- else :
220
- for char in party .chars :
221
- party .chars [char ].dirty = 1
222
- party .chars [char ].rect .move_ip (0 , - self .movement )
220
+ else : self .rect .move_ip (0 , - self .movement )
223
221
elif direction == "down" :
224
222
if self .rect .centery > PLAYER_SCROLL_BOTTOM and (
225
223
map_rect .height + self .scroll_pos [1 ] > CAMERA_SIZE [1 ]):
226
224
self .scroll_pos [1 ] -= self .movement
227
225
self .map .move ([0 , - self .movement ])
228
- else :
229
- for char in party .chars :
230
- party .chars [char ].dirty = 1
231
- party .chars [char ].rect .move_ip (0 , self .movement )
226
+ else : self .rect .move_ip (0 , self .movement )
232
227
elif direction == "left" :
233
228
if self .rect .centerx < PLAYER_SCROLL_LEFT and (
234
229
self .scroll_pos [0 ] < 0 ):
235
230
self .scroll_pos [0 ] += self .movement
236
231
self .map .move ([self .movement , 0 ])
237
- else :
238
- for char in party .chars :
239
- party .chars [char ].dirty = 1
240
- party .chars [char ].rect .move_ip (- self .movement , 0 )
232
+ else : self .rect .move_ip (- self .movement , 0 )
241
233
elif direction == "right" :
242
234
if self .rect .centerx > PLAYER_SCROLL_RIGHT and (
243
235
map_rect .width + self .scroll_pos [0 ] > CAMERA_SIZE [0 ]):
244
236
self .scroll_pos [0 ] -= self .movement
245
237
self .map .move ([- self .movement , 0 ])
246
- else :
247
- for char in party .chars :
248
- party .chars [char ].dirty = 1
249
- party .chars [char ].rect .move_ip (self .movement , 0 )
238
+ else : self .rect .move_ip (self .movement , 0 )
250
239
251
240
def check_encounter (self ):
252
241
"""Check for a random encounter."""
0 commit comments