Changeset 623:65881746dc20


Ignore:
Timestamp:
05/07/11 11:59:00 (12 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

More Sprite hierarchy work.

Location:
skaapsteker
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/level.py

    r621 r623  
    5252        image = data.load_image('tiles/' + dirname + '/' + image_name)
    5353        def _tilefac(pos):
    54             tile = Geography(pos, image)
     54            tile = Geography(pos, image=image)
    5555            tile.block = block
    5656            tile.floor = floor
     
    188188        text = Text("? Tile at\n(%i, %i)" % (x, y), (2, 2), size=14, color='white')
    189189        text.draw(surface)
    190         return Geography((x, y), surface.convert_alpha())
     190        return Geography((x, y), image=surface.convert_alpha())
  • skaapsteker/physics.py

    r622 r623  
    3434    # set to True to have .update() called once per tick (and have .collision_group set)
    3535    wants_updates = False
    36 
    37     debug_color = (240, 0, 0)
    3836
    3937    floor = False  # We special case collisions with ground objects
     
    5452    def init_pos(self):
    5553        self._float_pos = self.rect.center
    56 
    57     def get_debug_color(self):
    58         return self.debug_color
    59 
    60     def draw_debug(self, surface):
    61         pygame.draw.rect(surface, self.get_debug_color(), self.collide_rect, 1)
    6254
    6355
  • skaapsteker/sprites/base.py

    r622 r623  
    3636    image_file = None
    3737    sprite_layer = None
     38    debug_color = (240, 0, 0)
    3839
    3940    def __init__(self, pos, **opts):
     
    4243            # pygame's Sprite class clobbers self._layer in __init__(), so we need to thwart it.
    4344            self._layer = self.sprite_layer
    44         self.setup_image_data(pos)
     45        self.setup_image_data(pos, **opts)
    4546        self.setup(**opts)
    4647
     
    5152        return cdiv(self.rect.center, TILE_SIZE)
    5253
    53     def setup_image_data(self, pos):
     54    def setup_image_data(self, pos, **opts):
    5455        self.image = data.load_image(self.image_dir + self.image_file)
    5556        self.rect = self.image.get_rect(midbottom=tile_midbottom(pos))
    5657        self.collide_rect = self.rect.move(0, 0)
     58
     59    def get_debug_color(self):
     60        return self.debug_color
     61
     62    def draw_debug(self, surface):
     63        pygame.draw.rect(surface, self.get_debug_color(), self.collide_rect, 1)
    5764
    5865
     
    7178
    7279
    73     def setup_image_data(self, pos):
     80    def setup_image_data(self, pos, **opts):
    7481        self._animations = dict((k, []) for k, r in self.animation_regexes)
    7582        self._frame = 0
     
    393400
    394401
    395 class Geography(Sprite):
     402class Geography(GameSprite):
    396403    mobile = False
    397404    gravitates = False
     
    401408    bounce_factor = (0.0, 0.0)
    402409
    403     def __init__(self, pos, image):
    404         Sprite.__init__(self)
     410    def setup(self, image):
     411        pass
     412
     413    def setup_image_data(self, pos, image, **opts):
    405414        self.tile_pos = pos
    406415        self.image = image
     
    430439
    431440
    432     def setup_image_data(self, pos):
    433         super(Doorway, self).setup_image_data(pos)
     441    def setup_image_data(self, pos, **opts):
     442        super(Doorway, self).setup_image_data(pos, **opts)
    434443        self.image = pygame.transform.scale(self.image, self.image.get_rect().center)
    435444        self.rect = self.image.get_rect(midbottom=self.rect.midbottom)
     
    461470    actionable = False
    462471
    463     def setup_image_data(self, pos):
     472    def setup_image_data(self, pos, **opts):
    464473        self.image = pygame.Surface((0, 0))
    465474        self.rect = self.image.get_rect(midbottom=tile_midbottom(pos))
     
    489498        super(Skeleton, self).__init__(pos, **opts)
    490499
    491     def setup_image_data(self, pos):
    492         GameSprite.setup_image_data(self, pos)
     500    def setup_image_data(self, pos, **opts):
     501        super(Skeleton, self).setup_image_data(pos, **opts)
    493502        # Pixel based rect, not tile:
    494503        self.rect = self.image.get_rect(midbottom=self._pos)
  • skaapsteker/sprites/player.py

    r622 r623  
    6464
    6565
    66     def setup_image_data(self, pos):
     66    def setup_image_data(self, pos, **opts):
    6767        self.shape = 'fox'  # Needed so load image does the right thing
    6868        self._image_dict = {}
Note: See TracChangeset for help on using the changeset viewer.