Пример #1
0
 def trosballAnimation(self, timer):
     frame0 = self.theme.loadSprite('trosball.png', sprites=self)
     scale = 25. / max(frame0.get_size())
     frames = []
     for theta in range(0, 360, 15):
         frames.append(pygame.transform.rotozoom(frame0, -theta, scale))
     return Animation(0.05, timer, *frames)
Пример #2
0
    def createDisrupted(self):
        sRect = self.getRect()
        screens = [pygame.surface.Surface(sRect.size) for i in xrange(4)]

        # Because the creation of these disruption sprites is very slow, do
        # them a bit at a time so that other events don't get blocked.
        for screen in screens:
            reactor.callLater(0, self.drawSingleDisruption, screen)
        return Animation(0.1, timeNow, *screens)
Пример #3
0
 def trosballWarningAnimation(self, timer):
     frame0 = self.theme.loadSprite('trosball.png', sprites=self)
     scale = 25. / max(frame0.get_size())
     frames = []
     for theta in range(0, 360, 15):
         surface = pygame.transform.rotozoom(frame0, -theta, scale)
         # Every 90 degrees, invert the colours
         if (theta / 45) % 2 < 1:
             setToRed(surface)
         frames.append(surface)
     return Animation(0.05, timer, *frames)
Пример #4
0
 def ghostAnimation(self, team):
     if team is not None:
         frames = self.theme.loadTeamSprites(
             ['ghost1', 'ghost2', 'ghost3', 'ghost4', 'ghost3', 'ghost2'],
             team.id, self)
     else:
         lts = functools.partial(self.theme.loadTeamSprite, sprites=self)
         frames = [
             lts('ghost1', 'A'), lts('ghost2', 'B'), lts('ghost3', 'A'),
             lts('ghost4', 'B'), lts('ghost3', 'A'), lts('ghost2', 'B')]
     return [Animation(0.25, timeNow, *frames)]
Пример #5
0
    def makeShot(self, colour, sprites):
        '''
        Creates the shot sprite / animation. This is here because the Pirate
        theme needs the shot to spin, which it does not normally do.
        '''
        shotImg = self.loadSprite('%sShot.png' % (colour,), sprites=sprites)

        if self.name != 'pirate':
            return SingleImage(shotImg)

        numShotImages = 5
        degree = (360 / numShotImages)

        shots = [
            pygame.transform.rotate(shotImg, degree * i)
            for i in range(0, numShotImages)]
        return Animation(0.07, timeNow, *shots)
Пример #6
0
    def __init__(self, app, worldGUI, player, timer=None):
        super(PlayerSprite, self).__init__(app, worldGUI, player)
        if timer is None:
            timer = self.worldGUI.getTime
        self.timer = timer
        self.drawer = PlayerDrawer(app, timer)
        self._animationStart = None
        self.spriteTeam = player.team
        self.player = player
        self.nametag = NameTag(app, player.nick)
        self.countdown = CountDown(app, self.player)
        self._oldName = player.nick
        self._miniMapNameTag = None
        self.coinTally = CoinTally(app, 0)
        self.healthBar = HealthBar(
            app,
            badColour=self.app.theme.colours.badHealth,
            fairColour=self.app.theme.colours.fairHealth,
            goodColour=self.app.theme.colours.goodHealth)
        self.shieldBar = HealthBar(
            app,
            badColour=self.app.theme.colours.badShield,
            fairColour=self.app.theme.colours.fairShield,
            goodColour=self.app.theme.colours.goodShield)

        sprites = app.theme.sprites
        self.sprites = sprites

        self.ghostAnimation = sprites.ghostAnimation(
            worldGUI.getTime, self.player.team)

        self.shieldAnimation = Animation(0.15, timer, *sprites.shieldImages)

        flags = pygame.SRCALPHA
        self.alphaImage = pygame.Surface(self.canvasSize, flags)

        self.image = pygame.Surface(self.canvasSize, flags)
        self.rect = self.image.get_rect()

        # This probably shouldn't be done here.
        _t = datetime.date.today()
        self.is_christmas = _t.day in (24, 25, 26) and _t.month == 12
