Changeset 152:60138b935bc0


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

Make enemies block by default, so we can jump off them

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/physics.py

    r146 r152  
    3636
    3737    floor = False  # We special case collisions with ground objects
     38    block = False
    3839
    3940    def __init__(self, *args, **kwargs):
    4041        super(Sprite, self).__init__(*args, **kwargs)
    41         self.on_ground = False
     42        self.on_solid = False
    4243        self.velocity = (0.0, 0.0)
    4344        self.rect = pygame.Rect(0, 0, 10, 10) # sub-classes should override
     
    104105        dv_y = - normal[1] * b_y * v_y
    105106
    106         if normal == (0, 1) and other.floor and v_y > 0 and self.collide_rect.top < other.collide_rect.top:
     107        if normal == (0, 1) and (other.floor or other.block) and v_y > 0 and self.collide_rect.top < other.collide_rect.top:
    107108            # Colliding with the ground from above is special
    108             self.on_ground = True
     109            self.on_solid = True
    109110            dv_y = -v_y
    110111
     
    195196        dv = self.GRAVITY[0] * dt, self.GRAVITY[1] * dt
    196197        for sprite in self._gravitators:
    197             if sprite.on_ground:
     198            if sprite.on_solid:
    198199                sprite.deltav((dv[0], 0.0))
    199200            else:
     
    215216            if collisions:
    216217                self._backout_collisions(sprite, collisions, dt)
    217             if sprite.on_ground:
     218            contact_rect = pygame.Rect(
     219                    (sprite.collide_rect.left, sprite.collide_rect.bottom),
     220                    (sprite.collide_rect.width, 1))
     221            collides = contact_rect.colliderect
     222            if sprite.on_solid:
    218223                # Check if we are still in contact with the ground
    219                 contact_rect = sprite.collide_rect.move((0, 1))
    220                 collides = contact_rect.colliderect
    221                 still_on_ground = False
     224                still_on_solid = False
    222225                for other in self._collision_groups[sprite.collision_layer]:
    223                     if other.floor and collides(other.collide_rect):
    224                         still_on_ground = True
     226                    if (other.floor or other.block) and collides(other.collide_rect):
     227                        still_on_solid = True
    225228                        break
    226                 sprite.on_ground = still_on_ground
     229                sprite.on_solid = still_on_solid
    227230            else:
    228231                # Are we currently in contact with the groun
    229                 contact_rect = pygame.Rect(
    230                         (sprite.collide_rect.left, sprite.collide_rect.bottom -1),
    231                         (sprite.collide_rect.width, 1))
    232                 collides = contact_rect.colliderect
    233232                for other in self._collision_groups[sprite.collision_layer]:
    234                     if other.floor and collides(other.collide_rect):
    235                         sprite.on_ground = True
     233                    if (other.floor or other.block) and collides(other.collide_rect):
     234                        sprite.on_solid = True
    236235                        break
    237 
    238236
    239237        # call update methods
  • skaapsteker/sprites/base.py

    r144 r152  
    2222
    2323    debug_color = (240, 120, 120)
     24
     25    block = True
    2426
    2527    def __init__(self, pos, **opts):
  • skaapsteker/sprites/player.py

    r151 r152  
    8080    def set_pos(self, pos):
    8181        self.starting_tile_pos = pos
    82         self.rect.topleft = pos[0] * TILE_SIZE[0] + self.rect_offset[0], pos[1] * TILE_SIZE[1] + self.rect_offset[1]
    83         self.collide_rect.topleft = pos[0] * TILE_SIZE[0], pos[1] * TILE_SIZE[1]
     82        self.rect.midbottom = pos[0] * TILE_SIZE[0] + self.rect_offset[0], pos[1] * TILE_SIZE[1] + self.rect_offset[1]
     83        self.collide_rect.midbottom = pos[0] * TILE_SIZE[0], pos[1] * TILE_SIZE[1]
    8484
    8585    def action_left(self):
     
    9696
    9797    def action_up(self):
    98         if self.on_ground:
     98        if self.on_solid:
    9999            self.deltav((0.0, -350.0))
    100             self.on_ground = False
     100            self.on_solid = False
    101101
    102102    def action_down(self):
Note: See TracChangeset for help on using the changeset viewer.