# HG changeset patch # User Neil Muller # Date 1302031544 -7200 # Node ID 60138b935bc048ae08520f3fd4ed04f92a800fee # Parent 06be025c821cb2585c61fbe670d01e26ced81200 Make enemies block by default, so we can jump off them diff -r 06be025c821c -r 60138b935bc0 skaapsteker/physics.py --- a/skaapsteker/physics.py Tue Apr 05 20:17:08 2011 +0200 +++ b/skaapsteker/physics.py Tue Apr 05 21:25:44 2011 +0200 @@ -35,10 +35,11 @@ debug_color = (240, 0, 0) floor = False # We special case collisions with ground objects + block = False def __init__(self, *args, **kwargs): super(Sprite, self).__init__(*args, **kwargs) - self.on_ground = False + self.on_solid = False self.velocity = (0.0, 0.0) self.rect = pygame.Rect(0, 0, 10, 10) # sub-classes should override self.collide_rect = pygame.Rect(0, 0, 10, 10) # rectangle we use for collisions @@ -103,9 +104,9 @@ dv_x = - normal[0] * b_x * v_x dv_y = - normal[1] * b_y * v_y - if normal == (0, 1) and other.floor and v_y > 0 and self.collide_rect.top < other.collide_rect.top: + if normal == (0, 1) and (other.floor or other.block) and v_y > 0 and self.collide_rect.top < other.collide_rect.top: # Colliding with the ground from above is special - self.on_ground = True + self.on_solid = True dv_y = -v_y if other.mobile: @@ -194,7 +195,7 @@ # gravity dv = self.GRAVITY[0] * dt, self.GRAVITY[1] * dt for sprite in self._gravitators: - if sprite.on_ground: + if sprite.on_solid: sprite.deltav((dv[0], 0.0)) else: sprite.deltav(dv) @@ -214,28 +215,25 @@ collisions.append(other) if collisions: self._backout_collisions(sprite, collisions, dt) - if sprite.on_ground: + contact_rect = pygame.Rect( + (sprite.collide_rect.left, sprite.collide_rect.bottom), + (sprite.collide_rect.width, 1)) + collides = contact_rect.colliderect + if sprite.on_solid: # Check if we are still in contact with the ground - contact_rect = sprite.collide_rect.move((0, 1)) - collides = contact_rect.colliderect - still_on_ground = False + still_on_solid = False for other in self._collision_groups[sprite.collision_layer]: - if other.floor and collides(other.collide_rect): - still_on_ground = True + if (other.floor or other.block) and collides(other.collide_rect): + still_on_solid = True break - sprite.on_ground = still_on_ground + sprite.on_solid = still_on_solid else: # Are we currently in contact with the groun - contact_rect = pygame.Rect( - (sprite.collide_rect.left, sprite.collide_rect.bottom -1), - (sprite.collide_rect.width, 1)) - collides = contact_rect.colliderect for other in self._collision_groups[sprite.collision_layer]: - if other.floor and collides(other.collide_rect): - sprite.on_ground = True + if (other.floor or other.block) and collides(other.collide_rect): + sprite.on_solid = True break - # call update methods self._updaters.update() diff -r 06be025c821c -r 60138b935bc0 skaapsteker/sprites/base.py --- a/skaapsteker/sprites/base.py Tue Apr 05 20:17:08 2011 +0200 +++ b/skaapsteker/sprites/base.py Tue Apr 05 21:25:44 2011 +0200 @@ -22,6 +22,8 @@ debug_color = (240, 120, 120) + block = True + def __init__(self, pos, **opts): Sprite.__init__(self) self.image = data.load_image('sprites/' + self.image_file) diff -r 06be025c821c -r 60138b935bc0 skaapsteker/sprites/player.py --- a/skaapsteker/sprites/player.py Tue Apr 05 20:17:08 2011 +0200 +++ b/skaapsteker/sprites/player.py Tue Apr 05 21:25:44 2011 +0200 @@ -79,8 +79,8 @@ def set_pos(self, pos): self.starting_tile_pos = pos - self.rect.topleft = pos[0] * TILE_SIZE[0] + self.rect_offset[0], pos[1] * TILE_SIZE[1] + self.rect_offset[1] - self.collide_rect.topleft = pos[0] * TILE_SIZE[0], pos[1] * TILE_SIZE[1] + self.rect.midbottom = pos[0] * TILE_SIZE[0] + self.rect_offset[0], pos[1] * TILE_SIZE[1] + self.rect_offset[1] + self.collide_rect.midbottom = pos[0] * TILE_SIZE[0], pos[1] * TILE_SIZE[1] def action_left(self): if self.facing != 'left': @@ -95,9 +95,9 @@ self.deltav((100.0, 0.0)) def action_up(self): - if self.on_ground: + if self.on_solid: self.deltav((0.0, -350.0)) - self.on_ground = False + self.on_solid = False def action_down(self): self.deltav((0.0, 100.0))