Ejemplo n.º 1
0
    def slide(self, direction=-1, location=None, rect=None, speed=3):
        if not location:
            location = self.location
        if not rect:
            rect = self.rect

        (column, row) = location
        position = rect.center

        if direction == -1:
            direction = self.sliding

        if direction == EAST:
            destination = board.findPosition((column+1, row))
            if position[COLUMN] >= destination[COLUMN]:
                self.sliding = -1
                if column+1 == COLUMNS:
                    self.falling = True
                else:
                    self.location = (column+1, row)
            else:
                rect.left += speed
        elif direction == WEST:
            destination = board.findPosition((column-1, row))
            if position[COLUMN] <= destination[COLUMN]:
                self.sliding = -1
                if column-1 == -1:
                    self.falling = True
                else:
                    self.location = (column-1, row)
            else:
                rect.left -= speed
        elif direction == NORTH:
            destination = board.findPosition((column, row-1))
            if position[ROW] <= destination[ROW]:
                self.sliding = -1
                if row-1 == -1:
                    self.falling = True
                else:
                    self.location = (column, row-1)
            else:
                rect.top -= speed
        elif direction == SOUTH:
            destination = board.findPosition((column, row+1))
            if position[ROW] >= destination[ROW]:
                self.sliding = -1
                if row+1 == ROWS:
                    self.falling = True
                else:
                    self.location = (column, row+1)
            else:
                rect.top += 3
Ejemplo n.º 2
0
 def fallen(self):
     (column, row) = self.location
     if column == 0:
         self.location = (COLUMNS-1, row)
     elif column == COLUMNS-1:
         self.location = (0, row)
     elif row == 0:
         self.location = (column, ROWS-1)
     elif row == ROWS-1:
         self.location = (column, 0)
     self.rect = self.image.get_rect()
     self.rect.center = board.findPosition(self.location)
Ejemplo n.º 3
0
    def __init__(self, file="items.png", size=(50,50), location=(0,0),
        offset=0):

        pygame.sprite.Sprite.__init__(self)

        rect = pygame.Rect(offset*size[0], 0, size[0], size[1])
        if Item.image is None:
            Item.image = util.loadImage(file)

        self.image = Item.image.subsurface(rect)
        self.imageCopy = self.image
        self.location = location

        self.offset = offset

        self.rect = self.image.get_rect()
        self.rect.center = board.findPosition(location)

        self.falling = False
        self.sliding = -1
        self.tick = 0