def godowninflames(self, hit_by_plane=None): if hit_by_plane and hit_by_plane in self.shotlist: hittime = self.shotlist[hit_by_plane] if BubPlayer.FrameCounter < hittime + 60: del self.shotlist[hit_by_plane] scoreboard() self.seticon(self.getico()) self.gen.append(self.fly()) trail = [(self.x, self.y)] * 7 ico = images.sprget(PlayerBubbles.explosion[0]) s = ActiveSprite(ico, self.x + self.ico.w // 2 - CELL, self.y + self.ico.h // 2 - CELL) s.gen.append(s.die(PlayerBubbles.explosion)) self.bubber.emotic(self, 4) while True: yield None if random.random() < 0.37: ico = images.sprget(Bubble.exploding_bubbles[0]) x, y = random.choice(trail) x += random.randint(-10, 10) y += random.randint(-10, 10) s = ActiveSprite(ico, x + 2, y + 2) s.gen.append(s.die(Bubble.exploding_bubbles)) if random.random() < 0.5: yield None if 90 <= self.angle < 270: lst = [0, 0, 0, 0, -1, -1, -1, 1, 1] else: lst = [0, 0, 0, 0, -1, -1, 1, 1, 1] self.turn(random.choice(lst)) trail.pop(0) trail.append((self.x, self.y))
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 __init__(self, dragon, target, timeout): img = images.sprget(PlayerBubbles.explosion[2]) ActiveSprite.__init__(self, img, -img.w, 0) self.dragon = dragon self.target = target self.timeout = timeout self.gen.append(self.follow()) self.recenter(PlayerBubbles.explosion[2]) for imgnum, delay in self.numlist: images.sprget(imgnum) # preload
def extra_aquarium(): from mnstrmap import Flood from player import BubPlayer for i in range(200): if 'flood' not in curboard.sprites: # only one flooding at a time break yield 0 if curboard.cleaning_gen_state: return else: return curboard.sprites['flood'] = [] gl = curboard.sprites.setdefault('background', []) curboard.holes = True # so that random PlainBubbles show up anyway walls = curboard.sprites['walls'] seen = {} def newsprite(ico, x, y): s = gamesrv.Sprite(ico, x, y) s.to_back(walls[0]) gl.append(s) return s def fishplayers(ymin): for d in BubPlayer.DragonList: if d not in seen and d.y >= ymin: seen[d] = True d.become_fish() d.bubber.emotic(d, 4) waves_icons = [images.sprget(n) for n in Flood.waves] fill_icon = images.sprget(Flood.fill) waves_sprites = [newsprite(waves_icons[0], x, bheight-CELL) for x in range(2*CELL + HALFCELL, bwidth - 2*CELL, CELL)] while waves_sprites[0].y > -fill_icon.h: fishplayers(waves_sprites[0].y) yield 0 waves_icons.append(waves_icons.pop(0)) for s in waves_sprites: s.seticon(waves_icons[0]) fishplayers(waves_sprites[0].y) yield 0 for s in waves_sprites: newsprite(fill_icon, s.x, s.y) for s in waves_sprites: s.step(0, -16) for s in waves_sprites: s.kill() BubPlayer.SuperFish = True fishplayers(-sys.maxint)
def falling(self): bubber = getattr(self, 'bubber', None) while not onground(self.x, self.y): yield None ny = self.y + 3 if (ny & 15) > 14: ny = (ny // 16 + 1) * 16 elif (ny & 15) < 3: ny = (ny // 16) * 16 nx = self.x if nx < 32: nx += 1 + (self.vx - 1) * (bubber is not None) elif nx > boards.bwidth - 64: nx -= 1 + (self.vx - 1) * (bubber is not None) elif bubber: dx = bubber.wannago(self.dcap) if dx and dx != self.dir: self.dir = dx self.resetimages() self.setimages(None) if dx and not self.blocked(): nx += self.vx * dx self.seticon(images.sprget(self.imgrange1())) self.move(nx, ny) if self.y >= boards.bheight: self.vertical_warp() if bubber: nextgen = self.playing_monster else: nextgen = self.walking self.gen.append(nextgen())
def __init__(self, text): RPicture.__init__(self) x = 0 for c in text: ico = images.sprget(self.map[c]) self.put(ico, dx=x) x += ico.w + 1
def screen_bonus(): pairs = [] for p in BubPlayer.PlayerList: catch = p.stats.get('bonus', {}) for p2, count in catch.items(): if count > 1: pairs.append((count, p, p2)) random.shuffle(pairs) pairs.sort() pairs.reverse() seen = {} npairs = [] for count, p, p2 in pairs: if p2 not in seen: npairs.append((count, p, p2)) seen[p2] = 1 pairs = npairs del pairs[5:] lines = [] if pairs: lines.append([RText('Best Bonus Catchers')]) for count, p, p2 in pairs: pic = RPicture() pic.put(p.icons[1, +1], 0) pic.put(images.sprget(p2), 44) lines.append([pic, RNumber(str(count))]) return lines
def __init__(self, pn, nimages=None, top=None): if nimages is None: nimages = self.nimages[pn] b = boards.curboard if top is None: top = b.top if top == 0: testline = b.walls[-1] x, y = self.findhole(testline), boards.bheight dx, dy = 0, -1 elif top == 1: testline = b.walls[0] x, y = self.findhole(testline), -2 * CELL dx, dy = 0, 1 elif top == 2: x, y = -2 * CELL, random.randint(2 * CELL, boards.bheight - 4 * CELL) dx, dy = 1, 0 else: # top == 3: x, y = (boards.bwidth - CELL, random.randint(2 * CELL, boards.bheight - 4 * CELL)) dx, dy = -1, 0 Bubble.__init__(self, images.sprget((self.flip, nimages[0])), x, y) self.gen.append( self.normal_movements(dx=dx, dy=dy, timeout=self.timeout)) if len(nimages) == 3: nimages = [nimages[1], nimages[2], nimages[1], nimages[0]] if len(nimages) > 1: self.setimages(self.cyclic([(self.flip, n) for n in nimages]))
def bgen(self, limittime=60.1): # 0:60 self.score = {} for t in boards.initsubgame(music, self.displaypoints): yield t self.lemmap = {} for key in localmap: self.lemmap[key] = images.sprget(key) tc = boards.TimeCounter(limittime) self.lemlist = [] self.lemtotal = 0 for t in self.frame(): t = boards.normal_frame() yield t tc.update(t) if tc.time == 0.0: break tc.restore() for s in self.lemlist[:]: if s.alive: s.kill() for s in images.ActiveSprites[:]: if isinstance(s, Bubble): s.pop() for t in boards.result_ranking(self.score.copy(), self.lemtotal): yield t
def loadicons(self, flip): icons = self.transformedicons[flip] if flip == 'fish': for dir in (-1, 1): for key, value in self.FISH_MODE_MAP.items(): if value == 'black': flip = '' else: flip, index = value value = GreenAndBlue.fish[self.pn][index] if dir > 0: flip = flip or 'hflip' icons[key, dir] = images.sprget((flip, value)) else: for key, value in self.iconnames.items(): icons[key] = images.sprget((flip, value))
def __init__(self, d, x, y, dir, special_bubble=None, angle=0, thrustfactor=None, shootthrust=None): self.d = d pn = d.bubber.pn imglist1 = GreenAndBlue.new_bubbles[pn] imglist2 = GreenAndBlue.normal_bubbles[pn] if angle: asin, acos = math.sin(angle), math.cos(angle) else: asin, acos = 0, 1 Bubble.__init__(self, images.sprget(imglist1[0]), x + 12 * dir, y) self.setimages(self.imgseq(imglist1[1:] + imglist2[2:3], 4)) if shootthrust is None: shootthrust = d.dcap['shootthrust'] hspeed = dir * shootthrust if thrustfactor is not None: negative = hspeed < 0 hspeed = (abs(hspeed) - 4.0) * thrustfactor + 4.0 if negative: hspeed = -hspeed self.gen.append(self.throw_bubble(hspeed, special_bubble, (acos, asin)))
def recenter(self, imgnum): s = self.target if not s.alive or not s.touchable: self.kill() else: img = images.sprget(imgnum) self.move(s.x + (s.ico.w - img.w) // 2, s.y + (s.ico.h - img.h) // 2, img)
def __init__(self, x0, y0, poplist, dirs=None, countdown=0, flip=''): ico = images.sprget((flip, Fire.ground[0])) ActiveSprite.__init__(self, ico, x0 * CELL, y0 * CELL) if not countdown: dirs = [] self.poplist = poplist self.gen.append(self.burning(dirs, countdown)) self.setimages(self.cyclic([(flip, n) for n in Fire.ground], 1))
def crashed(self): self.untouchable() self.play(snd_crash) ico = images.sprget(Monky.decay_weapon[1]) self.seticon(ico) self.step(self.ico.w // 2 - CELL, self.ico.h // 2 - CELL) self.gen.append(self.die(Monky.decay_weapon[1:], 4)) yield None
def ranking_picture(results, maximum, givepoints): if maximum is None: maximum = 0 for n in results.values(): maximum += n maximum = maximum or 1 ranking = [] teamrank = [0, 0] teamplayers = [[], []] for p, n in results.items(): if p.team != -1: teamrank[p.team] += n teamplayers[p.team].append((n, p)) else: ranking.append((n, random.random(), p)) teamplayers[0].sort() teamplayers[0].reverse() teamplayers[1].sort() teamplayers[1].reverse() if teamplayers[0] != []: ranking.append((teamrank[0], random.random(), teamplayers[0])) if teamplayers[1] != []: ranking.append((teamrank[1], random.random(), teamplayers[1])) ranking.sort() ranking.reverse() nbpoints = givepoints and ((len(ranking) + 1) // 2) * 10000 lines = [] for (n, dummy, bubber), i in zip(ranking, range(len(ranking))): pic = RPicture() if isinstance(bubber, list): fraction = (nbpoints // (10 * len(bubber))) * 10 total = fraction * len(bubber) for n, bub in bubber: bub.givepoints(fraction) bubber = bubber[0][1] pic.put(images.sprget(('hat', bubber.team))) else: if len(ranking) == 1: icon = 0 elif i == 0: icon = 10 elif i == len(ranking) - 1: icon = 9 else: icon = 0 pic.put(bubber.icons[icon, +1]) total = 0 line = [] if nbpoints > 0: line.append(RPoints(bubber, nbpoints)) bubber.givepoints(nbpoints - total) nbpoints -= 10000 line.append(pic) line.append(RNumber(str(int(n * 100.00001 / maximum)) + '%')) lines.append(line) return lines
def getico(self): a = self.angle // ANGLE_STEP if self.flipped: if a: a = ANGLE_COUNT - a key = 'vflip', ('camel', a, self.bubber.pn) else: key = 'camel', a, self.bubber.pn return images.sprget(key)
def __init__(self, arkanoid, bubber, px, py): ico = images.sprget(('ark-paddle', bubber.pn)) ActiveSprite.__init__(self, ico, px - (ico.w - 2 * CELL) // 2, py - (ico.h - 2 * CELL) // 2) self.arkanoid = arkanoid self.bubber = bubber self.timeleft = None self.gen.append(self.bounce_down()) self.gen.append(self.bkgndstuff()) self.arkanoid.paddles.append(self)
def __init__(self, x, y, hspeed, author): if hspeed > 0: imgs = PlayerBubbles.right_weapon else: imgs = PlayerBubbles.left_weapon ActiveSprite.__init__(self, images.sprget(imgs[-1]), x, y) self.setimages(self.cyclic(imgs, 2)) self.author = author self.gen.append(self.moving(hspeed)) self.play(images.Snd.Shh)
def crash(self): self.move(self.x - self.dir[0], self.y - self.dir[1], self.icons[self.dir+self.dir]) self.to_back() self.play(snd_crash) ico = images.sprget(Monky.decay_weapon[1]) s = ActiveSprite(ico, self.x + self.ico.w//2 - CELL, self.y + self.ico.h//2 - CELL) s.gen.append(s.die(Monky.decay_weapon[1:], 4)) self.stop()
def __init__(self, paddle): self.paddle = paddle imglist1 = GreenAndBlue.new_bubbles[paddle.bubber.pn] ActiveSprite.__init__(self, images.sprget(imglist1[0]), paddle.x + paddle.ico.w // 2, paddle.y - Ball.Y_MARGIN) self.missed = 0 self.setimages(self.imgseq(imglist1[1:], 6)) self.bounceangle(0.2) self.gen.append(self.flying())
def xyiconumber(digits, x, y, pts, lst, width=7): if pts >= 10**width: pts = 10**width - 1 for l in range(width): ico = images.sprget(digits[pts % 10]) lst.append((x + (ico.w + 1) * (width - 1 - l), y, ico)) pts = pts // 10 if not pts: break return lst[-1][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']
def __init__(self, x, y, poplist): ActiveSprite.__init__(self, images.sprget(SpinningBalls.free[-1]), x, y) self.poplist = poplist self.gen.append(self.dropping()) imgs = SpinningBalls.free if random.random() < 0.5: imgs = list(imgs) imgs.reverse() self.setimages(self.cyclic(imgs, random.randrange(2, 5))) self.touchable = 1
def vjumping(self, limity, ndir): self.setimages(None) yield None self.dir = -self.dir self.seticon(images.sprget(self.imgrange()[0])) for i in range(9): yield None self.dir = -self.dir self.seticon(images.sprget(self.imgrange()[0])) for i in range(4): yield None self.dir = ndir self.seticon(images.sprget(self.imgrange1())) for ny in range(self.y - 4, limity - 4, -4): self.move(self.x, ny) if ny < -32: self.vertical_warp() yield None self.resetimages() self.gen.append(self.default_mode())
def to_front(self): ActiveSprite.to_front(self) if self.dcap['overlayglasses']: ico = images.sprget(('glasses', self.dir)) y = self.y + self.overlayyoffset if self.overlaysprite is None or not self.overlaysprite.alive: self.overlaysprite = images.ActiveSprite(ico, self.x, y) else: self.overlaysprite.to_front() self.overlaysprite.move(self.x, y, ico) self.overlaysprite.gen = [self.overlaysprite.die([None])]
def kill(self): images.Snd.Pop.play(1.0, pad=0.0) images.Snd.Pop.play(1.0, pad=1.0) ico = images.sprget(Bubble.exploding_bubbles[0]) for i in range(11): s = ActiveSprite(ico, self.x + random.randrange(self.ico.w) - CELL, self.y + random.randrange(self.ico.h) - CELL) s.gen.append(s.die(Bubble.exploding_bubbles)) try: self.arkanoid.paddles.remove(self) except ValueError: pass ActiveSprite.kill(self)
def __init__(self, mnstrdef, x=None, y=None, dir=None, in_list=None): self.mdef = mnstrdef self.ptag = None if dir is None: dir = mnstrdef.dir if x is None: x = mnstrdef.x * CELL if y is None: y = mnstrdef.y * CELL self.dir = dir ActiveSprite.__init__(self, images.sprget(self.imgrange()[0]), x, y) self.gen.append(self.waiting()) if in_list is None: in_list = BubPlayer.MonsterList self.in_list = in_list self.in_list.append(self) self.no_shoot_before = 0
def __init__(self, pacman, x, y): left = random.random() < 0.5 if left: ico = Ghost.left[0] else: ico = Ghost.right[0] PacSprite.__init__(self, images.sprget(ico), x, y) self.pacman = pacman self.gen.append(self.waiting()) if left: self.wannadx = -1 else: self.wannadx = 1 self.resetimages(self.wannadx, self.wannady)
def jumpout(self): # jumping out of the bubble self.seticon(images.sprget(self.mdef.jailed[1])) dxy = [(random.random() - 0.5) * 9.0, (random.random() + 0.5) * (-5.0)] for n in self.parabolic(dxy): yield n if dxy[1] >= 2.0: break if dxy[0] < 0: self.dir = -1 else: self.dir = 1 self.touchable = 1 self.gen.append(self.falling())
def __init__(self, x, y, dir, watercells, poplist, repeat): ActiveSprite.__init__(self, images.sprget(Water.top), x, y) self.poplist = poplist self.take_with_me = [] self.ping = 0 self.repeat = repeat self.watercells = watercells self.touchable = repeat % 3 == 1 if (x, y, dir) not in watercells: watercells[x, y, dir] = self if None not in watercells or not watercells[None].alive: self.in_charge() else: watercells[x, y, dir].join(self)