Beispiel #1
0
    def __init__(self, isLeft=True):
        """Init TitleTextSprite with the isLeft boolean.

        Instance variables:
            spriteSheet: The SpriteSheet object for the title sprite sheet image.
            animationFrames: A list of 13 Surface objects from the SpriteSheet object.
            coordinates: A tuple location to blit the sprite on the screen.
                If isLeft is True, then the coordinates are further to the left than if it is False.
            rotationCount: An integer tracking from where in animationFrame the sprite should take its next
                image.
            frameCount: An integer that increases whenever the update method is called.
                Used to control when other methods should be called.
            image: The current image to be drawn for the sprite.
                Defaults to the first image in animationFrames, the text 'CLU' facing backwards.
        """
        super().__init__()
        spriteSheet = SpriteSheet("title.png")
        self.animationFrames = []
        self.isLeft = isLeft
        if isLeft:
            self.coordinates = (98, 54)
        else:
            self.coordinates = (274, 54)
        self.rotationCount = self.frameCount = 0

        self.animationFrames.extend(spriteSheet.getStripImages(0, 0, 144, 82))
        self.animationFrames.extend(spriteSheet.getStripImages(0, 82, 144, 82))
        self.animationFrames.extend(
            spriteSheet.getStripImages(0, 164, 144, 82, 3))
        self.image = self.animationFrames[0]
        self.image.set_colorkey(c.BLACK)
Beispiel #2
0
    def __init__(self):
        """Init GoldSprite.

        Instance variables:
            spriteSheet: The SpriteSheet object for the gold sprite sheet image.
                If the current level is an instance of the BonusLevel class, uses the bonus sprite sheet image.
            animationFrames: A list of 8 Surface objects from the SpriteSheet object.
            coordinates: A tuple location to blit the sprite on the screen.
            goldState: An OtherStates Enum instance of the current state of the sprite.
                Used to determine which methods get called and when.
            passingDirection: A Directions Enum instance of the direction the player was facing upon colliding
                with this sprite.
                Should only be one of the four cardinal directions. Setting this to CLOCKWISE or COUNTER will
                cause unexpected and undesired results.
            isHorizontal: A boolean indicating if the sprite should be rotated 270 degrees or not.
            alreadyRevealed: A boolean indicating if the sprite has already been revealed by a player.
                Players only earn points from colliding with gold sprites that have not already been revealed.
            frameCount: An integer that increases whenever the update method is called.
            animationCount: An integer tracking from where in animationFrame the sprite should take its next
                image.
            flashImage: A Surface object, showing the gold flashing brightly.
            pointsImage: A Surface object, showing the 100 points earned from first revealing a gold sprite.
                The GoldSprite class never uses this image directly, but passes it to the PointsSprite class
                when creating a new instance of the latter.
            emptyImage: A Surface object, showing a fully-transparent blank image.
                Used when the sprite should not be visibly drawn onscreen.
            image: The current image to be drawn for the sprite.
                Defaults to the emptyImage.
            rect: A rect object for the sprite.
            collisionRect: A smaller rect object used for checking collision between this sprite and others.
                This creates a better visual for collision than using the main rect object.
        """
        super().__init__(c.goldGroup)
        if isinstance(PlayerSprite.currentLevel, BonusLevel):
            spriteSheet = SpriteSheet("gold_bonus.png")
        else:
            spriteSheet = SpriteSheet("gold.png")
        self.animationFrames = []

        self.coordinates = (0, 0)
        self.goldState = c.OtherStates.OFF_SCREEN
        self.passingDirection = c.Directions.RIGHT
        self.isHorizontal = self.alreadyRevealed = False
        self.frameCount = self.animationCount = 0

        self.animationFrames.extend(spriteSheet.getStripImages(0, 0, 34, 34))
        self.animationFrames.extend(spriteSheet.getStripImages(0, 34, 34, 34))
        self.flashImage = spriteSheet.getSheetImage(0, 68, 34, 34)
        self.pointsImage = spriteSheet.getSheetImage(34, 68, 34, 34)
        self.emptyImage = spriteSheet.getSheetImage(34, 102, 34, 34)

        self.image = self.emptyImage
        self.image.set_colorkey(c.BLACK)
        self.rect = self.image.get_rect()
        self.collisionRect = pg.rect.Rect((0, 0), (16, 32))