Пример #7
0
 def createDisrupted(self):
     screens = []
     for a in range(0, 4):
         screen = (pygame.surface.Surface((self.xFarRight - self.xFarLeft,
                                           self.gameViewer.zoneBarHeight)))
         x = y = 0
         xL = 1
         xR = self.xFarRight - self.xFarLeft - 1
         rect = pygame.rect.Rect(0, 0, 2, 2)
         disruptColours = [self.red, self.blue]
         while y < self.gameViewer.zoneBarHeight:
             while x < xR:
                 rect.left = x
                 rect.top = y
                 pygame.draw.rect(screen, random.choice(disruptColours),
                                  rect, 0)
                 x += 2
             xL += 2
             xR -= 2
             x = xL
             y += 2
         screen.set_colorkey((0, 0, 0))
         screens.append(screen)
     return Animation(0.1, timeNow, *screens)
Пример #8
0
 def trosballExplosion(self, timer):
     return Animation(0.07, timer, self.explosionFrame(0))
Пример #9
0
 def shoxwaveExplosion(self, timer):
     return Animation(0.05, timer,
                      *(self.shoxwaveFrame(i) for i in range(3)))
Пример #10
0
 def explosion(self, timer):
     return Animation(0.07, timer,
                      *(self.explosionFrame(i) for i in range(4)))
Пример #11
0
 def bigCoinAnimation(self):
     return Animation(0.07, timeNow, *self.bigCoinImages)
