Changeset 271:56a529a69e97


Ignore:
Timestamp:
04/08/11 15:26:06 (12 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Rebase:
33626265386564363830313531346131313636653933346232353663666463313938666431353837
Message:

Only backout / move-off "solid" collisions

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/physics.py

    r267 r271  
    207207
    208208    def _backout_collisions(self, sprite, others, dt):
    209         frac, normal, idx = -1.0, None, None
     209        frac, normal, idx = 0.0, None, None
    210210        v_x, v_y = sprite.velocity
    211211        abs_v_x, abs_v_y = abs(v_x), abs(v_y)
    212212
    213         for i, other in enumerate(others):
    214             clip = sprite.collide_rect.clip(other.collide_rect)
    215             # TODO: avoid continual "if abs_v_? > EPSILON"
    216             frac_x = clip.width / abs_v_x if abs_v_x > EPSILON else dt
    217             frac_y = clip.height / abs_v_y if abs_v_y > EPSILON else dt
    218             if frac_x > frac_y:
    219                 if frac_y > frac:
    220                     frac, normal, idx = frac_y, (0, 1), i
    221             else:
    222                 if frac_x > frac:
    223                     frac, normal, idx = frac_x, (1, 0), i
    224 
    225         sprite.deltap(max(-1.1 * frac, -dt))
    226         sprite.bounce(others[idx], normal)
     213        # We only backout of "solide" collisions
     214        if sprite.block:
     215            for i, other in enumerate(others):
     216                if other.block or other.floor:
     217                    clip = sprite.collide_rect.clip(other.collide_rect)
     218                    # TODO: avoid continual "if abs_v_? > EPSILON"
     219                    frac_x = clip.width / abs_v_x if abs_v_x > EPSILON else dt
     220                    frac_y = clip.height / abs_v_y if abs_v_y > EPSILON else dt
     221                    if frac_x > frac_y:
     222                        if frac_y > frac:
     223                            frac, normal, idx = frac_y, (0, 1), i
     224                    else:
     225                        if frac_x > frac:
     226                            frac, normal, idx = frac_x, (1, 0), i
     227
     228                if idx is not None:
     229                    # We can see no solide collisions now
     230                    sprite.deltap(max(-1.1 * frac, -dt))
     231                    sprite.bounce(others[idx], normal)
    227232
    228233        for other in others:
  • skaapsteker/sprites/base.py

    r264 r271  
    196196
    197197    debug_color = (240, 240, 240)
     198    bounce_factor = (0, 0)    #  NPC's don't bounce by default
    198199
    199200    block = False
     
    285286    wants_updates = True
    286287
     288    blocks = False
     289
    287290    image_file = 'torii.png'
    288291
  • skaapsteker/sprites/player.py

    r269 r271  
    1616    collides_with = set([MONSTER_LAYER])
    1717    wants_updates = True
     18
     19    block = True
    1820
    1921    _max_sprint_time = 2
     
    156158            # FIXME: Check if we're facing the right way
    157159            other.damage(5)
    158         if other not in self._last_collide:
     160        if other not in self._last_collide and (other.floor or other.block):
    159161            self._last_collide.append(other)
    160162            self._collide_pos = self.collide_rect.midbottom
    161163            self._collisions_seen = 0
    162         else:
     164        elif other in self._last_collide:
    163165            self._collisions_seen += 1
     166        print other, self._collisions_seen, self._last_collide
    164167        if hasattr(other, 'collided_player'):
    165168            other.collided_player(self)
Note: See TracChangeset for help on using the changeset viewer.