Beispiel #3
0
    def __init__(self):
        """Init ItemSprite.

        Instance variables:
            spriteSheet: The SpriteSheet object for the item sprite sheet image.
            animationFrames: A list of 16 Surface objects from the SpriteSheet object
            coordinates: A tuple location to blit the sprite on the screen.
            itemState: An OtherStates Enum instance of the current state of the sprite.
                Used to determine which methods get called and when.
            collectingPlayer: An instance of the PlayerSprite class that collects this item.
                Is a None type variable until the item is collected.
            frameCount: An integer that increases whenever the collectItem method is called.
            imageDict: A dict associating keys with Surface objects from the SpriteSheet object.
            image: The current image to be drawn for the sprite.
                Defaults to the emptyImage.
            baseImage: The image that the sprite will change to once it's been revealed.
                What image that is depends on the specific subclass.
            rect: A rect object for the sprite.
            collisionRect: A smaller rect object used for checking collision between this sprite and others.
                This creates a better visual for collision than using the main rect object.
            triggerRect: A smaller rect object at different coordinates than the collisionRect.
        """
        super().__init__(c.itemGroup)
        spriteSheet = SpriteSheet("item.png")
        self.animationFrames = []
        self.coordinates = (0, 0)
        self.itemState = c.OtherStates.OFF_SCREEN
        self.collectingPlayer = None
        self.frameCount = 0

        self.animationFrames.extend(spriteSheet.getStripImages(0, 0, 34, 34))
        self.animationFrames.extend(spriteSheet.getStripImages(0, 34, 34, 34))
        self.imageDictKeys = [
            "apple", "banana", "cherry", "eggplant", "melon", "pineapple",
            "strawberry", "800", "bag", "clock", "flag", "glasses",
            "explosion 1", "explosion 2", "empty", "1500"
        ]
        self.imageDict = dict(zip(self.imageDictKeys, self.animationFrames))

        self.image = self.baseImage = self.imageDict["empty"]
        self.rect = self.image.get_rect()
        self.collisionRect = pg.rect.Rect((0, 0), (18, 28))
        self.triggerRect = pg.rect.Rect((0, 0), (18, 28))
Beispiel #4
0
class DemoDisplay(pg.sprite.Sprite):
    """Create an instance of the display box surrounding the demo.

    Attributes:
        demoNumber: An integer determining whether this sprite belongs to the first, second, third, or fourth
            demo animation.
        coordinates: A tuple location to blit the sprite on the screen.
    """

    def __init__(self, demoNumber=0, coordinates=(0, 0)):
        """Init DemoSprite using the integer demoNumber and the tuple coordinates.

        Instance variables:
            spriteSheet: The SpriteSheet object for the demo display sprite sheet image.
            animationFrames: A list of 4 Surface objects from the SpriteSheet object.
            image: The image to be drawn for this display.
            rect: A rect object for the sprite.
        """
        super().__init__(c.demoGroup)
        self.spriteSheet = SpriteSheet("demo_display.png")
        self.animationFrames = []
        self.demoNumber = demoNumber
        self.coordinates = coordinates

        self.animationFrames.extend(self.spriteSheet.getStripImages(0, 0, 380, 260))
        self.animationFrames.extend(self.spriteSheet.getStripImages(0, 260, 380, 260))

        self.image = self.animationFrames[self.demoNumber]
        self.image.set_colorkey(c.BLACK)
        self.rect = self.image.get_rect()

    def update(self):
        """Not to be called directly, but inherited by subclasses."""
        pass

    def setCoordinates(self):
        """Set the display's rect to match its coordinates."""
        self.rect.topleft = self.coordinates

    def setMonochromeImage(self):
        """Not to be called directly, but inherited by subclasses."""
        pass