Пример #12
0
class PlayerSprite(UnitSprite):
    # These parameters are used to create a canvas for the player sprite object
    canvasSize = (int(33 * MAP_TO_SCREEN_SCALE + 0.5),
                  int(39 * MAP_TO_SCREEN_SCALE + 0.5))
    liveOffset = 3
    ghostOffset = 0

    def __init__(self, app, worldGUI, player, greyed=False, timer=None):
        super(PlayerSprite, self).__init__(app, worldGUI, player)
        if timer is None:
            timer = player.world.getMonotonicTime
        self.spriteTeam = player.team
        self.player = player
        self.nametag = NameTag(app, player.nick)
        self.countdown = CountDown(app, self.player)
        self._oldName = player.nick
        self.coinTally = CoinTally(app, 0)
        self.greyed = greyed
        self.healthBar = HealthBar(
            app,
            badColour=self.app.theme.colours.badHealth,
            fairColour=self.app.theme.colours.fairHealth,
            goodColour=self.app.theme.colours.goodHealth)
        self.shieldBar = HealthBar(
            app,
            badColour=self.app.theme.colours.badShield,
            fairColour=self.app.theme.colours.fairShield,
            goodColour=self.app.theme.colours.goodShield)

        sprites = app.theme.sprites
        self.greyVersion = None
        if greyed:
            sprites = sprites.greyed
        self.sprites = sprites
        self.gunImages = AngledImageCollection(
            self.getAngleFacing, *sprites.gunImages(self.player.team))
        self.machineGunImages = AngledImageCollection(
            self.getAngleFacing, *sprites.machineGunImages(self.player.team))
        self.ricoGunImages = AngledImageCollection(
            self.getAngleFacing, *sprites.ricoGunImages(self.player.team))
        self.shoxGunImages = SingleImage(sprites.shoxGun3)

        head = sprites.playerHead(self.player.team, self.player.bot)
        self.runningAnimation = [
            Animation(0.1, timer, *sprites.runningLegs),
            sprites.playerBody,
            head,
        ]
        self.ghostAnimation = sprites.ghostAnimation(self.player.team)
        self.blocker = [
            Animation(0.1, timer, sprites.blocker1, sprites.blocker1,
                      sprites.blocker2),
            head,
        ]
        self.bomber = [
            head,
            Animation(0.08, timer, sprites.bomber1, sprites.bomber2),
        ]

        self.reversingAnimation = [
            sprites.playerBody,
            Animation(0.1, timer, *sprites.backwardsLegs),
            head,
        ]

        self.turretAnimation = [
            sprites.turretBase,
            sprites.playerBody,
            head,
        ]

        self.standingAnimation = [
            sprites.playerStanding,
            sprites.playerBody,
            head,
        ]

        self.jumpingAnimation = [
            sprites.playerJumping,
            sprites.playerBody,
            head,
        ]
        self.holdingAnimation = [
            sprites.playerBody,
            sprites.playerHolding(self.player.team),
            head,
        ]
        self.fallingAnimation = self.jumpingAnimation
        self.shieldAnimation = Animation(0.15, timer, *sprites.shieldImages)
        self.jammingHat = sprites.jammingHat()

        if self.app.displaySettings.perPixelAlpha:
            flags = pygame.SRCALPHA
            self.alphaImage = pygame.Surface(self.canvasSize, flags)
        else:
            flags = 0
            self.alphaImage = None

        self.image = pygame.Surface(self.canvasSize, flags)
        self.rect = self.image.get_rect()

        # This probably shouldn't be done here.
        _t = datetime.date.today()
        self.is_christmas = _t.day in (24, 25, 26) and _t.month == 12

    def getAngleFacing(self):
        return self.player.angleFacing

    @property
    def angleFacing(self):
        return self.player.angleFacing

    def __getattr__(self, attr):
        '''
        Proxy attributes through to the underlying player class.
        '''
        return getattr(self.player, attr)

    def update(self):
        if self.player.nick != self._oldName:
            self._oldName = self.player.nick
            self.nametag = NameTag(self.app, self.player.nick)

        self.setImage()

    def _isSlow(self):
        # Consider horizontal movement of player.
        xMotion = self.player.getXKeyMotion()
        if xMotion < 0:
            return self.player._faceRight
        if xMotion > 0:
            return not self.player._faceRight
        return False

    def setImage(self):
        if not self.app.displaySettings.perPixelAlpha:
            self.image.set_alpha(None)

        self.image.fill((127, 127, 127, 0))
        self.image.set_colorkey((127, 127, 127))

        if self.player.resyncing and not self.greyed:
            if self.greyVersion is None:
                self.greyVersion = PlayerSprite(self.app,
                                                self.worldGUI,
                                                self.player,
                                                greyed=True)
            self.greyVersion.setImage()
            self.image.blit(self.greyVersion.image, (0, 0))
            return

        flip = None
        offset = self.liveOffset
        if self.player.dead:
            blitImages = self.ghostAnimation
            offset = self.ghostOffset
        elif self.player.turret:
            blitImages = self.turretAnimation
        elif self.player.bomber:
            if self.player.bomber.timeRemaining < 0.8:
                blitImages = self.bomber
            else:
                blitImages = self.blocker
        elif self.player.isAttachedToWall():
            blitImages = self.holdingAnimation
            if self.player.isAttachedToWall() == 'right':
                flip = False
            else:
                flip = True
        elif self.player.isOnGround():
            if self.player.getXKeyMotion() == 0:
                blitImages = self.standingAnimation
            elif self._isSlow():
                blitImages = self.reversingAnimation
            else:
                blitImages = self.runningAnimation
        else:
            if self.player.yVel > 0:
                blitImages = self.fallingAnimation
            else:
                blitImages = self.jumpingAnimation

        # Put the pieces together:
        for element in blitImages:
            self.image.blit(element.getImage(), (offset, 0))
        if not (self.player.dead or self.player.isAttachedToWall()
                or self.player.bomber):
            if self.player.machineGunner:
                weapon = self.machineGunImages
            elif self.player.hasRicochet:
                weapon = self.ricoGunImages
            elif self.player.shoxwave:
                weapon = self.shoxGunImages
            else:
                weapon = self.gunImages
            self.image.blit(weapon.getImage(), (offset, 0))
        if self.player.ninja:
            self.image.blit(self.sprites.ninjaHead.getImage(), (offset, 0))
        elif self.player.disruptive:
            self.image.blit(self.jammingHat.getImage(), (offset, 0))
        if self.player.hasElephant() and not self.player.dead:
            self.image.blit(self.sprites.elephant.getImage(), (offset, 0))
        if (not self.player.dead and not self.player.phaseshift
                and not self.player.ninja and self.is_christmas
                and not self.player.hasElephant()):
            self.image.blit(self.sprites.christmasHat.getImage(), (offset, 0))
        if not self.player._faceRight and flip is None or flip:
            self.image = pygame.transform.flip(self.image, True, False)
        if self.player.hasVisibleShield():
            img = self.shieldAnimation.getImage()
            if not (img.get_flags() & pygame.SRCALPHA):
                # The shield animation already uses per-pixel alphas so if they
                # are enabled we don't need per-surface alphas.
                img.set_alpha(128)
            self.image.blit(img, (offset, 0))

        # Flicker the sprite between different levels of transparency
        if self.player.phaseshift and self._canSeePhaseShift():
            self.setImageAlpha(random.randint(30, 150))
        elif self.player.dead:
            self.setImageAlpha(128)
        elif self.player.isInvulnerable():
            self.setImageAlpha(random.randint(30, 150))
        elif self.player.invisible:
            replay = self.worldGUI.gameViewer.replay
            if replay or self.player.isFriendsWith(self.getShownPlayer()):
                self.setImageAlpha(80)
            else:
                self.setImageAlpha(0)
        else:
            self.setImageAlpha(255)

    def setImageAlpha(self, alpha):
        setAlpha(self.image, alpha, alphaSurface=self.alphaImage)

    def getShownPlayer(self):
        return self.worldGUI.gameViewer.viewManager.target

    def _canSeePhaseShift(self):
        if self.worldGUI.gameViewer.replay:
            return True
        target = self.getShownPlayer()
        if not isinstance(target, Player):
            return False
        return self.player.isFriendsWith(target)
