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 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 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 emotic(self, dragon, strenght): bottom_up = hasattr(dragon, 'bottom_up') and dragon.bottom_up() vshift = getattr(dragon, 'up', 0.0) for i in range(7): angle = math.pi / 6 * i dx, dy = -math.cos(angle), -math.sin(angle) nx = random.randrange(3, 12) * dx ny = random.randrange(3, 9) * dy - 12 if bottom_up: dy = -dy ny = -ny e = ActiveSprite( images.sprget(('vflip' * bottom_up, ('emotic', i))), int(dragon.x + 8 + nx), int(dragon.y + 8 + ny - vshift)) e.gen.append( e.straightline((3.3 + random.random()) * dx, (2.3 + random.random()) * dy)) e.gen.append(e.die([None], strenght))
def control(self, delay=0): bubber = self.bubber prev_key_jump = 0 for i in range(delay): yield None shootdelay = 0 while True: wannago = bubber.wannago(self.dcap) self.turn(wannago) if shootdelay: shootdelay -= 1 elif bubber.key_fire: x = self.x + self.ico.w // 2 y = self.y + self.ico.h // 2 acos, asin = ANGLE_TABLE[self.angle] x += acos * 20 y += asin * 20 if self.flipped: acos = -acos asin = -asin x -= asin * 5 y += acos * 5 self.play(snd_fire) Shot(self, int(x), int(y), self.angle, 2) Shot(self, int(x), int(y), self.angle) shootdelay = 7 for i in range(2): if bubber.key_jump > prev_key_jump: self.flipped = not self.flipped prev_key_jump = bubber.key_jump yield None for s in self.touching(12): if isinstance(s, Plane) and s is not self: ico = images.sprget(Monky.decay_weapon[1]) s1 = ActiveSprite( ico, (self.x + s.x) // 2 + self.ico.w // 2 - CELL, (self.y + s.y) // 2 + self.ico.h // 2 - CELL) s1.gen.append(s1.die(Monky.decay_weapon[1:], 4)) s1.play(snd_crash) self.gen = [self.godowninflames(s)] s.gen = [s.godowninflames(self)]
def normal_movements(self): yfp = 0.0 hfp = 0 angryticks = 0 mytime = 0 privatetime = 0 while 1: dcap = self.dcap self.poplist = [self] carrying = dcap['carrying'] while carrying and carrying[0][0] < BubPlayer.FrameCounter: timeout, bonus = carrying.pop(0) if bonus.endaction: bonus.endaction(self) del bonus bubber = self.bubber wannafire = bubber.getkey(dcap, 'key_fire') wannajump = bubber.getkey(dcap, 'key_jump') wannago = bubber.wannago(dcap) bottom_up = self.bottom_up() onground1 = (onground, underground)[bottom_up] if dcap['autofire']: wannafire = 1 if dcap['pinball']: wannajump = 1 if dcap['pinball'] > 1: if self.up: self.up *= 0.982**dcap['pinball'] if dcap['hotstuff']: if not wannago: if self.dir * (random.random() - 0.07) < 0: wannago = -1 else: wannago = 1 wannafire = 1 if self.fire > (11 // dcap['hotstuff']): self.fire = 0 ## if dcap['hotstuff'] > 1 and random.random() < 0.4: ## from bubbles import FireDrop ## FireDrop(self.x + HALFCELL, self.y + HALFCELL) if wannago: self.dir = wannago * dcap['lookforward'] if self.x & 1: self.step(self.dir, 0) if dcap['slippy']: vx = dcap['vslippy'] if wannago: vx += wannago * 0.05 else: vx *= 0.95 if vx < 0.0: wannago = -1 else: wannago = 1 dcap['vslippy'] = vx mytime = (mytime + dcap['lookforward']) % 12 hfp += abs(vx) else: hfp += dcap['hspeed'] ## if self.glueddown: ## if wannajump or not dcap['nojump']: ## del self.glueddown ## else: ## # glued gliding movements ## self.step(self.x & 1, self.y & 1) ## if wannago: ## mytime = (mytime+dcap['lookforward']) % 12 ## else: ## hfp = 0 ## while hfp > 0 and self.glueddown: ## gx, gy = self.glueddown ## dx = wannago*gy ## dy = -wannago*gx ## x0 = (self.x + gx + dx) // CELL + 1 ## y0 = (self.y + gy + dy) // CELL + 1 ## if ' ' == bget(x0+dx, y0+dy) == bget(x0+dx-gx, y0+dy-gy): ## self.step(2*dx, 2*dy) ## # detached from this wall? ## x1 = (self.x + gx + dx) // CELL + 1 ## y1 = (self.y + gy + dy) // CELL + 1 ## if (' ' == bget(x1-dx+gx, y1-dy+gy) ## == bget(x0 +gx, y0 +gy) ## == bget(x0+dx+gx, y0+dy+gy)): ## if bget(x0-dx+gx, y0-dy+gy) != ' ': ## # rotate around the corner ## self.glueddown = -dx, -dy ## self.step(2*gx, 2*gy) ## else: ## del self.glueddown ## elif bget(x0-gx, y0-gy) == ' ': ## # attach to the wall into which we are running ## if (self.x*dx | self.y*dy) % CELL != 0: ## if ((((self.x-2*dx)*dx | (self.y-2*dy)*dy) & ## ((self.x-4*dx)*dx | (self.y-4*dy)*dy)) ## % CELL == 0): ## self.step(-2*dx, -2*dy) ## else: ## del self.glueddown ## else: ## self.glueddown = dx, dy ## else: ## del self.glueddown ## self.vertical_warp() ## hfp -= 0.82 # slightly faster than usual # normal left or right movements breakwalls = dcap['breakwalls'] while hfp > 0: hfp -= 1 dir = 0 if wannago == -1: x0 = (self.x + 1) // CELL y0 = (self.y + 4 - bottom_up * (CELL + 4)) // CELL + 1 y0bis = (self.y + CELL - 1) // CELL + 1 - bottom_up if bget(x0, y0) == ' ' == bget(x0, y0bis): dir = -1 elif breakwalls: self.breakwalls(x0, y0bis, -1) elif wannago == 1: x0 = (self.x - 3) // CELL + 2 y0 = self.y // CELL + 1 - bottom_up y0bis = (self.y + CELL - 1) // CELL + 1 - bottom_up if bget(x0, y0) == ' ' == bget(x0, y0bis): dir = +1 elif breakwalls: self.breakwalls(x0, y0bis, 1) self.step(2 * dir, 0) if dir: mytime = (mytime + dcap['lookforward']) % 12 else: f = -dcap['vslippy'] * (dcap['slippy'] + 1) / 3.0 dcap['vslippy'] = max(min(f, 10.0), -10.0) hfp = 0 onbubble = None if not dcap['infinite_shield']: touching = images.touching(self.x + 1, self.y + 1, 30, 30) touching.reverse() for s in touching: if s.touched(self): onbubble = s elif bubber.key_left or bubber.key_right or bubber.key_jump or bubber.key_fire: dcap['infinite_shield'] = 0 dir = self.dir icons = self.getcurrenticons('vflip' * bottom_up) if self.playing_fish: mode = self.one_fish_frame(onground1, bottom_up) elif self.up: # going up mode = 9 self.up -= dcap['gravity'] if (self.up, -self.up)[bottom_up] < 4.0: self.up = 0.0 mode = 10 else: ny = self.y + yfp - self.up self.move(self.x, int(ny)) yfp = ny - self.y self.vertical_warp() if wannago and dcap['teleport']: for t in self.teleport(wannago, icons, 0): yield t else: # going down or staying on ground if wannajump and onbubble: ground = True onbubble.dragon_jumped = True, bottom_up else: ground = onground1(self.x, self.y) if ground: if wannajump: self.play(images.Snd.Jump) if dcap['jumpdown'] and not onbubble: self.step(0, (1, -1)[bottom_up]) mode = 10 bubber.emotic(self, 4) else: yfp = 0.0 self.up = (7.5, -7.5)[bottom_up] mode = 9 else: mode = mytime // 4 if wannago and dcap['teleport']: for t in self.teleport(wannago, icons): yield t else: mode = 10 if dcap['fly']: self.fly_counter += 1 if self.fly_counter < dcap['fly']: ny = self.y else: del self.fly_counter ny = self.y + (1, -1)[bottom_up] else: ny = (self.y + (4, -1)[bottom_up]) & ~3 nx = self.x if nx < 32: nx += 2 elif nx > boards.bwidth - 64: nx -= 2 self.move(nx, ny) self.vertical_warp() if wannago and dcap['teleport']: for t in self.teleport(wannago, icons, 0): yield t if wannafire and not self.fire: self.firenow() self.hatangle = 1 if self.fire: if self.fire <= 5: mode = 3 self.hatangle = 2 elif self.fire <= 10: mode = 4 self.hatangle = 3 self.fire += 1 if self.fire >= 64 // dcap['firerate']: self.fire = 0 s = dcap['shield'] if s: if dcap['infinite_shield'] and s < 20: s += 4 s -= 1 if dcap['overlayglasses']: self.overlayyoffset = ({ 3: 2, 4: 0, 9: 3, 10: 5 }.get(mode, 4) + self.playing_fish * 2) elif s & 2: mode = 11 dcap['shield'] = s if dcap['ring']: # and random.random() > 0.1: if dcap['ring'] > 1: mode = 12 else: mode = 11 self.seticon(icons[mode, dir]) self.watermoveable = not wannajump privatetime += BubPlayer.PlayersPrivateTime while privatetime >= 100: yield None privatetime -= 100 if self.angry: if angryticks == 0: s = ActiveSprite(icons[11, self.dir], self.x, self.y) s.gen.append(s.die([None], speed=10)) angryticks = 6 angryticks -= 1
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
def stopping(self): self.move(self.x, -self.ico.h) positions = [(py // CELL, px // CELL) for px, py in self.brick_positions() if py >= 0] positions.sort() positions = [(px, py) for py, px in positions] for b in self.bricks: b.stop(self.tetris) if b.ty < 0: b.remove() self.bricks = [] staticbricks = self.tetris.staticbricks pts = 500 while 1: for px, py in positions: y = py x1 = px while (x1 - 1, y) in staticbricks: x1 -= 1 if bget(x1 - 1, y) != '#': continue x2 = px while (x2, y) in staticbricks: x2 += 1 if bget(x2, y) != '#': continue if x2 - x1 < 2: continue # full line ico = images.sprget(Bubble.exploding_bubbles[0]) self.tetris.score[self.bubber] = self.tetris.score.get( self.bubber, 0) + 1 xlist = range(x1, x2) for x in xlist: s = ActiveSprite(ico, x * CELL + random.randrange(CELL) - CELL, y * CELL + random.randrange(CELL) - CELL) s.gen.append(s.die(Bubble.exploding_bubbles)) s = staticbricks[x, y] points(x * CELL + HALFCELL, y * CELL + HALFCELL, s, pts) s.remove() if pts == 500: self.play(images.Snd.Fruit) elif pts == 4000: self.play(images.Snd.Extralife) else: self.play(images.Snd.Extra) pts *= 2 for y in range(py - 1, -1, -1): if not [x for x in xlist if (x, y) in staticbricks]: break for t in range(4): yield None if [x for x in xlist if (x, y + 1) in staticbricks]: break for x in xlist: if (x, y) in staticbricks: staticbricks[x, y].shiftdown() yield None break else: break if self.tetris.ready < 2: self.gen.append(self.playing_bubble(self))