Пример #1
0
class Healthy:
    def __init__(self, scene, meter_size = (30,4)):
        self._health = self.get_max_health()
        self.health_bar = Meter(V2(self.x, self.y - self._height / 2), meter_size[0], meter_size[1], PICO_RED, self.get_max_health())
        self.health_bar.value = self.health
        self.health_bar.offset = (0.5,1)
        self.health_bar.stay = False
        self.health_bar.visible = 0
        self.health_bar._recalc_rect()
        scene.ui_group.add(self.health_bar)

    @property
    def health(self):
        return self._health

    @health.setter
    def health(self, val):
        old = self._health
        self._health = max(min(val, self.get_max_health()), 0)
        if old != self._health:
            self.health_bar.value = self._health
            self.health_bar.max_value = self.get_max_health()
            self.health_bar.show()

    def get_max_health(self):
        return 0
Пример #2
0
def config_monitor(mid, rect):
    from meter import Meter;
    from widget.linear_meter import LinearMeterWidget;
    from widget.circle_meter import CircleMeterWidget;
    from widget.surface import SurfaceWidget;
    from widget.pango import PangoWidget;
    from monitor import Monitor;
    from datetime import datetime;
    import math;
    import cairo;

    c = Meter(300, 300);
    c.add_widget(LinearMeterWidget(LambdaMonitor(lambda : Monitor.get().cpu_usage), 
                                   145, 6, color = (1,1,1), alpha = 0.5,
                                   gravity = LinearMeterWidget.GRAVITY_EAST),
                 145, 300, 1, 1);
    c.add_widget(LinearMeterWidget(LambdaMonitor(lambda : Monitor.get().pmem_usage),
                                   145, 6, color = (1,1,1), alpha = 0.5,
                                   gravity = LinearMeterWidget.GRAVITY_WEST),
                 155, 300, -1, 1);
    c.add_widget(CircleMeterWidget(LambdaMonitor(lambda : (datetime.now().time().hour % 12) / 12.0), 
                                   140, 6, -math.pi / 2 + math.pi / 10, -math.pi / 2 - math.pi / 10,
                                   color=(1,1,1), alpha = 0.5, style = CircleMeterWidget.STYLE_SEGMENT),
                 150, 150, 0, 0);
    c.add_widget(CircleMeterWidget(LambdaMonitor(lambda : datetime.now().time().minute / 60.0 + datetime.now().time().second / 3600.0),
                                   128, 10, -math.pi / 2, -math.pi / 2,
                                   color=(1,1,1), alpha = 0.5),
                 150, 150, 0, 0);
    c.add_widget(CircleMeterWidget(LambdaMonitor(lambda : datetime.now().time().second / 60.0),
                                   112, 10, -math.pi / 2 - math.pi / 10, -math.pi / 2 + math.pi / 10,
                                   style=CircleMeterWidget.STYLE_SEGMENT, color=(1,1,1), alpha = 0.5), 
                 150, 150, 0, 0);
    c.add_widget(PangoWidget(LambdaMonitor(lambda :
                                           "<span font='Monospace 25'>" + datetime.now().strftime("%H%M%S") + "</span>\n" +
                                           "<span font='Monospace 20'>" + datetime.now().strftime("%y%m%d") + "</span>"),
                             color=(1,1,1), alpha = 0.5, alignment = "center"), 
                 150, 150, 0, 0);
            
    c.add_widget(PangoWidget(LambdaMonitor(lambda :
                                           "<span font='Monospace 20'>" + str(Monitor.get().gmail_unread_count) + "</span>"),
                             color=(1,1,1), alpha = 0.5, alignment = "center"), 
                 gmail_icon.get_width(), 0, -1, -1);

    c.add_widget(SurfaceWidget(gmail_icon, gmail_icon.get_width(), gmail_icon.get_height()),
                 0, 0, -1, -1);

    c.get_window().move(rect.x + (rect.width - c.width) / 2,
                        rect.y + (rect.height - c.height) / 2);
    c.show();
Пример #3
0
class Healthy:
    def __init__(self, scene, meter_size=(30, 4)):
        self._health = 1
        self.health_bar = Meter(V2(self.x, self.y - self._height / 2),
                                meter_size[0], meter_size[1], PICO_RED, 1)
        self.health_bar.value = self.health
        self.health_bar.offset = (0.5, 1)
        self.health_bar.stay = False
        self.health_bar.visible = 0
        self.health_bar._recalc_rect()
        scene.ui_group.add(self.health_bar)

        self._shield_damage = 0
        self.shield_bar = Meter(V2(self.x, self.y - self._height / 2 - 3),
                                meter_size[0], 2, PICO_BLUE, 1)
        self.shield_bar.value = 9999999
        self.shield_bar.offset = (0.5, 1)
        self.shield_bar.stay = False
        self.shield_bar.visible = 0
        self.shield_bar._recalc_rect()
        scene.ui_group.add(self.shield_bar)

    def set_health(self, health, show_healthbar=False):
        self.health = health
        self.health_bar.visible = show_healthbar

    @property
    def health(self):
        return self._health

    @health.setter
    def health(self, val):
        old = self._health
        self._health = max(min(val, self.get_max_health()), 0)
        if old != self._health:
            self.health_bar.value = self._health
            self.health_bar.max_value = self.get_max_health()
            self.health_bar.show()
            self.on_health_changed(old, self._health)
            if old > 0 and self._health <= 0:
                self.on_die()

    def on_die(self):
        pass

    def on_health_changed(self, old, new):
        pass

    def get_max_health(self):
        return 1

    def get_max_shield(self):
        return 0

    @property
    def shield(self):
        return max(self.get_max_shield() - self._shield_damage, 0)

    @shield.setter
    def shield(self, value):
        old = self._shield_damage
        self._shield_damage = min(max(self.get_max_shield() - value, 0),
                                  self.get_max_shield())
        if old != self._shield_damage:
            self.shield_bar.value = self.shield
            self.shield_bar.max_value = self.get_max_shield()
            self.shield_bar.show()
            self.health_bar.show()

    def take_damage(self, damage, origin=None):
        was_shield = False
        sa = min(damage, self.shield)
        if self.shield > 0:
            was_shield = True
        self.shield -= sa
        damage -= sa
        self.health -= damage
        if origin:
            delta = origin.pos - self.pos
            dn = helper.try_normalize(delta)
            hitpos = self.pos + dn * self.radius
            if was_shield:
                sound.play("shield")
                for i in range(10):
                    ang = dn.as_polar()[1]
                    ang *= 3.14159 / 180
                    rad = max(self.radius, 5) + 2
                    hp = self.pos + rad * helper.from_angle(
                        ang + random.random() - 0.5)
                    p = Particle([
                        PICO_GREEN, PICO_WHITE, PICO_BLUE, PICO_BLUE,
                        PICO_BLUE, PICO_BLUE, PICO_DARKBLUE
                    ], 1, hp, 0.65 + random.random() * 0.2, dn)
                    self.scene.game_group.add(p)
            else:
                sound.play("hit")
                particles = 10
                if self.radius > 6:
                    particles = 4
                    e = Explosion(hitpos, [PICO_WHITE, PICO_YELLOW, PICO_RED],
                                  0.2, 5, "log", 2)
                    self.scene.game_group.add(e)
                for i in range(particles):
                    p = Particle([
                        PICO_WHITE, PICO_YELLOW, PICO_YELLOW, PICO_RED,
                        PICO_LIGHTGRAY
                    ], 1, hitpos, 0.25,
                                 helper.random_angle() * 9)
                    self.scene.game_group.add(p)