Пример #13
0
 def jammingHat(self):
     images = []
     for spark in self.jammingHatSparks:
         images.append(spark)
         images.extend([self.jammingHatImage] * randrange(5, 15))
     return Animation(0.05, timeNow, *images)
Пример #14
0
 def shoxwaveExplosion(self):
     return Animation(
         0.05, timeNow, *(self.shoxwaveFrame(i) for i in xrange(3)))
Пример #15
0
 def explosion(self):
     return Animation(
         0.07, timeNow, *(self.explosionFrame(i) for i in xrange(4)))
Пример #16
0
 def coinAnimation(self, timer):
     return Animation(0.07, timer, *self.coinImages)
Пример #17
0
 def bigCoinAnimation(self, timer):
     return Animation(0.07, timer, *self.bigCoinImages)
Пример #18
0
    def __init__(self, app, worldGUI, player, greyed=False, timer=None):
        super(PlayerSprite, self).__init__(app, worldGUI, player)
        if timer is None:
            timer = player.world.getMonotonicTime
        self.spriteTeam = player.team
        self.player = player
        self.nametag = NameTag(app, player.nick)
        self.countdown = CountDown(app, self.player)
        self._oldName = player.nick
        self.coinTally = CoinTally(app, 0)
        self.greyed = greyed
        self.healthBar = HealthBar(
            app,
            badColour=self.app.theme.colours.badHealth,
            fairColour=self.app.theme.colours.fairHealth,
            goodColour=self.app.theme.colours.goodHealth)
        self.shieldBar = HealthBar(
            app,
            badColour=self.app.theme.colours.badShield,
            fairColour=self.app.theme.colours.fairShield,
            goodColour=self.app.theme.colours.goodShield)

        sprites = app.theme.sprites
        self.greyVersion = None
        if greyed:
            sprites = sprites.greyed
        self.sprites = sprites
        self.gunImages = AngledImageCollection(
            self.getAngleFacing, *sprites.gunImages(self.player.team))
        self.machineGunImages = AngledImageCollection(
            self.getAngleFacing, *sprites.machineGunImages(self.player.team))
        self.ricoGunImages = AngledImageCollection(
            self.getAngleFacing, *sprites.ricoGunImages(self.player.team))
        self.shoxGunImages = SingleImage(sprites.shoxGun3)

        head = sprites.playerHead(self.player.team, self.player.bot)
        self.runningAnimation = [
            Animation(0.1, timer, *sprites.runningLegs),
            sprites.playerBody,
            head,
        ]
        self.ghostAnimation = sprites.ghostAnimation(self.player.team)
        self.blocker = [
            Animation(0.1, timer, sprites.blocker1, sprites.blocker1,
                      sprites.blocker2),
            head,
        ]
        self.bomber = [
            head,
            Animation(0.08, timer, sprites.bomber1, sprites.bomber2),
        ]

        self.reversingAnimation = [
            sprites.playerBody,
            Animation(0.1, timer, *sprites.backwardsLegs),
            head,
        ]

        self.turretAnimation = [
            sprites.turretBase,
            sprites.playerBody,
            head,
        ]

        self.standingAnimation = [
            sprites.playerStanding,
            sprites.playerBody,
            head,
        ]

        self.jumpingAnimation = [
            sprites.playerJumping,
            sprites.playerBody,
            head,
        ]
        self.holdingAnimation = [
            sprites.playerBody,
            sprites.playerHolding(self.player.team),
            head,
        ]
        self.fallingAnimation = self.jumpingAnimation
        self.shieldAnimation = Animation(0.15, timer, *sprites.shieldImages)
        self.jammingHat = sprites.jammingHat()

        if self.app.displaySettings.perPixelAlpha:
            flags = pygame.SRCALPHA
            self.alphaImage = pygame.Surface(self.canvasSize, flags)
        else:
            flags = 0
            self.alphaImage = None

        self.image = pygame.Surface(self.canvasSize, flags)
        self.rect = self.image.get_rect()

        # This probably shouldn't be done here.
        _t = datetime.date.today()
        self.is_christmas = _t.day in (24, 25, 26) and _t.month == 12
Пример #19
0
 def coinAnimation(self):
     return Animation(0.07, timeNow, *self.coinImages)