Changeset 202:a11325bc5ff0


Ignore:
Timestamp:
04/06/11 20:42:35 (12 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Sprite refactoring stuff.

Location:
skaapsteker/sprites
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/base.py

    r193 r202  
    1717
    1818
    19 class Monster(Sprite):
    2019
     20class GameSprite(Sprite):
     21    image_dir = 'sprites/'
    2122    image_file = None
     23
     24    def __init__(self, pos, **opts):
     25        Sprite.__init__(self)
     26        self.image = data.load_image(self.image_dir + self.image_file)
     27        self.starting_tile_pos = pos
     28        self.rect = self.image.get_rect(midbottom=(pos[0]*TILE_SIZE[0]+TILE_SIZE[0]/2, (pos[1]+1)*TILE_SIZE[1]))
     29        self.collide_rect = self.rect.move(0, 0)
     30        self.setup(**opts)
     31
     32
     33
     34class Monster(GameSprite):
     35
    2236    collision_layer = MONSTER_LAYER
    2337    collides_with = set([PC_LAYER])
     
    2842
    2943    def __init__(self, pos, **opts):
    30         Sprite.__init__(self)
    31         self.image = data.load_image('sprites/' + self.image_file)
    32         self.starting_tile_pos = pos
    33         self.rect = self.image.get_rect(midbottom=(pos[0]*TILE_SIZE[0]+TILE_SIZE[0]/2, (pos[1]+1)*TILE_SIZE[1]))
    34         self.collide_rect = self.rect.move(0, 0)
     44        GameSprite.__init__(self, pos, **opts)
    3545        self.floor_rect = Rect(self.collide_rect.topleft, (self.collide_rect.width, 2))
    3646        self._layer = Layers.PLAYER
    37         self.setup(**opts)
    3847
    3948
    40     def setup(self):
    41         pass
     49    def collided_player(self):
     50        print "%s collided with player" % self
    4251
    4352
    44 class NPC(Sprite):
     53class NPC(GameSprite):
    4554
    4655    image_file = None
     
    5059    debug_color = (240, 240, 240)
    5160
    52     block = True
     61    block = False
    5362
    5463    def __init__(self, pos, **opts):
    55         Sprite.__init__(self)
    56         self.image = data.load_image('sprites/' + self.image_file)
    57         self.starting_tile_pos = pos
    58         self.rect = self.image.get_rect(midbottom=(pos[0]*TILE_SIZE[0]+TILE_SIZE[0]/2, (pos[1]+1)*TILE_SIZE[1]))
    59         self.collide_rect = self.rect.move(0, 0)
     64        GameSprite.__init__(self, pos, **opts)
    6065        self._layer = Layers.PLAYER
    61         self.setup(**opts)
     66
    6267
    6368    def setup(self, name, world, dsm):
     
    6570
    6671
    67 class Projectile(Sprite):
     72class Projectile(GameSprite):
    6873    gravitates = False
    6974
    7075
    71 class Item(Sprite):
     76class Item(GameSprite):
    7277    mobile = False
    7378    gravitates = False
    7479
    75     image_file = None
    7680    collision_layer = MONSTER_LAYER
    7781    collides_with = set([PC_LAYER])
     
    8084
    8185    def __init__(self, pos, **opts):
    82         Sprite.__init__(self)
    83         self.image = data.load_image('sprites/' + self.image_file)
    84         self.starting_tile_pos = pos
    85         self.rect = self.image.get_rect(midbottom=(pos[0]*TILE_SIZE[0]+TILE_SIZE[0]/2, (pos[1]+1)*TILE_SIZE[1]))
    86         self.collide_rect = self.rect.move(0, 0)
     86        GameSprite.__init__(self, pos, **opts)
    8787        self._layer = Layers.PLAYER
    88         self.setup(**opts)
    8988
    9089
     
    9796            return (240, 0, 240)
    9897        return (0, 0, 240)
     98
     99
     100    def collided_player(self):
     101        print "Player touched %s" % self
    99102
    100103
  • skaapsteker/sprites/enemies.py

    r174 r202  
    77    def setup(self, direction):
    88        self.facing = direction
    9 
    10 
  • skaapsteker/sprites/player.py

    r200 r202  
    135135        else:
    136136            self._collisions_seen += 1
     137        if hasattr(other, 'collided_player'):
     138            other.collided_player()
    137139
    138140
    139141    def set_pos(self, pos):
    140142        self.starting_tile_pos = pos
    141         self.rect.midbottom = pos[0] * TILE_SIZE[0] + self.rect_offset[0], pos[1] * TILE_SIZE[1] + self.rect_offset[1]
     143        self.rect.midbottom = pos[0] * TILE_SIZE[0] + self.rect_offset[0], (pos[1] + 1) * TILE_SIZE[1] + self.rect_offset[1]
    142144        self.collide_rect.midbottom = pos[0] * TILE_SIZE[0], pos[1] * TILE_SIZE[1]
    143145
Note: See TracChangeset for help on using the changeset viewer.