Пример #1
0
 def forward_step(self, dir):
     s = gamesrv.Sprite(self.icons[self.dir + dir], self.x, self.y)
     self.tron.trailsprites.append(s)
     self.dir = dir
     self.cx += dir[0]
     self.cy += dir[1]
     self.move(self.cx*8-2, self.cy*8-2, self.icons[dir])
Пример #2
0
def writestr(x, y, text):
    result = []
    for c in text:
        ico = sprcharacterget(c)
        if ico is not None:
            result.append(gamesrv.Sprite(ico, x, y))
            x += 7
    return result
Пример #3
0
def extra_water_flood():
    from mnstrmap import Flood
    from monsters import Monster
    waves_icons = [images.sprget(n) for n in Flood.waves]
    fill_icon = images.sprget(Flood.fill)
    bspr = []
    if 'flood' in curboard.sprites:
        return    # only one flooding at a time
    curboard.sprites['flood'] = bspr
    waves_sprites = [gamesrv.Sprite(waves_icons[0], x, bheight-CELL)
                     for x in range(0, bwidth, CELL)]
    bspr += waves_sprites
    fill_by_line = []
    poplist = [None]
    while waves_sprites[0].y > 0:
        yield 0
        waves_icons.insert(0, waves_icons.pop())
        for s in waves_sprites:
            s.seticon(waves_icons[0])
        yield 0
        sprites = [gamesrv.Sprite(fill_icon, s.x, s.y) for s in waves_sprites]
        bspr += sprites
        fill_by_line.append(sprites)
        for s in waves_sprites:
            s.step(0, -16)
        for s in images.touching(0, waves_sprites[0].y, bwidth, bheight):
            if isinstance(s, Monster):
                s.argh(poplist)
    while 1:
        for i in range(2):
            yield 0
            waves_icons.insert(0, waves_icons.pop())
            for s in waves_sprites:
                s.seticon(waves_icons[0])
        if not fill_by_line:
            break
        for s in fill_by_line.pop():
            s.kill()
        for s in waves_sprites:
            s.step(0, 16)
    for s in waves_sprites:
        s.kill()
    del curboard.sprites['flood']
Пример #4
0
def extra_swap_up_down(N=27):
    # unregister all walls
    walls = curboard.walls_by_pos.items()
    walls.sort()
    if not walls:
        return
    curboard.walls_by_pos.clear()
    emptyline = '##' + ' '*(width-4) + '##'
    curboard.walls = [emptyline] * height
    l = curboard.sprites['walls']
    wallicon = l[0].ico
    wallpool = l[:]
    l[:] = [gamesrv.Sprite(wallicon, 0, -wallicon.h)]
    
    # force the top half of the walls on front
    #for (y,x), w in walls:
    #    if y*2 < height:
    
    # show the walls swapping up/down
    ycenter = ((height-1)*CELL) // 2
    for i in range(N):
        alpha = math.cos((math.pi*(i+1))/N)
        ymap = {}
        for y in range(height):
            ymap[y] = int(alpha*(y*CELL-ycenter)) + ycenter
        for (y,x), w in walls:
            if y in ymap:
                w.move(x*CELL, ymap[y])
        yield 0
        if i == (N+1)//2:
            # reorder the wall sprites in the middle of the swap
            walls = [((-y,x), w) for (y,x), w in walls]
            walls.sort()
            for i in range(len(walls)):
                (y,x), w = walls[i]
                walls[i] = (y,x), wallpool[i]
            walls = [((-y,x), w) for (y,x), w in walls]
            walls.sort()
            # reverse all dragons!
            from player import BubPlayer
            for dragon in BubPlayer.DragonList:
                dragon.dcap['gravity'] *= -1.0
    
    # freeze the walls in their new position
    i = 0
    for (y,x), w in walls:
        y = height-1 - y
        if 0 <= y < height and (y,x) not in curboard.walls_by_pos:
            w = wallpool[i]
            i += 1
            curboard.putwall(x, y, w)
    l[:0] = wallpool[:i]
    for w in wallpool[i:]:
        w.kill()
    curboard.reorder_walls()
Пример #5
0
 def putwall(self, x, y, w=None):
     wallicon = patget((self.num, x%self.wnx, y%self.wny), images.KEYCOL)
     if w is None:
         w = gamesrv.Sprite(wallicon, 0, bheight)
         l = self.sprites['walls']
         w.to_back(l[-1])
         l.append(w)
     self.walls_by_pos[y,x] = w
     if y >= 0:
         line = self.walls[y]
         self.walls[y] = line[:x] + '#' + line[x+1:]
