Beispiel #1
0
def scoreboard(reset=0, inplace=0, compresslimittime=0):
    endgame = 1
    if reset:
        for p in BubPlayer.PlayerList:
            if inplace:
                for s in p.letters.values():
                    if isinstance(s, ActiveSprite):
                        s.kill()
            if len(p.letters) == 6:
                p.letters.clear()
            for key in p.letters:
                p.letters[key] = 2
    brd = boards.curboard
    if not brd or not gamesrv.sprites_by_n:
        return
    lst = []
    bubblesshown = {}
    plist = []
    teamslist = [[], []]
    teamspoints = [0, 0]
    for p in BubPlayer.PlayerList:
        if p.isplaying():
            if p.lives != 0:
                endgame = 0
        else:
            if not p.keepalive:
                continue
            if p.keepalive < time.time():
                p.reset()
                continue
        if BubPlayer.DisplayPoints is not None:
            points = BubPlayer.DisplayPoints(p)
        else:
            points = p.points
        if p.team == -1:
            plist.append((points, p, None))
        else:
            teamslist[p.team].append((points, p))
            teamspoints[p.team] += points
    teamslist[0].sort()
    teamslist[1].sort()
    plist.append((teamspoints[0], None, teamslist[0]))
    plist.append((teamspoints[1], None, teamslist[1]))
    plist.sort()
    x0 = boards.bwidth
    y0 = boards.bheight
    for score, p, t in plist:
        if p:
            if p.lives == 0:
                ico = images.sprget(GreenAndBlue.gameover[p.pn][0])
            elif p.icons:
                if p.isplaying():
                    mode = 0
                else:
                    mode = 11
                ico = BubPlayer.OverridePlayerIcon or p.icons[mode, -1]
            lst.append((x0 + 9 * CELL - ico.w, y0 - ico.h, ico))
            #if boards.curboard.wastingplay is None:
            for l in range(6):
                name = bubbles.extend_name(l)
                if name in p.letters:
                    x, y = x0 + l * (CELL - 1), y0 - 3 * CELL
                    imglist = getattr(LetterBubbles, name)
                    ico = images.sprget(imglist[1])
                    if gamesrv.game.End in (0, 1):
                        s = p.letters[name]
                        if (isinstance(s, ActiveSprite)
                                and BubPlayer.FrameCounter <= s.timeout):
                            s.move(x, y)
                            bubblesshown[s] = 1
                            continue
                        if s == 1:
                            s = ActiveSprite(ico, x, y)
                            s.setimages(
                                s.cyclic([
                                    imglist[0], imglist[1], imglist[2],
                                    imglist[1]
                                ]))
                            s.timeout = BubPlayer.FrameCounter + 500
                            p.letters[name] = s
                            bubblesshown[s] = 1
                            continue
                    lst.append((x, y, ico))
    ##        else:
    ##            ico = images.sprget(Bonuses.blue_sugar)
    ##            lst.append((x0+12, y0-3*CELL-8, ico))
    ##            xyiconumber(DigitsMisc.digits_white, x0-19, y0-3*CELL+5,
    ##                        p.bonbons, lst)
            xyiconumber(GreenAndBlue.digits[p.pn], x0 + 2, y0 - 18, score, lst)
            if p.lives is not None and p.lives > 0:
                xyiconumber(DigitsMisc.digits_white,
                            x0 + 7 * CELL,
                            y0 - 18,
                            p.lives,
                            lst,
                            width=2)
            x = x0 + 13 * HALFCELL
            for ico in p.nameicons:
                x -= 7
                lst.append((x, y0 - 35, ico))
            y0 -= 7 * HALFCELL
        else:  # Team
            for pscore, p in t:
                if p.lives == 0:
                    ico = images.sprget(GreenAndBlue.gameover[p.pn][0])
                elif p.icons:
                    if p.isplaying():
                        mode = 0
                    else:
                        mode = 11
                    ico = BubPlayer.OverridePlayerIcon or p.icons[mode, -1]
                lst.append((x0 + 9 * CELL - ico.w, y0 - ico.h, ico))
                for l in range(6):
                    name = bubbles.extend_name(l)
                    if name in p.letters:
                        x, y = x0 + l * (CELL - 1), y0 - 2 * CELL
                        imglist = getattr(LetterBubbles, name)
                        ico = images.sprget(imglist[1])
                        if gamesrv.game.End in (0, 1):
                            s = p.letters[name]
                            if (isinstance(s, ActiveSprite)
                                    and BubPlayer.FrameCounter <= s.timeout):
                                s.move(x, y)
                                bubblesshown[s] = 1
                                continue
                            if s == 1:
                                s = ActiveSprite(ico, x, y)
                                s.setimages(
                                    s.cyclic([
                                        imglist[0], imglist[1], imglist[2],
                                        imglist[1]
                                    ]))
                                s.timeout = BubPlayer.FrameCounter + 500
                                p.letters[name] = s
                                bubblesshown[s] = 1
                                continue
                        lst.append((x, y, ico))
                x = x0 + 13 * HALFCELL
                for ico in p.nameicons:
                    x -= 7
                    lst.append((x, y0 - 19, ico))
                y0 -= 4 * HALFCELL
            if t != []:
                xyiconumber(GreenAndBlue.digits[t[-1][1].pn], x0 + 2, y0 - 18,
                            score, lst)
                ico = images.sprget(('hat', p.team, -1, 1))
                lst.append((x0 + 9 * CELL - ico.w, y0 - ico.h + 16, ico))
                y0 -= 5 * HALFCELL
    for p in BubPlayer.PlayerList:
        for name, s in p.letters.items():
            if isinstance(s, ActiveSprite) and s not in bubblesshown:
                p.letters[name] = 2
                s.kill()
    compressable = len(lst)
    #if BubPlayer.HighScoreColor is not None:
    #    x = xyiconumber(GreenAndBlue.digits[BubPlayer.HighScoreColor],
    #                    x0+2*CELL, HALFCELL, BubPlayer.HighScore, lst)
    #    ico = images.sprget(GreenAndBlue.players[BubPlayer.HighScoreColor][3])
    #    lst.append((x-5*HALFCELL, 1, ico))
    if BubPlayer.LimitScoreColor is not None:
        xyiconumber(GreenAndBlue.digits[BubPlayer.LimitScoreColor],
                    x0 + 2 * CELL, HALFCELL, BubPlayer.LimitScore, lst)
    if BubPlayer.LimitTime is not None:
        seconds = int(BubPlayer.LimitTime)
        xyiconumber(DigitsMisc.digits_white,
                    x0 + 2 * CELL,
                    HALFCELL,
                    seconds // 60,
                    lst,
                    width=3)
        ico = images.sprget('colon')
        lst.append((x0 + 5 * CELL - 1, HALFCELL + 1, ico))
        seconds = seconds % 60
        ico = images.sprget(DigitsMisc.digits_white[seconds // 10])
        lst.append((x0 + 6 * CELL, HALFCELL, ico))
        ico = images.sprget(DigitsMisc.digits_white[seconds % 10])
        lst.append((x0 + 6 * CELL + ico.w, HALFCELL, ico))
        ymin = HALFCELL + ico.h
    elif compresslimittime:
        ico = images.sprget(DigitsMisc.digits_white[0])
        ymin = HALFCELL + ico.h
    else:
        ymin = 0
    if not brd.bonuslevel:
        if brd.num < 99:
            xyiconumber(DigitsMisc.digits_white,
                        2,
                        2,
                        brd.num + 1,
                        lst,
                        width=2)
        else:
            xyiconumber(DigitsMisc.digits_white,
                        2,
                        2,
                        brd.num + 1,
                        lst,
                        width=3)

    # compress the scoreboard vertically if it doesn't fit
    ymin += HALFCELL
    if y0 < ymin:
        factor = float(boards.bheight - ymin) / (boards.bheight - y0)
        shift = ymin - y0 * factor + 0.5
        for i in range(compressable):
            x, y, ico = lst[i]
            lst[i] = x, int((y + ico.h) * factor + shift) - ico.h, ico

    brd.writesprites('scoreboard', lst)

    if gamesrv.game.End in (0, 1):
        gamesrv.game.End = endgame
Beispiel #2
0
class Pac(PacSprite):
    no_hat = 1

    def __init__(self, pacman, bubber, x, y, dcap):
        ico = GreenAndBlue.normal_bubbles[bubber.pn][1]
        PacSprite.__init__(self, images.sprget(('eyes', 0, 0)), x, y)
        self.bubble = ActiveSprite(images.sprget(ico), x, y)
        self.bubber = bubber
        self.pacman = pacman
        self.ready = 0
        self.gen.append(self.playing())
        self.pacman.pacs.append(self)
        self.dcap = dcap

    def resetimages(self, dx, dy):
        self.ready = 1
        self.setimages(
            self.cyclic([('pac-lg', dx, dy), 'pac-black', ('pac-sm', dx, dy)],
                        5))

    def to_front(self):
        self.bubble.to_front()
        ActiveSprite.to_front(self)

    def kill(self):
        self.play(images.Snd.Pop)
        self.bubble.gen = [self.bubble.die(Bubble.exploding_bubbles)]
        self.pacman.latestposition[self.bubber] = self.x, self.y
        try:
            self.bubber.dragons.remove(self)
        except ValueError:
            pass
        try:
            self.pacman.pacs.remove(self)
        except ValueError:
            pass
        ActiveSprite.kill(self)

    def playing(self):
        bubber = self.bubber
        for t in self.moving():
            if self.pacman.ready:
                d = [(bubber.key_left, -1, 0), (bubber.key_right, 1, 0),
                     (bubber.key_jump, 0, -1), (bubber.key_fire, 0, 1)]
                d.sort()
                if d[-1][0] > d[-2][0]:
                    self.wannadx, self.wannady = d[-1][1:]

            self.bubble.move(self.x, self.y)
            yield None

            if self.ready:
                touching = images.touching(self.x + CELL - 3,
                                           self.y + CELL - 3, 6, 6)
                touching.reverse()
                for s in touching:
                    if isinstance(s, Bonus):
                        s.touched(self)
                    elif isinstance(s, PacGhost):
                        self.kill()
                        return