Mercurial > skaapsteker
comparison skaapsteker/physics.py @ 629:59556235dec7
Clean up some leftover mess from collision handling work.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 07 May 2011 20:43:12 +0200 |
parents | 35919d12b792 |
children |
comparison
equal
deleted
inserted
replaced
628:1fdfc7f03d98 | 629:59556235dec7 |
---|---|
306 for col in collisions: | 306 for col in collisions: |
307 if sprite.block and (col.floor or col.block): | 307 if sprite.block and (col.floor or col.block): |
308 escape_vector = cabsmax(escape_vector, rect_projection(sprite.collide_rect, col.collide_rect)) | 308 escape_vector = cabsmax(escape_vector, rect_projection(sprite.collide_rect, col.collide_rect)) |
309 sprite.collided(col) | 309 sprite.collided(col) |
310 sprite.update_position(cadd(sprite._float_pos, escape_vector)) | 310 sprite.update_position(cadd(sprite._float_pos, escape_vector)) |
311 # if escape_vector[0] != 0: | |
312 # sprite.velocity = (0, sprite.velocity[1]) | |
313 # if escape_vector[1] != 0: | |
314 # sprite.velocity = (sprite.velocity[0], 1) | |
315 # self._backout_collisions(sprite, collisions, dtf) | |
316 contact_rect = pygame.Rect( | |
317 cadd(sprite.collide_rect.bottomleft, (1, 0)), | |
318 (sprite.collide_rect.width, 1)) | |
319 return contact_rect.colliderect | |
320 | 311 |
321 | 312 |
322 def update_sprite_positions(self, dt): | 313 def update_sprite_positions(self, dt): |
323 # position update and collision check (do last) | 314 # position update and collision check (do last) |
324 for sprite in self._mobiles: | 315 for sprite in self._mobiles: |
325 collides = self.collide_sprite(dt, sprite) | 316 self.collide_sprite(dt, sprite) |
326 | 317 |
327 # Are we currently in contact with the ground? | 318 # Are we currently in contact with the ground? |
328 if not sprite.block: | 319 if not sprite.block: |
329 continue | 320 continue |
321 contact_rect = pygame.Rect( | |
322 cadd(sprite.collide_rect.bottomleft, (4, 0)), | |
323 (sprite.collide_rect.width - 8, 1)) | |
330 floors = [] | 324 floors = [] |
331 sprite.on_solid = False | 325 sprite.on_solid = False |
332 for other in self._collision_groups[sprite.collision_layer]: | 326 for other in self._collision_groups[sprite.collision_layer]: |
333 if (other.floor or other.block) and collides(other.floor_rect): | 327 if (other.floor or other.block) and contact_rect.colliderect(other.floor_rect): |
334 sprite.on_solid = True | 328 sprite.on_solid = True |
335 if sprite.velocity[1] > 0: | 329 if sprite.velocity[1] > 0: |
336 sprite.velocity = (sprite.velocity[0], 0) | 330 sprite.velocity = (sprite.velocity[0], 0) |
337 floors.append(other) | 331 floors.append(other) |
338 sprite.check_floors(floors) | 332 sprite.check_floors(floors) |