示例#1
0
    def __init__(self, count, pos_x, pos_y, *groups):
        if count > 1:
            label = "%d" % count
        else:
            label = ""

        pos_y -= 2

        spr = data.load_image("ghost.png")
        w, h = spr.get_size()

        fnt = data.load_image("digits.png")
        fnt_w = 4
        fnt_h = 5

        txt_x = w + 1
        txt_y = 2

        self.image = pygame.Surface((txt_x + fnt_w * len(label), h),
                                    pygame.SRCALPHA)
        self.image.blit(spr, (0, 0))
        for i, c in enumerate(label):
            fnt_x = int(c) * fnt_w
            self.image.blit(fnt, (txt_x + i * fnt_w, txt_y),
                            (fnt_x, 0, fnt_w, fnt_h))

        self.rect = pygame.Rect(pos_x, pos_y, *self.image.get_size())
        self.targ_y = pos_y - DEAD_TTL // 2

        pygame.sprite.Sprite.__init__(self, *groups)
示例#2
0
    def draw(self, x, y, pop, targ):
        scaled_good = self.scale(pop.good)
        scaled_sick = self.scale(pop.sick)
        scaled_dead = self.scale(pop.dead)

        if x > GRID_MAX_W * GRID_W - INFO_WIDTH - GRID_W - INFO_OFFSET:
            x = x - INFO_WIDTH - INFO_OFFSET
        else:
            x = x + GRID_W + INFO_OFFSET

        if y > GRID_MAX_H * GRID_H - INFO_HEIGHT - GRID_H - INFO_OFFSET:
            y = y - INFO_HEIGHT - INFO_OFFSET
        else:
            y = y + GRID_H + INFO_OFFSET

        # Avoid showing an empty popup
        if scaled_good + scaled_sick + scaled_dead == 0:
            return

        background = pygame.Rect(x, y, INFO_WIDTH, INFO_HEIGHT)
        pygame.draw.rect(targ, INFO_COLOR, background)

        if scaled_good > 0:
            good = pygame.Rect(
                x + INFO_BORDER,
                y + INFO_BORDER + (INFO_BAR_THICKNESS + INFO_BAR_SPACE) * 0,
                scaled_good, INFO_BAR_THICKNESS)
            pygame.draw.rect(targ, GOOD_COLOR, good)

        if scaled_sick > 0:
            sick = pygame.Rect(
                x + INFO_BORDER,
                y + INFO_BORDER + (INFO_BAR_THICKNESS + INFO_BAR_SPACE) * 1,
                scaled_sick, INFO_BAR_THICKNESS)
            pygame.draw.rect(targ, SICK_COLOR, sick)

        if scaled_dead > 0:
            dead = pygame.Rect(
                x + INFO_BORDER,
                y + INFO_BORDER + (INFO_BAR_THICKNESS + INFO_BAR_SPACE) * 2,
                scaled_dead, INFO_BAR_THICKNESS)
            pygame.draw.rect(targ, DEAD_COLOR, dead)
示例#3
0
    def __init__(self, pos_x, pos_y, *groups):
        pygame.sprite.Sprite.__init__(self, *groups)

        pos_x += GRID_W * random.randint(-1, 1)
        pos_y += GRID_H * random.randint(-1, 1)

        pos_y -= 2
        self.targ_y = pos_y - 6

        self.image = data.load_image("plus.png")
        self.rect = pygame.Rect(pos_x, pos_y, GRID_W, GRID_H)
示例#4
0
    def __init__(self, font, text, cb, x, y, w=None, h=None):
        self.text = font.render(text, True, self.fg_color)
        text_w, text_h = self.text.get_size()

        if w is None:
            w = text_w + self.margin * 2
        if h is None:
            h = text_h + self.margin * 2

        self.cb = cb
        self.rect = pygame.Rect(x, y, w, h)
        self.tpos = x + w / 2 - text_w / 2, y + h / 2 - text_h / 2
        self.shown = False
示例#5
0
文件: unit.py 项目: vickenty/plague
 def __init__(self, model, x, y):
     self.x = x
     self.y = y
     self.rect = pygame.Rect(0, 0, GRID_W, GRID_H)
     if pygame.version.vernum >= (2, 0, 0):
         # facepalm
         self.rect.w -= 1
         self.rect.h -= 1
     self.command = self.cmd_idle, ()
     self.anim = anim.Anim("unit.cfg", self.idle_seq, self.x, self.y)
     self.is_moving = False
     self.is_blocking = False
     self.model = model
     self.scream_sample = data.load_sample("aaaargh.wav")
     self.scream_sample.set_volume(0.7)
示例#6
0
文件: anim.py 项目: vickenty/plague
    def __init__(self, name, seq, pos_x, pos_y, *groups):
        super(Anim, self).__init__(*groups)
        self.conf = conf = data.load_json(name)

        self.sheet = data.load_image(conf["image"])
        self.frame_w, self.frame_h = conf["frame"]
        self.offset_x, self.offset_y = conf["offset"]
        self.rect = pygame.Rect(
            pos_x + self.offset_x,
            pos_y + self.offset_y,
            self.frame_w,
            self.frame_h,
        )

        self.delay = conf.get("delay", 0)
        self.time = self.delay  # force first update

        self.seq = None
        self.set_seq(seq)
        self.update()
示例#7
0
    def __init__(self, font, text, cb, x, y, img=None):
        self.text = font.render(text, True, self.fg_color)
        text_w, text_h = self.text.get_size()

        # assuming iup and idown have the same dimensions
        if img:
            self.image_up, self.image_down = img
        else:
            self.image_up = data.load_image("button_up.png")
            self.image_down = data.load_image("button_dn.png")

        w, h = self.image_up.get_size()
        h += 3

        self.rect = pygame.Rect(x, y, w, h)

        self.ipos = x, y
        self.tpos = int(x + w / 2 - text_w / 2), int(y + h / 2 - text_h / 2)
        self.cb = cb
        self.shown = False
        self.pressed = False