def open_door(self, tile): if not tile.openable: raise TypeError('tile cannot be opened.'.format(tile)) tiletype = TileType.get_door_type(tile.tiletype.direction, False, True, False) tiletype = TileType(tile.tiletype.name.replace('closed', 'open')) tile.tiletype = tiletype return True
def load_tile_types(self,files): for file_name in files: f = open(file_name) data = yaml.load(f) f.close() yamlhelp.merge(data,self.tile_types) for tile_type_id in self.tile_types: tile_type = self.tile_types[tile_type_id] tile_type = TileType(tile_type_id,**tile_type) self.tile_types[tile_type_id] = tile_type if type(tile_type.color)==list: tile_type.color = [yamlhelp.load_color(c) for c in tile_type.color] else: tile_type.color = yamlhelp.load_color(tile_type.color) tile_type.color_not_visible = yamlhelp.load_color(tile_type.color_not_visible)
def define_tiles(): # Tile naming scheme: [udlr][pn/] directions powered/notpowered/nothing tile_types["ud/"] = TileType( get_sprite_at_tiles_spritesheet_location(0, 0), ["up", "down"], ["up", "down"]) tile_types["lr/"] = TileType( get_sprite_at_tiles_spritesheet_location(1, 0), ["left", "right"], ["left", "right"]) tile_types["dr/"] = TileType( get_sprite_at_tiles_spritesheet_location(2, 0), ["down", "right"], ["down", "right"]) tile_types["dl/"] = TileType( get_sprite_at_tiles_spritesheet_location(3, 0), ["down", "left"], ["down", "left"]) tile_types["udn"] = TileType( get_sprite_at_tiles_spritesheet_location(4, 0), ["up", "down"], ["up", "down"]) tile_types["lrn"] = TileType( get_sprite_at_tiles_spritesheet_location(5, 0), ["left", "right"], ["left", "right"]) tile_types["drn"] = TileType( get_sprite_at_tiles_spritesheet_location(6, 0), ["down", "right"], ["down", "right"]) tile_types["dln"] = TileType( get_sprite_at_tiles_spritesheet_location(7, 0), ["down", "left"], ["down", "left"]) tile_types["udp"] = TileType( get_sprite_at_tiles_spritesheet_location(8, 0), ["up", "down"], ["up", "down"]) tile_types["lrp"] = TileType( get_sprite_at_tiles_spritesheet_location(9, 0), ["left", "right"], ["left", "right"]) tile_types["drp"] = TileType( get_sprite_at_tiles_spritesheet_location(10, 0), ["down", "right"], ["down", "right"]) tile_types["dlp"] = TileType( get_sprite_at_tiles_spritesheet_location(11, 0), ["down", "left"], ["down", "left"]) tile_types["ulr/"] = TileType( get_sprite_at_tiles_spritesheet_location(0, 1), ["up", "left", "right"], ["up", "left", "right"]) tile_types["udl/"] = TileType( get_sprite_at_tiles_spritesheet_location(1, 1), ["up", "left", "down"], ["up", "left", "down"]) tile_types["ur/"] = TileType( get_sprite_at_tiles_spritesheet_location(2, 1), ["up", "right"], ["up", "right"]) tile_types["ul/"] = TileType( get_sprite_at_tiles_spritesheet_location(3, 1), ["up", "left"], ["up", "left"]) tile_types["ulrn"] = TileType( get_sprite_at_tiles_spritesheet_location(4, 1), ["up", "left", "right"], ["up", "left", "right"]) tile_types["udln"] = TileType( get_sprite_at_tiles_spritesheet_location(5, 1), ["up", "left", "down"], ["up", "left", "down"]) tile_types["urn"] = TileType( get_sprite_at_tiles_spritesheet_location(6, 1), ["up", "right"], ["up", "right"]) tile_types["uln"] = TileType( get_sprite_at_tiles_spritesheet_location(7, 1), ["up", "left"], ["up", "left"]) tile_types["ulrp"] = TileType( get_sprite_at_tiles_spritesheet_location(8, 1), ["up", "left", "right"], ["up", "left", "right"]) tile_types["udlp"] = TileType( get_sprite_at_tiles_spritesheet_location(9, 1), ["up", "left", "down"], ["up", "left", "down"]) tile_types["urp"] = TileType( get_sprite_at_tiles_spritesheet_location(10, 1), ["up", "right"], ["up", "right"]) tile_types["ulp"] = TileType( get_sprite_at_tiles_spritesheet_location(11, 1), ["up", "left"], ["up", "left"]) tile_types["dlr/"] = TileType( get_sprite_at_tiles_spritesheet_location(0, 2), ["down", "right", "left"], ["down", "right", "left"]) tile_types["udr/"] = TileType( get_sprite_at_tiles_spritesheet_location(1, 2), ["down", "up", "right"], ["down", "up", "right"]) tile_types["udlr/"] = TileType( get_sprite_at_tiles_spritesheet_location(2, 2), ["down", "up", "left", "right"], ["down", "up", "left", "right"]) tile_types[""] = TileType(get_sprite_at_tiles_spritesheet_location(3, 2), [], []) tile_types["dlrn"] = TileType( get_sprite_at_tiles_spritesheet_location(4, 2), ["down", "right", "left"], ["down", "right", "left"]) tile_types["udrn"] = TileType( get_sprite_at_tiles_spritesheet_location(5, 2), ["down", "up", "right"], ["down", "up", "right"]) tile_types["udlrn"] = TileType( get_sprite_at_tiles_spritesheet_location(6, 2), ["down", "up", "left", "right"], ["down", "up", "left", "right"]) tile_types["dlrp"] = TileType( get_sprite_at_tiles_spritesheet_location(8, 2), ["down", "right", "left"], ["down", "right", "left"]) tile_types["udrp"] = TileType( get_sprite_at_tiles_spritesheet_location(9, 2), ["down", "up", "right"], ["down", "up", "right"]) tile_types["udlrp"] = TileType( get_sprite_at_tiles_spritesheet_location(10, 2), ["down", "up", "left", "right"], ["down", "up", "left", "right"]) # Special tiles tile_types["batteryMain"] = TileType(batteryMainAnim, ["down", "up", "left", "right"], ["down", "up", "left", "right"]) tile_types["batteryNotMain"] = TileType(batteryNotMainAnim, ["down", "up", "left", "right"], ["down", "up", "left", "right"]) tile_types["batteryOff"] = TileType( get_sprite_at_tiles_spritesheet_location(3, 3), ["down", "up", "left", "right"], ["down", "up", "left", "right"]) tile_types["batteryEnd"] = TileType( get_sprite_at_tiles_spritesheet_location(0, 4), ["down", "up", "left", "right"], ["down", "up", "left", "right"]) tile_types["batteryEndAnim"] = TileType(batteryEndAnim, ["down", "up", "left", "right"], ["down", "up", "left", "right"])
positronAnim = Animation([ get_sprite_at_enemy_spritesheet_location(0, 0), get_sprite_at_enemy_spritesheet_location(1, 0), get_sprite_at_enemy_spritesheet_location(2, 0), get_sprite_at_enemy_spritesheet_location(3, 0), get_sprite_at_enemy_spritesheet_location(4, 0), get_sprite_at_enemy_spritesheet_location(5, 0), get_sprite_at_enemy_spritesheet_location(6, 0), get_sprite_at_enemy_spritesheet_location(7, 0) ], [10, 10, 10, 10, 10, 10, 10, 10]) p1 = Player(1, 13, p1anim, world, p1deathAnim) quitRequested = False tile_type_test = TileType(get_sprite_at_tiles_spritesheet_location(0, 0), None, None) animations_to_update = [batteryMainAnim, batteryNotMainAnim, positronAnim] enemies = [ Positron(positronAnim, world, 150, 150), Positron(positronAnim, world, 26 * 50, 50), Positron(positronAnim, world, 27 * 50, 8 * 50), Positron(positronAnim, world, 17 * 50, 14 * 50), Positron(positronAnim, world, 2 * 50, 15 * 50), Positron(positronAnim, world, 6 * 50, 15 * 50), Positron(positronAnim, world, 26 * 50, 27 * 50), Positron(positronAnim, world, 38 * 50, 27 * 50) ]
def fix_door(self, tile): if not tile.fixable: raise TypeError('tile cannot be fixed.'.format(tile)) tiletype = TileType.get_door_type(tile.tiletype.direction, False, True, False) tile.tiletype = tiletype return True
def break_door(self, tile): if not tile.breakable: raise TypeError('tile cannot be broken.'.format(tile)) tiletype = TileType.get_door_type(tile.tiletype.direction, True, True, False) tile.tiletype = tiletype return True
def unlock_door(self, tile): if not tile.unlockable: raise TypeError('tile cannot be unlocked.'.format(tile)) tiletype = TileType.get_door_type(tile.tiletype.direction, False, False, False) tile.tiletype = tiletype return True
def close_door(self, tile): if not tile.closable: raise TypeError('tile cannot be closed.'.format(tile)) tiletype = TileType.get_door_type(tile.tiletype.direction, False, False, False) tile.tiletype = tiletype return True