def update(self, dt):
        for event in self.event_bus.get_events():
            if event.ty == EventType.PLAYER:
                if event.data['type'] == PlayerEventType.XP_ADDED:
                    original_level = PlayerData.level_from_xp(
                        event.data['original'])
                    new_level = PlayerData.level_from_xp(event.data['new'])

                    if original_level != new_level:
                        self.event_bus.send.append(
                            Event(
                                {
                                    'type': NotifyEventType.NOTIFY,
                                    'time': 2,
                                    'title': "Level Up",
                                    'text': "Upgrades Available",
                                    'sound_path': "player/level_up.wav"
                                }, EventType.NOTIFY))

                    self.world.remove_component(self.entity, self.sprite)
                    self.sprite = Sprite.new_text("Level " + str(new_level),
                                                  (255, 255, 255), 14)
                    self.world.add_component(self.entity, self.sprite)
                    self.sprite._redraw = True
                    self.transform.x = constants.WIDTH / 2 - self.sprite.bounds.width / 2
示例#2
0
    def load(data, path):
        if 'text' in data.keys():
            text = data['text']
            text_val = text['text']
            color = text['color']
            size = text['size']
            fontname = text.get('font', pygame.font.get_default_font())

            return Sprite.new_text(text_val, color, size, fontname)

        image_path = paths.IMAGES + data['image'] + ".png"
        texture = pygame.image.load(image_path)

        bounds = data.get('bounds', None)
        if bounds != None:
            bounds = pygame.Rect(bounds[0], bounds[1], bounds[2], bounds[3])

        visible = data.get('visible', True)

        offset = pygame.math.Vector2(
            data.get('offset', [0, 0])[0],
            data.get('offset', [0, 0])[1])

        sprite = Sprite(texture, bounds, visible, offset)

        if 'animation' in data.keys():
            animation = data['animation']
            frame_width = animation['frame_width']
            frame_height = animation['frame_height']
            delay = animation.get('delay', -1)
            start = animation.get('start', 0)
            end = animation.get('end', None)

            sprite.with_animation(frame_width, frame_height, delay, start, end)

        return sprite
示例#3
0
    def create_text(self):
        self.notify.text_entity = self.notify.world.create_entity_with(
            *loader.load("entity", "ui/overworld/notification_text")[0])

        self.notify.world.remove_component(self.notify.text_entity, Sprite)
        sprite = Sprite.new_text(self.notify.queue[0].text, (255, 255, 255),
                                 16)
        self.notify.world.add_component(self.notify.text_entity, sprite)

        self.text_transform = self.notify.world.component_for_entity(
            self.notify.text_entity, Transform)

        self.text_transform.position.x = constants.WIDTH / 2 - (
            sprite.texture.get_width() * self.text_transform.scale.x) / 2
        self.text_transform.position.y = self.notify.transform.position.y + constants.NOTIFY_TEXT_DISTANCE
    def update_action(self):
        if self.text_entity != None:
            self.world.delete_entity(self.text_entity)
            self.text_entity = None

        self.sprite.visible = True

        self.text_entity = self.world.create_entity_with(
            *loader.load("entity", "ui/overworld/action_text")[0])
        sprite = Sprite.new_text(self.cur_text, (255, 255, 255), 20)
        self.world.add_component(self.text_entity, sprite)
        transform = self.world.component_for_entity(self.text_entity,
                                                    Transform)
        transform.position.x = constants.WIDTH / 2 - sprite.texture.get_width(
        ) / 2
        transform.position.y = 320
示例#5
0
    def update_text(self, new):
        if self.text_entity != None:
            self.world.delete_entity(self.text_entity)
            self.text_entity = None
        
        self.text_entity = self.world.create_entity_with(*loader.load("entity", "ui/overworld/arrow_text")[0])
        
        transform = self.world.component_for_entity(self.text_entity, Transform)

        transform.position.x = self.transform.position.x + 16
        transform.position.y = self.transform.position.y + 18

        self.world.remove_component(self.text_entity, Sprite)
        
        new_sprite = Sprite.new_text(str(new), (255, 255, 255), 14)

        self.world.add_component(self.text_entity, new_sprite)