Beispiel #5
0
    def __init__(self):
        """Init RubberTrapSprite.

        Instance variables:
            spriteSheet: The SpriteSheet object for the trap sprite sheet image.
            animationFrames: A list of 4 Surface objects from the SpriteSheet object
            coordinates: A tuple location to blit the sprite on the screen.
            trapState: An OtherStates Enum instance of the current state of the sprite.
                Used to determine which methods get called and when.
            collidingPlayer: An instance of the PlayerSprite class that collides with this sprite.
                Is a None type variable until the trap sprite overlaps with a player sprite.
            isHorizontal: A boolean indicating if the sprite should be rotated 90 degrees or not.
            flipTrigger: A boolean indicating if the trap is in a step in its animation where it is triggered and
                its image should be flipped.
            frameCount: An integer that increases whenever the animateTrap method is called.
            emptyImage: A Surface object, showing a fully-transparent blank image.
                Used when the sprite should not be visibly drawn onscreen.
            image: The current image to be drawn for the sprite.
                Defaults to the emptyImage.
            rect: A rect object for the sprite.
            collisionRect: A smaller rect object used for checking collision between this sprite and others.
                This creates a better visual for collision than using the main rect object.
        """
        super().__init__(c.rubberGroup)
        spriteSheet = SpriteSheet("trap.png")
        self.animationFrames = []

        self.coordinates = (0, 0)
        self.trapState = c.OtherStates.OFF_SCREEN
        self.collidingPlayer = None
        self.isHorizontal = self.flipTrigger = False
        self.frameCount = 0

        self.animationFrames.extend(spriteSheet.getStripImages(0, 0, 60, 56, 4, key=c.RED))
        self.emptyImage = spriteSheet.getSheetImage(0, 240, 60, 56, key=c.RED)

        self.image = self.emptyImage
        self.image.set_colorkey(c.BLACK)
        self.rect = self.image.get_rect()
        self.collisionRect = pg.rect.Rect((0, 0), (16, 32))
Beispiel #6
0
    def __init__(self):
        """Init TitleBoxSprite.

        Instance variables:
            spriteSheet: The SpriteSheet object for the title sprite sheet image.
            animationFrames: A list of 2 Surface objects from the SpriteSheet object.
            coordinates: A tuple location to blit the sprite on the screen.
            frameCount: An integer that increases whenever the update method is called.
                Used to control when other methods should be called.
            image: The current image to be drawn for the sprite.
                Defaults to the first image in animationFrames, the text 'CLU' facing backwards.
        """
        super().__init__()
        spriteSheet = SpriteSheet("display.png")
        self.animationFrames = []
        self.coordinates = (50, 22)
        self.frameCount = 0

        self.animationFrames.extend(
            spriteSheet.getStripImages(0, 0, 416, 242, key=c.RED))
        self.image = self.animationFrames[0]
        self.image.set_colorkey(c.RED)
Beispiel #7
0
    def __init__(self):
        """Init BlackHoleSprite.

        Instance variables:
            spriteSheet: The SpriteSheet object for the hole sprite sheet image.
            animationFrames: A list of 4 Surface objects from the SpriteSheet object.
            coordinates: A tuple location to blit the sprite on the screen.
            frameCount: An integer that increases whenever the update method is called.
            animationCount: An integer tracking from where in animationFrames the sprite should take its next
                image.
            image: The current image to be drawn for the sprite.
                Defaults to the first Surface object in animationFrames.
            rect: A rect object for the sprite.
        """
        super().__init__(c.blackHoleGroup)
        spriteSheet = SpriteSheet("hole.png")
        self.animationFrames = []
        self.coordinates = (0, 0)
        self.frameCount = self.animationCount = 0

        self.animationFrames.extend(spriteSheet.getStripImages(0, 0, 34, 34))
        self.image = self.animationFrames[0]
        self.image.set_colorkey(c.BLACK)
        self.rect = self.image.get_rect()
