def fill_scene_with_objects(self): """ Fills this object's scene with objects as described by tiled_map """ from engine import GameObject tiled_map = self.map scene = self.game_object.scene for group in tiled_map.visible_object_groups: for obj in tiled_map.layers[group]: game_object = GameObject() translation = Vector2(0, 0) if obj.image is not None: translation.x = obj.image.get_width()/2 translation.y = obj.image.get_height()/2 obj_position = Vector2(obj.x, obj.y) + translation game_object.add_components(Transform(position=obj_position)) game_object.name = obj.name if obj.image is not None: animation_data = obj.properties.get("animation_data", None) game_object.add_components(SpriteRenderer(image=obj.image, animation_data=animation_data)) if "components" in obj.properties: self._resolve_components(obj.properties["components"].split(";"), game_object) scene.add_object(game_object)
def init(self, width, height): super(self.__class__, self).init(width, height) self.scene = Scene(self) map_obj = GameObject() self.scene.add_object(map_obj) map_obj.add_components(engine.components.Transform(), engine.components.TiledMap(map_path="assets/levels/level01.tmx")) self.scene.camera = GameObject() self.scene.add_object(self.scene.camera) self.scene.camera.add_components(engine.components.Transform(), engine.components.Camera()) self._create_interface() Input.bindings["left"] = pygame.K_a Input.bindings["right"] = pygame.K_d Input.bindings["jump"] = pygame.K_SPACE