def __init__(self, resource, parent_node): """Constructor. :param resource: The terrain resource :type resource: :class:`loaders.Resource` :param parent_node: Parent node to attach the terrain entity to. :type param_node: subclass of :class:`renderer.SceneNode` """ shader = resource['shader'] mesh = resource['floor_mesh'] texture = Texture.from_image(resource['floor_texture']) # shader params params = { 'tex': texture, 'animate': 0, } renderable = Renderable( parent_node, mesh, shader, params, textures=[texture], enable_light=True) super().__init__(renderable) # FIXME: this offset here is due to the calculation of the walkable # matrix that adds one more walkable line on top of the scenario. self[Renderable].transform.translate(Vec(0.0, 0.0, 1.0))
def __init__(self, resource, position, progress, completed, parent_node): """Constructor. :param resource: The building resource :type resource: :class:`loaders.Resource` :param position: The position of the building :type position: :class:`tuple` :param progress: The current amount of hp and the total one :type progress: :class:`tuple` :param completed: Whether the building is completed or not :type completed: :class:`bool` :param parent_node: The parent node in the scene graph :type parent_node: :class:`renderer.scene.SceneNode` """ self._position = position # Progress is going to be a property used to update only when necessary # the health bar. self._progress = progress self.completed = completed shader = resource['shader'] texture = Texture.from_image(resource['texture']) self.mesh_project = resource['model_project'] self.mesh_complete = resource['model_complete'] # Setup the group node and add the health bar group_node = SceneNode() g_transform = group_node.transform g_transform.translate(to_scene(*position)) parent_node.add_child(group_node) self.health_bar = HealthBar( resource['health_bar'], progress[0] / progress[1], group_node) params = { 'tex': texture, } # create components renderable = Renderable( group_node, self.mesh, shader, params, textures=[texture], enable_light=True) # initialize entity super().__init__(renderable) # FIXME: hardcoded bounding box self._bounding_box = Vec(-0.5, 0, -0.5), Vec(0.5, 2, 0.5)
def __init__(self, resource, ref): self.w = resource.data['width'] self.h = resource.data['height'] mesh = Rect(self.w, self.h) texture = Texture.from_image(resource[ref]) shader = resource['shader'] params = { 'tex': texture, 'width': self.w, 'height': self.h, } self.node = GeometryNode( mesh, shader, params=params, textures=[texture], enable_light=False)
def __init__(self, resource, parent_node): """Constructor. :param resource: Resource containing map data. :type resource: :class:`resource_manager.Resource` :param parent_node: Node to attach the map to. :type parent_node: :class:`renderer.scene.SceneNode` """ shader = resource['shader'] mesh = resource['walls_mesh'] texture = Texture.from_image(resource['walls_texture']) # shader params params = { 'tex': texture, 'animate': 0, 'opacity': 1.0, 'color_ambient': Vec(0, 0, 0, 1), 'color_diffuse': Vec(0, 0, 0, 1), 'color_specular': Vec(0.1, 0.1, 0.1, 1), } renderable = Renderable( parent_node, mesh, shader, params, textures=[texture], enable_light=True) super().__init__(renderable) # FIXME: this offset here is due to the calculation of the walkable # matrix that adds one more walkable line on top of the scenario. self[Renderable].transform.translate(Vec(0.0, 0.0, 1.0)) self.objects = [] # Initialize static objects for obj in resource.data['objects']: self.add_object( MapObject(resource[obj['ref']], obj, self[Renderable].node))
def __init__(self, resource, parameters, parent_node): """Constructor. :param resource: Resource containing the object data. :type resource: :class:`resource_manager.Resource` :param parameters: Parameters for the object. :type parameters: :class:`dict` :param parent_node: Node to attach the object to. :type parent_node: :class:`renderer.scene.SceneNode` """ mesh = resource["model"] shader = resource["shader"] texture = Texture.from_image(resource["texture"]) # shader params params = { "tex": texture, "animate": 0, "opacity": 1.0, "color_ambient": Vec(0, 0, 0, 1), "color_diffuse": Vec(0, 0, 0, 1), "color_specular": Vec(0.1, 0.1, 0.1, 1), } renderable = Renderable(parent_node, mesh, shader, params, textures=[texture], enable_light=True) super().__init__(renderable) self[Renderable].transform.translate(to_scene(*parameters["pos"])) if "rotation" in parameters: self[Renderable].transform.rotate(Y_AXIS, parameters["rotation"] * pi / 180) # FIXME: hardcoded bounding box self._position = parameters["pos"] self._bounding_box = Vec(-0.5, 0.5, -0.5), Vec(0.5, 1.5, 0.5)
def __init__(self, resource, actor_type, health, parent_node): """Constructor. :param resource: The character resource :type resource: :class:`loaders.Resource` :param health: The current amount of hp and the total one :type health: :class:`tuple` :param parent_node: The parent node in the scene graph :type parent_node: :class:`renderer.scene.SceneNode` """ self.actor_type = actor_type # Health is going to be a property used to update only when necessary # the health bar. self._health = health shader = resource['shader'] mesh = resource['model']['mesh'] md = resource['model']['mesh_data'] # root transformation to apply to the mesh self.transform = md.transform # instantiate animations self.init_animations(md) self.current_anim = self.animations[action_anim_index(ActionType.idle)] texture = Texture.from_image(resource['texture']) # shader params params = { 'tex': texture, 'opacity': 1.0, 'color_ambient': Vec(0, 0, 0, 1), 'color_diffuse': Vec(0, 0, 0, 1), 'color_specular': Vec(0.1, 0.1, 0.1, 1), } # Initialize movable component movable = Movable((0.0, 0.0)) # Setup the group node and add the health bar # FIXME: I don't like the idea of saving the group node here. We need # something better here. self.group_node = SceneNode() g_transform = self.group_node.transform g_transform.translate(to_scene(*movable.position)) parent_node.add_child(self.group_node) self.health_bar = HealthBar( resource['health_bar'], health[0] / health[1], self.group_node, resource.data.get('hb_y_offset')) # create components renderable = Renderable( self.group_node, mesh, shader, params, textures=[texture], enable_light=True, animation=self.current_anim) # by default, start with playing animation renderable.animate = True # initialize actor super().__init__(renderable, movable) # FIXME: hardcoded bounding box self._bounding_box = Vec(-0.5, 0, -0.5), Vec(0.5, 2, 0.5) self.heading = 0.0