Changeset 186:72e92893ccb8


Ignore:
Timestamp:
04/06/11 18:49:47 (12 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Message:

Use layers for floor check

Location:
skaapsteker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/physics.py

    r177 r186  
    4545        self.rect = pygame.Rect(0, 0, 10, 10) # sub-classes should override
    4646        self.collide_rect = pygame.Rect(0, 0, 10, 10) # rectangle we use for collisions
     47        self.floor_rect = self.collide_rect
    4748        self.image = pygame.Surface((10, 10))
    4849        self.image.fill((0, 0, 200))
     
    8485        delta_pos = self.rect.left - old_pos[0], self.rect.top - old_pos[1]
    8586        self.collide_rect.move_ip(delta_pos)
     87        self.floor_rect.move_ip(delta_pos)
    8688
    8789    def _check_mask(self):
     
    268270                still_on_solid = False
    269271                for other in self._collision_groups[sprite.collision_layer]:
    270                     if (other.floor or other.block) and collides(other.collide_rect):
     272                    if (other.floor or other.block) and collides(other.floor_rect):
    271273                        still_on_solid = True
    272274                        break
     
    275277                # Are we currently in contact with the ground
    276278                for other in self._collision_groups[sprite.collision_layer]:
    277                     if (other.floor or other.block) and collides(other.collide_rect):
     279                    if (other.floor or other.block) and collides(other.floor_rect):
    278280                        sprite.on_solid = True
    279281                        break
  • skaapsteker/sprites/base.py

    r174 r186  
    3131        self.rect = self.image.get_rect(midbottom=(pos[0]*TILE_SIZE[0]+TILE_SIZE[0]/2, (pos[1]+1)*TILE_SIZE[1]))
    3232        self.collide_rect = self.rect.move(0, 0)
     33        self.floor_rect = Rect(self.collide_rect.topleft, (self.collide_rect.width, 2))
    3334        self._layer = Layers.PLAYER
    3435        self.setup(**opts)
     
    8384        self.image = image
    8485        self.collide_rect = self.image.get_bounding_rect(1)
     86        self.floor_rect = Rect(self.collide_rect.topleft, (self.collide_rect.width, 2))
    8587        self.rect = self.image.get_rect()
    8688        self.rect_offset = self.collide_rect.left - self.rect.left, self.rect.top - self.rect.top
    8789        self.collide_rect.topleft = pos[0] * TILE_SIZE[0] + self.rect_offset[0], pos[1] * TILE_SIZE[1] + self.rect_offset[1]
     90        self.floor_rect.topleft = pos[0] * TILE_SIZE[0] + self.rect_offset[0], pos[1] * TILE_SIZE[1] + self.rect_offset[1]
    8891        self.rect.topleft = pos[0] * TILE_SIZE[0], pos[1] * TILE_SIZE[1]
    8992
Note: See TracChangeset for help on using the changeset viewer.