Beispiel #8
0
    def __init__(self):
        """Init UrchinSprite.

        Instance variables:
            spriteSheet: The SpriteSheet object for the urchin sprite sheet image.
            coordinates: A tuple location to blit the sprite on the screen.
            enemyState: An EnemyStates Enum instance of the current state of the sprite.
                Used to determine which methods get called and when.
            color: A tuple representing the urchin's current color.
                Blue urchins are active, whereas yellow urchins are stunned.
            facingDirection: A Directions Enum instance of the current direction the sprite is facing.
                Used to determine which direction the sprite moves and whether its image is flipped.
                Should only be one of the four cardinal directions. Setting this to CLOCKWISE or COUNTER will
                cause unexpected and undesired results.
            bouncingOff: A boolean indicating if the sprite is currently colliding with any objects that would
                prevent it from moving forwards.
            running: A boolean indicating if the sprite is currently moving at double speed.
            frameCount: An integer that increases whenever the update method is called.
            animationCount: An integer that increases whenever the sprite changes its animation image under
                specific circumstances.
                This is tracked for the purposes of controlling when to change the enemyState.
            delayCount: An integer representing how long the sprite must wait at an intersection before it can
                move.
            imageDict: A dict associating the keys BLUE and YELLOW with sub-dictionaries. These sub-dictionaries
                associate keywords with lists of Surface objects from the SpriteSheet object.
            emptyImage: A Surface object, showing a fully-transparent blank image.
                Used when the sprite should not be visibly drawn onscreen.
            image: The current image to be drawn for the sprite.
                Defaults to the emptyImage.
            rect: A rect object for the sprite.
            collisionRect: A smaller rect object used for checking collision between this sprite and others.
                This creates a better visual for collision than using the main rect object.
        """
        super().__init__(c.enemyGroup)
        spriteSheet = SpriteSheet("urchin.png")
        self.coordinates = (0, 0)
        self.enemyState = c.EnemyStates.SMALL_BALL
        self.color = c.BLUE
        self.facingDirection = c.Directions.RIGHT
        self.bouncingOff = self.running = False
        self.frameCount = self.animationCount = self.delayCount = 0
        self.audioCount = 1

        self.imageDict = {c.BLUE: {}, c.YELLOW: {}}
        self.imageDictKeys = ["horizontal", "vertical", "ball"]

        # xValue is used to prevent repetition, as we need to call getStripImages three times in total with very
        # similar arguments, differing only by xValue each time, and only by 34 each time.
        # In this case, we want (0, 0, 34, 34); (0, 34, 34, 34); (0, 68, 34, 34)
        xValue = 0
        for key in self.imageDictKeys:
            stripImages = spriteSheet.getStripImages(0, xValue, 34, 34)
            self.imageDict[c.BLUE][key] = [stripImages[0], stripImages[1]]
            self.imageDict[c.YELLOW][key] = [stripImages[2], stripImages[3]]
            xValue += 34
        self.imageDict[c.BLUE]["death"] = self.imageDict[c.YELLOW]["death"]\
            = spriteSheet.getStripImages(0, 102, 34, 34)
        self.emptyImage = spriteSheet.getSheetImage(0, 136, 34, 34)

        self.image = self.emptyImage
        self.image.set_colorkey(c.BLACK)
        self.rect = self.image.get_rect()
        self.collisionRect = pg.rect.Rect((0, 0), (18, 18))