Пример #6
0
 def writesprites(self, name, xyicolist):
     sprlist = self.sprites.setdefault(name, [])
     xyicolist = xyicolist[:]
     xyicolist.reverse()
     for s in sprlist[:]:
         if xyicolist:
             s.move(*xyicolist.pop())
         else:
             s.kill()
             sprlist.remove(s)
     while xyicolist:
         x, y, ico = xyicolist.pop()
         sprlist.append(gamesrv.Sprite(ico, x, y))
Пример #7
0
    def enter(self, complete=1, inplace=0, fastreenter=False):
        global curboard
        if inplace:
            print "Re -",
        print "Entering board", self.num+1
        self.set_musics()
        # add board walls
        l = self.sprites.setdefault('walls', [])
        bl = self.sprites.setdefault('borderwalls', [])
        if inplace:
            deltay = 0
        else:
            deltay = bheight
        wnx = wny = 1
        while haspat((self.num, wnx, 0)):
            wnx += 1
        while haspat((self.num, 0, wny)):
            wny += 1
        self.wnx = wnx
        self.wny = wny

        if haspat((self.num, 'l')):
            lefticon = patget((self.num, 'l'))
            if haspat((self.num, 'r')):
                righticon = patget((self.num, 'r'))
            else:
                righticon = lefticon
            xrange = range(2, self.width-2)
        else:
            xrange = range(self.width)
            lefticon = righticon = None

        if BOARD_BKGND == 1:
            gl = self.sprites.setdefault('background', [])
            xmax = (self.width-2)*CELL
            ymax = self.height*CELL
            y = -HALFCELL
            ystep = 0
            firstextra = 1
            while y < ymax:
                x = 2*CELL+HALFCELL
                xstep = 0
                while x < xmax:
                    bitmap, rect = loadpattern((self.num, xstep, ystep),
                                               images.KEYCOL)
                    bitmap, rect = images.makebkgndpattern(bitmap, rect)
                    if firstextra:
                        # special position where a bit of black might show up
                        x -= rect[2]
                        xstep = (xstep-1) % wnx
                        firstextra = 0
                        continue
                    bkgndicon = bitmap.geticon(*rect)
                    w = gamesrv.Sprite(bkgndicon, x, y + deltay)
                    gl.append(w)
                    x += rect[2]
                    xstep = (xstep+1) % wnx
                y += rect[3]
                ystep = (ystep+1) % wny
        else:
            gl = []

        if lefticon is not None:
            for y in range(0, self.height, lefticon.h // CELL):
                bl.append(gamesrv.Sprite(lefticon, 0, y*CELL + deltay))

        for y in range(self.height):
            for x in xrange:
                c = self.walls[y][x]
                if c == '#':
                    wallicon = patget((self.num, x%wnx, y%wny), images.KEYCOL)
                    w = gamesrv.Sprite(wallicon, x*CELL, y*CELL + deltay)
                    l.append(w)
                    self.walls_by_pos[y,x] = w

        if not l:
            # self.sprites['walls'] must not be empty, for putwall
            wallicon = patget((self.num, 0, 0), images.KEYCOL)
            w = gamesrv.Sprite(wallicon, 0, -wallicon.h)
            l.append(w)

        if righticon is not None:
            for y in range(0, self.height, lefticon.h // CELL):
                bl.append(gamesrv.Sprite(righticon, (self.width-2)*CELL, y*CELL + deltay))

        while deltay:
            dy = -min(deltay, 8)
            for w in gl:
                w.step(0, dy)
            for w in l:
                w.step(0, dy)
            for w in bl:
                w.step(0, dy)
            deltay += dy
            yield 1

        if inplace:
            for w in images.ActiveSprites:
                w.to_front()

        curboard = self
        if gamesrv.game:
            gamesrv.game.updateboard()
        if not complete:
            return
        # add players
        from player import BubPlayer, scoreboard
        if not inplace:
            random.shuffle(BubPlayer.PlayerList)
        scoreboard(1, inplace=inplace)
        if not fastreenter:
            random.shuffle(BubPlayer.PlayerList)
            playing = []
            for p in BubPlayer.PlayerList:
                if p.isplaying():
                    p.enterboard(playing)
                    p.zarkon()
                    playing.append(p)
            for d in BubPlayer.DragonList:
                d.enter_new_board()
        else:
            # kill stuff left over from leave(inplace=1) (Big Clock bonus only)
            import bonuses
            keepme = bonuses.Points
            dragons = {}
            playing = []
            for p in BubPlayer.PlayerList:
                if p.isplaying():
                    for d in p.dragons:
                        if hasattr(d, 'dcap'):
                            d.dcap['shield'] = 90
                        dragons[d] = True
                    playing.append(p)
            for s in images.ActiveSprites[:]:
                if isinstance(s, keepme) or s in dragons:
                    pass
                else:
                    s.kill()
        # add monsters
        if not self.bonuslevel:
            import monsters
            f_monsters = gamesrv.game.f_monsters
            if f_monsters < 0.1:
                f_monsters = max(1.0, min(2.0, (len(playing)-2)/2.2+1.0))
            for mdef in self.monsters:
                if not fastreenter:
                    yield 2
                cls = getattr(monsters, mdef.__class__.__name__)
                dir = mdef.dir
                i = random.random()
                while i < f_monsters:
                    cls(mdef, dir=dir)
                    dir = -dir
                    i += 1.0
        self.playingboard = 1
Пример #8
0
 def newsprite(ico, x, y):
     s = gamesrv.Sprite(ico, x, y)
     s.to_back(walls[0])
     gl.append(s)
     return s
Пример #9
0
def display(lines, timeleft, bgen=None, black=0):
    waves = []
    if lines:
        totalwidth = 0
        totalheight = 0
        for line in lines:
            w, h = linesize(line)
            if w > totalwidth:
                totalwidth = w
            totalheight += h
        heightmargin = (boards.bheight - 2 * CELL -
                        totalheight) // (len(lines) + 1)
        if heightmargin > VMARGIN:
            heightmargin = VMARGIN
        totalheight += heightmargin * (len(lines) + 1)

        # size in number of CELLs
        cwidth = (totalwidth + CELL - 1) // CELL
        cheight = (totalheight + CELL - 1) // CELL

        x0 = ((boards.width - cwidth) // 2) * CELL + HALFCELL
        y0 = ((boards.height - cheight) // 2) * CELL + HALFCELL
        extras = boards.curboard.sprites.setdefault('ranking', [])
        #while extras:
        #    extras.pop().kill()
        #    yield 0.12
        vspeed = -4
        while extras:
            nextras = []
            for s in extras:
                s.step(0, vspeed)
                if s.y + s.ico.h <= 0:
                    s.kill()
                else:
                    nextras.append(s)
            extras[:] = nextras
            yield 1
            vspeed -= 1

        # draw the box filled with water
        original_y0 = y0
        wallicon = boards.patget((boards.curboard.num, 0, 0), images.KEYCOL)
        if black:
            fillicon = images.sprget('gameoverbkgnd')
            waveicons = [wallicon]
            y0 = boards.bheight + CELL
        else:
            fillicon = images.sprget(Flood.fill)
            waveicons = [images.sprget(n) for n in Flood.waves]
        for y in range(y0 - CELL, y0 + cheight * CELL + CELL, CELL):
            w = gamesrv.Sprite(wallicon, x0 - CELL, y)
            extras.append(w)
        for x in range(x0, x0 + cwidth * CELL, CELL):
            w = gamesrv.Sprite(wallicon, x, y0 + cheight * CELL)
            extras.append(w)
            w = gamesrv.Sprite(waveicons[-1], x, y0 - CELL)
            extras.append(w)
            waves.append(w)
            for y in range(y0, y0 + cheight * CELL, CELL):
                w = gamesrv.Sprite(fillicon, x, y)
                extras.append(w)
        for y in range(y0 - CELL, y0 + cheight * CELL + CELL, CELL):
            w = gamesrv.Sprite(wallicon, x0 + cwidth * CELL, y)
            extras.append(w)

        # draw the individual items inside
        y = y0 + totalheight
        lines.reverse()
        for line in lines:
            linew, lineh = linesize(line)
            x = x0 + MARGIN
            y -= (lineh + heightmargin)
            for item in line:
                w, h = item.getsize()
                extras += item.render(x, y + (lineh - h) // 2)
                x += w

        vspeed = 0
        while y0 > original_y0:
            vspeed = max(vspeed - 1, original_y0 - y0)
            y0 += vspeed
            for s in extras:
                s.step(0, vspeed)
            yield 1

    while timeleft > 0.0:
        if waves:
            ico = waveicons.pop(0)
            waveicons.append(ico)
            for w in waves:
                w.seticon(ico)
        for i in range(2):
            if bgen is None:
                t = boards.normal_frame()
            else:
                try:
                    t = bgen.next()
                except StopIteration:
                    timeleft = 0.0
                    break
            timeleft -= t
            yield t
Пример #10
0
 def render(self, x, y):
     return [
         gamesrv.Sprite(ico, x + dx, y + dy) for dx, dy, ico in self.icons
     ]