def parser_basic_info(self, parse): ''' @brief Método que parsea la información basica de un objeto del juego. @param parse Parse a Archivo xml con xml.dom.minidom ''' parent_node = parse.firstChild sprite_name = str(parent_node.getAttribute('sprite_code')) self.original_sprite = resource.get_new_sprite(sprite_name) #Cargamos las distintas animaciones del objeto for element in parse.getElementsByTagName('animation'): animation_name = str(element.getAttribute('name')) animation_frames = str(element.getAttribute('frames')) animation_delay = int(element.getAttribute('delay')) #Vemos que tipo de animación es y lo añadimos al mapa de imagenes if animation_name == 'normal': self.animations[NORMAL] = animation.Animation( animation_frames, animation_delay) elif animation_name == 'noaction': self.animations[NOACTION] = animation.Animation( animation_frames, animation_delay) elif animation_name == 'run': self.animations[RUN] = animation.Animation( animation_frames, animation_delay) elif animation_name == 'forward': self.animations[FORWARD] = animation.Animation( animation_frames, animation_delay) elif animation_name == 'reverse': self.animations[REVERSE] = animation.Animation( animation_frames, animation_delay) elif animation_name == 'damaged': self.animations[DAMAGED] = animation.Animation( animation_frames, animation_delay) elif animation_name == 'erase': self.animations[ERASE] = animation.Animation( animation_frames, animation_delay) elif animation_name == 'yaw': self.animations[YAW] = animation.Animation( animation_frames, animation_delay) elif animation_name == 'fall': self.animations[FALL] = animation.Animation( animation_frames, animation_delay) elif animation_name == 'turbo': self.animations[TURBO] = animation.Animation( animation_frames, animation_delay) #Inicializamos la imagen, el rectangulo y la mascara de pixeles self.image = self.original_sprite.get_frame( self.animations[NORMAL].get_frame()) self.rect = self.image.get_rect() self.mask = pygame.mask.from_surface(self.image) self.hitmask = pixelperfect.get_alpha_hitmask(self.image, self.rect)
def parser_basic_info(self, parse): ''' @brief Método que parsea la información basica de un objeto del juego. @param parse Parse a Archivo xml con xml.dom.minidom ''' parent_node = parse.firstChild sprite_name = str(parent_node.getAttribute('sprite_code')) self.original_sprite = resource.get_new_sprite(sprite_name) #Cargamos las distintas animaciones del objeto for element in parse.getElementsByTagName('animation'): animation_name = str(element.getAttribute('name')) animation_frames = str(element.getAttribute('frames')) animation_delay = int(element.getAttribute('delay')) #Vemos que tipo de animación es y lo añadimos al mapa de imagenes if animation_name == 'normal': self.animations[NORMAL] = animation.Animation(animation_frames, animation_delay) elif animation_name == 'noaction': self.animations[NOACTION] = animation.Animation(animation_frames, animation_delay) elif animation_name == 'run': self.animations[RUN] = animation.Animation(animation_frames, animation_delay) elif animation_name == 'forward': self.animations[FORWARD] = animation.Animation(animation_frames, animation_delay) elif animation_name == 'reverse': self.animations[REVERSE] = animation.Animation(animation_frames, animation_delay) elif animation_name == 'damaged': self.animations[DAMAGED] = animation.Animation(animation_frames, animation_delay) elif animation_name == 'erase': self.animations[ERASE] = animation.Animation(animation_frames, animation_delay) elif animation_name == 'yaw': self.animations[YAW] = animation.Animation(animation_frames, animation_delay) elif animation_name == 'fall': self.animations[FALL] = animation.Animation(animation_frames, animation_delay) elif animation_name == 'turbo': self.animations[TURBO] = animation.Animation(animation_frames, animation_delay) #Inicializamos la imagen, el rectangulo y la mascara de pixeles self.image = self.original_sprite.get_frame(self.animations[NORMAL].get_frame()) self.rect = self.image.get_rect() self.mask = pygame.mask.from_surface(self.image) self.hitmask = pixelperfect.get_alpha_hitmask(self.image, self.rect)
def __init__(self, game_control, owner, path_xml, x, y, angle): ''' @brief Constructor. @param game_control Referencia a GameControl @param owner GameObject que lanza el item. @param path_xml Archivo xml con las características del item @param x Posición en el eje x @param y Posición en el eje y @param angle Ángulo del item ''' Item.__init__(self, game_control, owner, path_xml, x, y, angle) self.type = MISSILE parser = xml.dom.minidom.parse(data.get_path_xml(path_xml)) root = parser.firstChild #Inicializamos atributos self.aceleration = float(root.getAttribute('aceleration')) self.max_speed = float(root.getAttribute('max_speed')) self.explosion_sprite = resource.get_new_sprite('explosion') self.explosion_animation = animation.Animation( '0,1,2,3,4,5,6,7,8,9,10,11,2,13,14,15,16,17,18,19,20,22,23,24,25', 0) #Funciones para cada estado self.states = { gameobject.NORMAL: self.__normal_state, gameobject.RUN: self.__run_state, gameobject.EXPLOSION: self.__explosion_state, gameobject.ERASE: self.__erase_state, } #Creamos el sistema de particulas, para cuando colisionemos con la caja self.explosion = False self.rect_explosion = self.explosion_sprite.get_frame(0).get_rect() self.actual_speed = 0.1
def __init__(self, game_control, owner, path_xml, x, y, angle): ''' @brief Constructor. @param game_control Referencia a GameControl @param owner GameObject que lanza el item. @param path_xml Archivo xml con las características del item @param x Posición en el eje x @param y Posición en el eje y @param angle Ángulo del item ''' Item.__init__(self, game_control, owner, path_xml, x, y, angle) self.type = MISSILE parser = xml.dom.minidom.parse(data.get_path_xml(path_xml)) root = parser.firstChild #Inicializamos atributos self.aceleration = float(root.getAttribute('aceleration')) self.max_speed = float(root.getAttribute('max_speed')) self.explosion_sprite = resource.get_new_sprite('explosion') self.explosion_animation = animation.Animation('0,1,2,3,4,5,6,7,8,9,10,11,2,13,14,15,16,17,18,19,20,22,23,24,25', 0) #Funciones para cada estado self.states = { gameobject.NORMAL: self.__normal_state, gameobject.RUN: self.__run_state, gameobject.EXPLOSION: self.__explosion_state, gameobject.ERASE: self.__erase_state, } #Creamos el sistema de particulas, para cuando colisionemos con la caja self.explosion = False self.rect_explosion = self.explosion_sprite.get_frame(0).get_rect() self.actual_speed = 0.1