def __init__(self, standing_image, walk_left_images, walk_right_images): Movable.__init__(self, standing_image) self.walk_right_images = walk_right_images self.walk_left_images = walk_left_images self.standing_image = standing_image self.is_player = False self.dead = False
def tick(self) : Movable.tick(self) for part in self.parts : if part.square : part.tick()
def __init__(self, level, pos): Movable.__init__(self, level, pos) self.tile = 0, 1 self.speed = 100 self.moves_continuously = True
def __init__(self, level, pos): Movable.__init__(self, level, pos) self.tile = 1, 1 self.speed = 100 self.is_sinkable = False self.moves_continuously = True
def __init__(self, level, pos, facing): Movable.__init__(self, level, pos, facing) self.tile = 7, 1 # facing = diagonal dir the mirror is facing: 0-3, clockwise from northeast # out_dirs = the two cardinal dirs the mirror is facing self.out_dirs = facing, (facing + 1) % 4
def tick( self ) : Movable.tick(self) if self.pause : return if not self.isMoving() : if self.logic == 1 or self.logic == 2 : self.moveRound() else : self.moveRandom()
def tick(self) : Movable.tick(self) # Check that dummy hasn't been removed from the grid (which will happen if my tick caused it to die) if self.dummy.square : self.dummy.tick() if self.square and not self.isMoving() : forward = self.look( self.direction, 0 ) if forward.hasTag(self.squash) : self.move(self.direction, 0)
def __init__( self, parent, dx, dy ) : Movable.__init__(self) self.parent = parent self.offsetx = dx self.offsety = dy self.speed = parent.speed self.parent.parts.append( self ) x = parent.square.x + dx y = parent.square.y + dy self.square = parent.square.grid.getSquare(x, y) self.square.occupant = self
def update(self): if self.dead: return # Called every frame self.check_for_key_press() rc = Movable.update(self) if rc == MovableRC.FELL_OFF_SCREEN: self.die() elif not rc == MovableRC.STOP_ALL: self.animate()
def act_on_collision(self, tile): log.debug( "Collided with {}. y_speed = {}. Tile attributes = {}".format( tile.tile_id, self.y_speed, tile.attrs)) self.rotating = False if tile.attrs & TileAttr.DISABLE_ON_ROTATE and not tile.rotation_enabled: return Movable.act_on_collision(self, tile) if tile.attrs & TileAttr.KILL: self.die() return MovableRC.STOP_ALL if tile.tile_id == "EXIT": print("Posting exit event") self.scene = None pygame.event.post(pygame.event.Event(config.REACHED_EXIT_EVENT_ID)) return MovableRC.STOP_ALL if tile.tile_id == "SPIN": self.y_speed = 0 self.last_collided = None # Make sure we don't hit spin again after it's been deleted self.scene.spin_activated(tile) return MovableRC.STOP if self.y_speed > config.SPRING_ACTIVE_SPEED and tile.attrs & TileAttr.SPRING and tile.state == 0: log.info("Hit SPRING_UP. y_speed = {}".format(self.y_speed)) self.scene.animate_spring(tile) self.y_speed = min(self.y_speed, 10) self.falling = True return MovableRC.STOP_ALL elif self.y_speed > config.SPRING_ACTIVE_SPEED and tile.attrs & TileAttr.SPRING and tile.state == 1: log.info("Hit SPRING_DOWN") self.scene.animate_spring(tile) # ToDo. This is a nasty hack to avoid the tile springing back and overlapping the sprite. self.rect.top -= int(config.TILE_SIZE_PX) / 2 self.y_speed = -1 * config.SPRING_JUMP_SPEED return MovableRC.STOP_ALL elif self.y_speed > config.SPRING_ACTIVE_SPEED and tile.attrs & TileAttr.BUTTON: log.info("Hit button. y_speed = {}".format(self.y_speed)) self.scene.hit_button(tile) self.y_speed = min(self.y_speed, 10) return MovableRC.CONTINUE return Movable.act_on_collision(self, tile)
def __init__(self, x, y, dx, dy, rotation, world_width, world_height): Movable.__init__(self, x, y, dx, dy, world_width, world_height) self.mRotation = rotation
def move(self, dx, dy,speed=None) : Movable.move(self,dx,dy,speed) # Check if dummy is still on the grid (it won't be if my movement caused us both to die). if self.dummy.square : self.dummy.move(dx, dy, speed)
def onDeath(self) : if self.dummy : self.dummy.removeFromGrid() Movable.onDeath(self)
def __init__(self, level, pos): Movable.__init__(self, level, pos) self.tile = 8, 1
def move( self, dx, dy, speed=None ) : Movable.move( self, dx, dy, speed ) for part in self.parts : part.move( dx, dy, speed )
def start_scene(self, scene, initial_left, initial_top): Movable.start_scene(self, scene, initial_left, initial_top) self.walking = False self.walk_index = 0 self.dead = False
def removeFromGrid(self) : Movable.removeFromGrid(self) for part in self.parts : part.removeFromGrid()
def __init__(self) : Movable.__init__(self) # A list of Part objects self.parts = []