Changeset 149:5b4d73d301a1


Ignore:
Timestamp:
Apr 5, 2011, 3:35:14 PM (9 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Don't change image if it will introduce new collisions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/player.py

    r148 r149  
    2222        self._image_dict = {}
    2323        self._animation_frame = 0.0
     24        self._recent_collisions = []
    2425        # State flags and such
    2526        self.running = False
     
    4344        else:
    4445            cur_pos = (0, 0)
     46        cand_image = images[int(self._animation_frame)]
     47        cand_collide_rect = cand_image.get_bounding_rect(1)
     48        cand_collide_rect.bottomleft = cur_pos
     49        if cand_collide_rect.collidelist(self._recent_collisions) != -1 \
     50                and self.collide_rect.collidelist(self._recent_collisions) == -1:
     51            # We introduce a new collision, so don't update the image
     52            return
    4553        self.image = images[int(self._animation_frame)]
     54        self.collide_rect = self.image.get_bounding_rect(1)
    4655        self.rect = self.image.get_rect()
    47         self.collide_rect = self.image.get_bounding_rect(1)
    4856        self.rect_offset = self.rect.left - self.collide_rect.left, self.rect.bottom - self.collide_rect.bottom
    4957        self.collide_rect.bottomleft = cur_pos
     
    6573        self.facing = new_facing
    6674
     75    def collided(self, other):
     76        self._recent_collisions.append(other.collide_rect)
     77        while len(self._recent_collisions) > 10:
     78            self._recent_collisions.pop(0)
    6779
    6880    def set_pos(self, pos):
Note: See TracChangeset for help on using the changeset viewer.