Beispiel #9
0
    def __init__(self, playerNumber=1):
        """Init PlayerSprite using the integer playerNumber.

        Instance variables:
            spriteSheet: The SpriteSheet object for the player sprite sheet image.
            lives: An integer representing the player's current remaining number of lives.
            baseCoordinates: A tuple location to blit the sprite upon starting a level or after losing a life.
                This should be updated whenever the player begins a new level, and at no other point.
            coordinates: A tuple location to blit the sprite on the screen.
            swingingArmCoordinates: A tuple location of the center point of the player's arm sprite when it grabs
                onto a post.
                This should be updated whenever the arm sprite grabs onto a new post, and at no other point.
            playerState: A PlayerStates Enum instance of the current state of the sprite.
                Used to determine which methods get called and when.
            facingDirection: A Directions Enum instance of the current direction the sprite is facing.
                Used to determine which direction the sprite moves and whether its image is flipped.
                Should only be one of the four cardinal directions. Setting this to CLOCKWISE or COUNTER will
                cause unexpected and undesired results.
            initialSwingDirection: A Directions Enum instance of which direction the sprite was facing
                immediately before entering the SWINGING PlayerStates Enum.
                Used to determine if a player should fall into a black hole sprite if they finish swinging while
                their rects overlap.
                Should only be one of the four cardinal directions. Setting this to CLOCKWISE or COUNTER will
                cause unexpected and undesired results.
            swingingDirection: A Directions Enum instance indicating if the sprite is swinging clockwise or
                counter-clockwise.
                Should only be one of the two rotation directions. Setting this to a cardinal direction will
                cause unexpected and undesired results.
            bouncingOffWall: A boolean indicating if the sprite is currently colliding with any of the level
                boundary's rect objects.
            bouncingOffPlayer: A boolean indicating if the sprite is currently colliding with any other Player
                sprites.
            isFrozen: A boolean indicating if the sprite is currently unable to move due to the methods of an
                ItemClock sprite.
            killedUrchinCount: An integer tracking how many Urchin sprites the player has killed in the current
                level.
            goldCollectedCount: An integer tracking how many Gold sprites the player has revealed in the current
                level.
            self.score: An integer tracking the player's total cumulative score.
            frameCount: An integer that increases whenever the update method is called.
                Used to control when other methods should be called.
            currentAngle: A float that tracks the current angle between the player sprite's center point and
                swingingArmCoordinates.
                Should only be updated or referenced while the player is swinging.
            imageDict: A dict associating keys with lists of Surface objects from the SpriteSheet object.
                As the player's image appears different when moving or squishing based on if they are moving
                horizontally or vertically, those keys take dicts of Surface objects instead of lists.
            emptyImage: A Surface object, showing a fully-transparent blank image.
                Used when the sprite should not be visibly drawn onscreen.
            image: The current image to be drawn for the sprite.
                Defaults to the emptyImage.
            rect: A rect object for the sprite.
            collisionRect: A smaller rect object used for checking collision between this sprite and others.
                This creates a better visual for collision than using the main rect object.
        """
        super().__init__(c.playerGroup)
        spriteSheet = SpriteSheet("player{}.png".format(playerNumber))
        self.playerNumber = playerNumber
        self.lives = 5
        self.baseCoordinates = (0, 0)
        self.coordinates = (0, 0)
        self.swingingArmCoordinates = (0, 0)
        self.playerState = c.PlayerStates.OFF_SCREEN
        self.facingDirection = c.Directions.RIGHT
        self.initialSwingDirection = c.Directions.RIGHT
        self.swingingDirection = c.Directions.CLOCKWISE
        self.bouncingOffWall = self.bouncingOffPlayer = self.isFrozen = False
        self.killedUrchinCount = self.goldCollectedCount = self.score = self.frameCount = 0
        self.currentAngle = 0.0

        self.imageDict = {
            "arm": [],
            "ball": [],
            "end": [],
            "death": [],
            "turn": [],
            "fall": [],  # #######
            "move": {},
            "squish": {}
        }
        armImageList = spriteSheet.getStripImages(152, 0, 16, 16, 2)
        armImageList.append(spriteSheet.getSheetImage(184, 0, 14, 14))
        self.imageDict["arm"] = armImageList
        self.imageDict["ball"] = spriteSheet.getStripImages(0, 0, 34, 34, 2)
        self.imageDict["end"] = spriteSheet.getStripImages(68, 0, 42, 32, 2)
        self.imageDict["death"] = spriteSheet.getStripImages(0, 34, 34, 34, 4)
        self.imageDict["turn"] = spriteSheet.getStripImages(136, 34, 34, 34)
        self.imageDict["fall"] = spriteSheet.getStripImages(0, 68, 34, 34, 4)
        self.imageDict["move"]["vertical"] = spriteSheet.getStripImages(
            0, 102, 32, 38, 4)
        self.imageDict["squish"]["vertical"] = spriteSheet.getStripImages(
            128, 102, 48, 38)
        self.imageDict["move"]["horizontal"] = spriteSheet.getStripImages(
            0, 140, 34, 34, 4)
        self.imageDict["squish"]["horizontal"] = spriteSheet.getStripImages(
            136, 140, 30, 52, 3)
        self.emptyImage = spriteSheet.getSheetImage(136, 68, 34, 34)

        self.image = self.emptyImage
        self.image.set_colorkey(c.BLACK)
        self.rect = self.image.get_rect()
        self.collisionRect = pg.rect.Rect((0, 0), (16, 16))