def start_falling(self): ''' Starts the Block falling down. Only called once before this Block's state switches to STATES.FALLING. Blocks that are falling must not be part of matches. ''' self.acceleration[1] = GRAVITY blockgrid.check_block(self, False) if self.gridcell[1]: #If we're not at the top of the grid... block_above = blockgrid.blocks[self.gridcell[0]][self.gridcell[1] - 1] if block_above: #If there's at least one block above us... assert isinstance(block_above, Block), \ "%s expected a Block, got a %s" % (self, block_above) for i in blockgrid.blocks[self.gridcell[0]]: #For all grid cells above us... if i and not i.velocity[1]: #If this is a block that's not moving... i.change_state(Block.STATES.START_FALLING) else: break self.change_state(Block.STATES.FALLING)
def stop(self): ''' Handles the Block when it hits the bottom of the grid or another block. Changes velocity, plays sounds, etc. ''' self.acceleration[1] = 0.0 self.velocity[1] = 0.0 self.position = self.__get_snap() self.rect.topleft = self.position self.gridcell[1] = self.rect.centery // self.rect.height #(row, col) self.state = Block.STATES.ACTIVE blockgrid.blocks[self.gridcell[0]][self.gridcell[1]] = self blockgrid.check_block(self, True) _bump.play() #blockgrid.update() if self._special: #If this is a special block... UFO_BLOCK.play() self.emitter.pool = color.random_color_particles if self.gridcell[1] < blockgrid.SIZE[1] - 1: #If we're not at the bottom of the grid... self.color = blockgrid.blocks[self.gridcell[0]][self.gridcell[1]+ 1].color blockgrid.clear_color(self.color) else: blockgrid.clear_row(self.gridcell[1]) elif not self.gridcell[1]: #If we go past the the playing field... self._anim = len(FRAMES) - 2 #Bring us to the second-to-last frame self.__animate() #And let the animation system finish gamedata.lives = 0
def stop(self): ''' Handles the Block when it hits the bottom of the grid or another block. Changes velocity, plays sounds, etc. ''' self.acceleration[1] = 0.0 self.velocity[1] = 0.0 self.position = self.__get_snap() self.rect.topleft = self.position self.gridcell[1] = self.rect.centery // self.rect.height #(row, col) self.state = Block.STATES.ACTIVE blockgrid.blocks[self.gridcell[0]][self.gridcell[1]] = self blockgrid.check_block(self, True) _bump.play() #blockgrid.update() if self._special: #If this is a special block... UFO_BLOCK.play() self.emitter.pool = color.random_color_particles if self.gridcell[1] < blockgrid.SIZE[1] - 1: #If we're not at the bottom of the grid... self.color = blockgrid.blocks[self.gridcell[0]][ self.gridcell[1] + 1].color blockgrid.clear_color(self.color) else: blockgrid.clear_row(self.gridcell[1]) elif not self.gridcell[1]: #If we go past the the playing field... self._anim = len(FRAMES) - 2 #Bring us to the second-to-last frame self.__animate() #And let the animation system finish gamedata.lives = 0
def vanish(self): blockgrid.check_block(self, False) self.emitter.burst(20) self.kill() blockgrid.blocks[self.gridcell[0]][self.gridcell[1]] = None self._anim = 0 self.position = [-300.0, -300.0] self.rect.topleft = self.position self.gridcell = None self.change_state(Block.STATES.IDLE) self.__replace()
def wait(self): ''' Constantly checks to see if this block can fall. ''' gridcell = self.gridcell if self.rect.bottom < blockgrid.RECT.bottom: #If we're not at the bottom of the grid... block_below = blockgrid.blocks[gridcell[0]][gridcell[1] + 1] if not block_below or block_below.velocity[1]: #If there's no block directly below... blockgrid.check_block(self, False) self.acceleration[1] = GRAVITY self.change_state(Block.STATES.START_FALLING) if __debug__ and self.rect.collidepoint(pygame.mouse.get_pos()): print(self)