Esempio n. 1
0
    def __init__(self, x, y, w, h, properties, game):

        self.spritePath = './Assets/Objects/computer.png'
        self.game = game
        self.spriteBaseSize = 16
        self.topoffset = 5
        self.xoffset = 0
        self.setProperties(properties)

        self.x, self.y, self.w, self.h = x, y, 32, 32
        self.startQTBoundaries(self.x, self.y, self.w, self.h)

        self.collide = True
        self.collectable = True
        self.collected = False
        self.collisionExecuted = False
        self.inContactWithPlayer = False
        self.activationDelay = 20
        self.activationDelayMax = 20

        self.idleSprite = SpriteSheet(pygame.image.load(self.spritePath))
        self.idleAnimation = SpriteAnimation(4, 30, True)
        self.idleState = [
            self.idleSprite.getimage(32 * x, 0, 32, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)
Esempio n. 2
0
    def __init__(self, x, y, w, h, properties, game):

        self.spritePath = './Assets/Objects/coin.png'
        self.game = game
        self.setProperties(properties)
        self.spriteBaseSize = 16
        self.topoffset = 5
        self.xoffset = 5

        self.x, self.y, self.w, self.h = x, y, 32, 32
        self.startQTBoundaries(self.x, self.y, self.w, self.h)

        self.collide = True
        self.collectable = True
        self.collected = False
        self.collisionExecuted = False

        # IDLE Graphics
        self.idleSprite = SpriteSheet(pygame.image.load(self.spritePath))
        self.idleAnimation = SpriteAnimation(4, 10, True)
        self.idleState = [
            self.idleSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)
Esempio n. 3
0
class Effect(object):

    def __init__(self,x,y,w,h,path,loop,frameQuantity,frameSpeed):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.life = frameQuantity*frameSpeed
        self.loop = loop
        self.frameQuantity = frameQuantity
        self.frameSpeed = frameSpeed

        self.sprite = SpriteSheet(pygame.image.load(path))
        self.animation = SpriteAnimation(frameQuantity,frameSpeed,loop)
        self.effect = [self.sprite.getimage(x * self.w,0,self.w,self.h) for x in range(frameQuantity)]

    def update(self,effectSystem):
        self.animation.update()
        if not self.loop:
            self.life -= 1
            if self.life <= 0:
                effectSystem.effects.remove(self)

    def draw(self,display,camera):
        #self.effect[self.animation.get()]
        display.blit( pygame.transform.scale( self.effect[self.animation.get()],(self.w*2,self.h*2) )
            ,(self.x+camera.x, self.y + camera.y))
Esempio n. 4
0
class WaterSurface(GameObject):
    def __init__(self, x, y, w, h, properties, game):
        self.x, self.y, self.w, self.h = x, y, 32, 32
        self.startQTBoundaries(self.x, self.y, self.w, self.h)
        self.setProperties(properties)

        self.spritePath = './Assets/Objects/water_surface_blue.png'
        self.spritePathBorder = './Assets/Objects/water_surface.png'
        if self.have('color'):
            color = self.get('color')
            self.spritePath = self.spritePath.replace('blue', color)

        self.game = game
        self.spriteBaseSize = 16
        self.topoffset = 5
        self.xoffset = 5

        self.collide = True
        self.collectable = True
        self.collisionExecuted = False

        # IDLE Graphics
        self.idleSprite = SpriteSheet(pygame.image.load(self.spritePath))
        self.idleAnimation = SpriteAnimation(8, 10, True)
        self.idleState = [
            self.idleSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)

        self.idleSpriteBorder = SpriteSheet(
            pygame.image.load(self.spritePathBorder))
        self.idleAnimationBorder = SpriteAnimation(8, 10, True)
        self.idleStateBorder = [
            self.idleSpriteBorder.getimage(self.spriteBaseSize * x, 0,
                                           self.spriteBaseSize,
                                           self.spriteBaseSize)
            for x in range(self.idleAnimationBorder.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimationBorder)

    def draw(self, display, camera):
        display.blit(
            pygame.transform.scale(
                self.idleStateBorder[self.idleAnimationBorder.get()],
                (self.w, self.h)), (self.x + camera.x, self.y + camera.y))
        display.blit(pygame.transform.scale(
            self.idleState[self.idleAnimation.get()], (self.w, self.h)),
                     (self.x + camera.x, self.y + camera.y),
                     area=None,
                     special_flags=pygame.BLEND_RGB_MULT)

    def update(self, keys):
        pass

    def collisionEvent(self):
        if not self.collisionExecuted:
            self.collisionExecuted = True
Esempio n. 5
0
    def __init__(self,x,y,w,h,path,loop,frameQuantity,frameSpeed):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.life = frameQuantity*frameSpeed
        self.loop = loop
        self.frameQuantity = frameQuantity
        self.frameSpeed = frameSpeed

        self.sprite = SpriteSheet(pygame.image.load(path))
        self.animation = SpriteAnimation(frameQuantity,frameSpeed,loop)
        self.effect = [self.sprite.getimage(x * self.w,0,self.w,self.h) for x in range(frameQuantity)]
Esempio n. 6
0
    def __init__(self, x, y, w, h, properties, game):

        self.spritePathOpen = './Assets/Objects/door_open.png'
        self.spritePathClosed = './Assets/Objects/door_close.png'
        self.spritePathOpenCoin = './Assets/Objects/door_open_coin.png'
        self.spritePathClosedCoin = './Assets/Objects/door_close_coin.png'
        self.spritePathOpenEnemy = './Assets/Objects/door_open_enemies.png'
        self.spritePathClosedEnemy = './Assets/Objects/door_close_enemies.png'

        self.game = game
        self.spriteBaseSize = 16
        self.topoffset = 18
        self.xoffset = 19
        self.setProperties(properties)

        self.enemyDoor = self.have('enemy')
        self.coinDoor = self.have('coin')

        self.x, self.y, self.w, self.h = x, y, 32, 32
        self.startQTBoundaries(self.x, self.y, self.w, self.h)

        self.collide = True
        self.collectable = True
        self.collected = False
        self.collisionExecuted = False
        self.opened = True

        if self.enemyDoor:
            self.openSprite = SpriteSheet(
                pygame.image.load(self.spritePathOpenEnemy))
            self.closeSprite = SpriteSheet(
                pygame.image.load(self.spritePathClosedEnemy))
        elif self.coinDoor:
            self.openSprite = SpriteSheet(
                pygame.image.load(self.spritePathOpenCoin))
            self.closeSprite = SpriteSheet(
                pygame.image.load(self.spritePathClosedCoin))
        else:
            self.openSprite = SpriteSheet(
                pygame.image.load(self.spritePathOpen))
            self.closeSprite = SpriteSheet(
                pygame.image.load(self.spritePathClosed))

        self.openAnimation = SpriteAnimation(10, 5, False)
        self.openState = [
            self.openSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.openAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.openAnimation)
Esempio n. 7
0
class Computer(GameObject):
    def __init__(self, x, y, w, h, properties, game):

        self.spritePath = './Assets/Objects/computer.png'
        self.game = game
        self.spriteBaseSize = 16
        self.topoffset = 5
        self.xoffset = 0
        self.setProperties(properties)

        self.x, self.y, self.w, self.h = x, y, 32, 32
        self.startQTBoundaries(self.x, self.y, self.w, self.h)

        self.collide = True
        self.collectable = True
        self.collected = False
        self.collisionExecuted = False
        self.inContactWithPlayer = False
        self.activationDelay = 20
        self.activationDelayMax = 20

        self.idleSprite = SpriteSheet(pygame.image.load(self.spritePath))
        self.idleAnimation = SpriteAnimation(4, 30, True)
        self.idleState = [
            self.idleSprite.getimage(32 * x, 0, 32, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)

    def draw(self, display, camera):
        display.blit(
            pygame.transform.scale(self.idleState[self.idleAnimation.get()],
                                   (64, self.h)),
            (self.x + camera.x, self.y + camera.y))

    def update(self, keys):
        self.activationDelay -= 1
        if self.activationDelay < 0: self.activationDelay = 0

        if self.inContactWithPlayer and self.activationDelay == 0 and keys[
                pygame.K_e]:
            self.isActivated = True
            self.activationDelay = self.activationDelayMax
            self.activationEvent()

        self.inContactWithPlayer = False

    def collisionEvent(self):
        self.inContactWithPlayer = True

    def activationEvent(self):
        if self.properties != None:
            self.game.audioSystem.playSFX('computer')
            # process dialogs
            dialogs = self.getMany('dialog')
            if len(dialogs) > 0:
                for x in range(len(dialogs)):
                    self.game.uiSystem.addDialog(dialogs[x])
Esempio n. 8
0
class Hearth(GameObject):
    def __init__(self, x, y, w, h, properties, game):

        self.spritePath = './Assets/Objects/hearth.png'
        self.game = game
        self.spriteBaseSize = 16
        self.topoffset = 5
        self.xoffset = 5
        self.setProperties(properties)

        self.x, self.y, self.w, self.h = x, y, 32, 32
        self.startQTBoundaries(self.x, self.y, self.w, self.h)

        self.collide = True
        self.collectable = True
        self.collected = False
        self.collisionExecuted = False

        # IDLE Graphics
        self.idleSprite = SpriteSheet(pygame.image.load(self.spritePath))
        self.idleAnimation = SpriteAnimation(4, 10, True)
        self.idleState = [
            self.idleSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)

    def draw(self, display, camera):
        display.blit(
            pygame.transform.scale(self.idleState[self.idleAnimation.get()],
                                   (self.w, self.h)),
            (self.x + camera.x, self.y + camera.y))

    def update(self, keys):
        pass

    def collisionEvent(self):
        if not self.collisionExecuted:
            self.game.player.health += 1
            if self.get('once'):
                self.game.objectsOnce.append([
                    self.game.currentRoom,
                    int(self.x / self.w),
                    int(self.y / self.h)
                ])
            if self.game.player.health > self.game.player.maxHealth:
                self.game.player.health = self.game.player.maxHealth
            self.game.objects.remove(self)
            self.game.removeQuadTreeItem(self)
            self.game.effectsSystem.generateEffect('COLLECTED', self.x, self.y)
            self.game.audioSystem.playSFX('hearth')
            self.collisionExecuted = True
Esempio n. 9
0
    def __init__(self, x, y, w, h, properties, game):
        self.x, self.y, self.w, self.h = x, y, 32, 32
        self.startQTBoundaries(self.x, self.y, self.w, self.h)
        self.setProperties(properties)

        self.spritePath = './Assets/Objects/water_surface_blue.png'
        self.spritePathBorder = './Assets/Objects/water_surface.png'
        if self.have('color'):
            color = self.get('color')
            self.spritePath = self.spritePath.replace('blue', color)

        self.game = game
        self.spriteBaseSize = 16
        self.topoffset = 5
        self.xoffset = 5

        self.collide = True
        self.collectable = True
        self.collisionExecuted = False

        # IDLE Graphics
        self.idleSprite = SpriteSheet(pygame.image.load(self.spritePath))
        self.idleAnimation = SpriteAnimation(8, 10, True)
        self.idleState = [
            self.idleSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)

        self.idleSpriteBorder = SpriteSheet(
            pygame.image.load(self.spritePathBorder))
        self.idleAnimationBorder = SpriteAnimation(8, 10, True)
        self.idleStateBorder = [
            self.idleSpriteBorder.getimage(self.spriteBaseSize * x, 0,
                                           self.spriteBaseSize,
                                           self.spriteBaseSize)
            for x in range(self.idleAnimationBorder.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimationBorder)
Esempio n. 10
0
    def setupSprite(self):
        # IDLE
        self.idleSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'bat_idle.png'))
        self.idleAnimation = SpriteAnimation(4, 30, True)
        self.idleState = [
            self.idleSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)

        # WALK
        self.walkSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'bat_walk.png'))
        self.walkAnimation = SpriteAnimation(4, 10, True)
        self.walkState = [
            self.walkSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.walkAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.walkAnimation)
Esempio n. 11
0
class Bat(Enemy):
    def __init__(self, x, y, w, h, props, game):
        Enemy.__init__(self, x, y, w, h, props, game)
        self.x, self.y, self.w, self.h = x, y, w, h
        self.setProperties(props)
        self.spritePathPrefix = './Assets/Enemies/'
        self.game = game
        self.spriteBaseSize = 16
        self.hurtAmount = 1
        self.cs = (0, 0)
        self.co = (0, 0)
        self.activationDistance = 250
        self.originalPosition = Vector2(self.x, self.y)
        self.interpolatorCount = 0
        self.hurtCount = 60
        self.maxHurtCount = 60
        self.state = 'IDLE'
        self.drop = None
        self.dropAdded = False

        self.setupSprite()

    def setupSprite(self):
        # IDLE
        self.idleSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'bat_idle.png'))
        self.idleAnimation = SpriteAnimation(4, 30, True)
        self.idleState = [
            self.idleSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)

        # WALK
        self.walkSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'bat_walk.png'))
        self.walkAnimation = SpriteAnimation(4, 10, True)
        self.walkState = [
            self.walkSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.walkAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.walkAnimation)

    def draw(self, display, camera):
        if self.velocity.length() != 0.0:
            display.blit(
                pygame.transform.scale(
                    self.walkState[self.walkAnimation.get()],
                    (self.w, self.h)),
                (self.position.x + camera.x, self.position.y + camera.y))
        else:
            display.blit(
                pygame.transform.scale(
                    self.idleState[self.idleAnimation.get()],
                    (self.w, self.h)),
                (self.position.x + camera.x, self.position.y + camera.y))

    def update(self, keys):

        playerPosition = Vector2(self.game.player.x, self.game.player.y)
        enemyPosition = Vector2(self.position.x, self.position.y)

        direction = playerPosition - enemyPosition
        distance = direction.length()
        if distance < self.activationDistance:
            self.acceleration = direction
            self.interpolatorCount = 0
            self.state = 'ATTACK'
        else:
            self.state = 'IDLE'
            self.interpolatorCount += 0.01
            if self.interpolatorCount > 1: self.interpolatorCount = 1
            self.velocity.x = 0
            self.velocity.y = 0
            currentPosition = Vector2(self.x, self.y)
            toHome = currentPosition.lerp(self.originalPosition,
                                          self.interpolatorCount)
            self.position = toHome

        Enemy.update(self, keys)
        self.x = self.position.x
        self.y = self.position.y
        self.hurtCount -= 1
        if self.hurtCount < 0: self.hurtCount = 0

    def hurt(self):
        if self.hurtCount == 0:
            self.state = 'KILL'
            self.game.audioSystem.playSFX('bat_dead')
            self.hurtCount = self.maxHurtCount
            self.game.effectsSystem.generateEffect('BAT_KILL', self.x,
                                                   self.y - 20, 0, 16)
            self.game.enemies.remove(self)
            if self.drop != None and not self.dropAdded:
                self.game.queueSystem.addItem(self.drop)
                self.dropAdded = True
            elif self.drop == None and not self.dropAdded:
                drop = self.game.enemySystem.enemyDefaultDrop(self)
                if drop != None:
                    self.game.queueSystem.addItem(drop)
                self.dropAdded = True
Esempio n. 12
0
class Door(GameObject):
    def __init__(self, x, y, w, h, properties, game):

        self.spritePathOpen = './Assets/Objects/door_open.png'
        self.spritePathClosed = './Assets/Objects/door_close.png'
        self.spritePathOpenCoin = './Assets/Objects/door_open_coin.png'
        self.spritePathClosedCoin = './Assets/Objects/door_close_coin.png'
        self.spritePathOpenEnemy = './Assets/Objects/door_open_enemies.png'
        self.spritePathClosedEnemy = './Assets/Objects/door_close_enemies.png'

        self.game = game
        self.spriteBaseSize = 16
        self.topoffset = 18
        self.xoffset = 19
        self.setProperties(properties)

        self.enemyDoor = self.have('enemy')
        self.coinDoor = self.have('coin')

        self.x, self.y, self.w, self.h = x, y, 32, 32
        self.startQTBoundaries(self.x, self.y, self.w, self.h)

        self.collide = True
        self.collectable = True
        self.collected = False
        self.collisionExecuted = False
        self.opened = True

        if self.enemyDoor:
            self.openSprite = SpriteSheet(
                pygame.image.load(self.spritePathOpenEnemy))
            self.closeSprite = SpriteSheet(
                pygame.image.load(self.spritePathClosedEnemy))
        elif self.coinDoor:
            self.openSprite = SpriteSheet(
                pygame.image.load(self.spritePathOpenCoin))
            self.closeSprite = SpriteSheet(
                pygame.image.load(self.spritePathClosedCoin))
        else:
            self.openSprite = SpriteSheet(
                pygame.image.load(self.spritePathOpen))
            self.closeSprite = SpriteSheet(
                pygame.image.load(self.spritePathClosed))

        self.openAnimation = SpriteAnimation(10, 5, False)
        self.openState = [
            self.openSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.openAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.openAnimation)

    def draw(self, display, camera):
        if self.opened:
            display.blit(
                pygame.transform.scale(
                    self.openState[self.openAnimation.get()],
                    (self.w, self.h)), (self.x + camera.x, self.y + camera.y))
        else:
            display.blit(
                pygame.transform.scale(
                    self.closeSprite.getimage(0, 0, self.spriteBaseSize,
                                              self.spriteBaseSize),
                    (self.w, self.h)), (self.x + camera.x, self.y + camera.y))

    def update(self, keys):
        if self.coinDoor:
            if self.game.countCoins() != 0:
                self.opened = False
            else:
                self.opened = True
        elif self.enemyDoor:
            if self.game.countEnemies() != 0:
                self.opened = False
            else:
                self.opened = True
        else:
            self.opened = True

    def collisionEvent(self):
        if self.opened:
            if self.properties != None:
                map = self.get('map')
                x = self.get('x')
                y = self.get('y')
                self.game.audioSystem.playSFX('boss_dead')
                self.game.loadLevel(map, self.game.objects, self.game.enemies,
                                    self.game.objectsTopLayer,
                                    self.game.objectsWaterLayer,
                                    (int(x) * 32, int(y) * 32), False)
Esempio n. 13
0
class Slime(Enemy):
    def __init__(self, x, y, w, h, props, game):
        self.x, self.y, self.w, self.h = x, y, w, h
        self.cs = (-8, -12)
        self.co = (4, 12)
        self.killAnimationTime = 30
        self.spritePathPrefix = './Assets/Enemies/'
        self.setProperties(props)
        self.game = game
        self.spriteBaseSize = 16
        self.hurtAmount = 1
        self.mathUtil = MathFunctions()

        self.velX = 0
        self.velY = 0

        self.state = "NORMAL"
        self.movSpeed = 0.003

        self.startXPosition = self.x / 32
        self.startYPosition = self.y / 32
        self.endXPosition = self.x / 32
        self.endYPosition = self.y / 32
        if self.have('x'):
            self.endXPosition = int(self.get('x'))
        if self.have('y'):
            self.endYPosition = int(self.get('y'))

        self.movement = [
            self.startXPosition, self.startYPosition, self.endXPosition,
            self.endYPosition
        ]
        self.movementTimer = 0
        self.drop = None
        self.dropAdded = False

        if self.have('drop'):
            attr = self.get('drop').split('|')
            self.drop = QueueItem(attr[0], attr[1] + ':' + attr[2])

        # Idle State
        self.idleSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'slime_idle.png'))
        self.idleAnimation = SpriteAnimation(5, 10, True)
        self.idleState = [
            self.idleSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)

        # Walk State
        self.walkSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'slime_walk.png'))
        self.walkAnimation = SpriteAnimation(2, 20, True)
        self.walkState = [
            self.walkSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.walkAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.walkAnimation)

        # Kill State
        self.killSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'slime_kill.png'))
        self.killState = [
            self.killSprite.getimage(0, 0, self.spriteBaseSize,
                                     self.spriteBaseSize)
        ]

    def draw(self, display, camera):
        if self.state != 'KILL':
            if self.velX == 0 and self.velY == 0:
                display.blit(
                    pygame.transform.scale(
                        self.idleState[self.idleAnimation.get()],
                        (self.w, self.h)),
                    (self.x + camera.x, self.y + camera.y))
            elif self.velX < 0:
                if self.state != 'ATTACK':
                    display.blit(
                        pygame.transform.scale(
                            self.walkState[self.walkAnimation.get()],
                            (self.w, self.h)),
                        (self.x + camera.x, self.y + camera.y))
                else:
                    display.blit(
                        pygame.transform.scale(
                            self.attackState[self.attackAnimation.get()],
                            (self.w, self.h)),
                        (self.x + camera.x, self.y + camera.y))
            elif self.velX > 0:
                if self.state != 'ATTACK':
                    display.blit(
                        pygame.transform.flip(
                            pygame.transform.scale(
                                self.walkState[self.walkAnimation.get()],
                                (self.w, self.h)), 1, 0),
                        (self.x + camera.x, self.y + camera.y))
                else:
                    display.blit(
                        pygame.transform.flip(
                            pygame.transform.scale(
                                self.attackState[self.attackAnimation.get()],
                                (self.w, self.h)), 1, 0),
                        (self.x + camera.x, self.y + camera.y))

        else:
            display.blit(
                pygame.transform.scale(self.killState[0], (self.w, self.h)),
                (self.x + camera.x, self.y + camera.y))

    def update(self, keys):
        calcX = self.x
        calcY = self.y

        if self.state != 'KILL' and self.movement != None:
            mov = self.movement
            xPos = self.mathUtil.sawTooth(mov[0] * self.w, mov[2] * self.w,
                                          self.movementTimer)
            self.movementTimer += self.movSpeed
            if self.movementTimer > 1: self.movementTimer = 0
            self.x = xPos

        if self.state == 'KILL' and self.killAnimationTime > 0:
            self.killAnimationTime -= 1
        if self.killAnimationTime <= 0:
            self.game.enemies.remove(self)

        self.velX = self.x - calcX
        self.velY = self.y - calcY

    def hurt(self):
        self.state = 'KILL'
        self.game.audioSystem.playSFX('slime_dead')
        self.game.effectsSystem.generateEffect('COLLECTED', self.x, self.y, 0,
                                               16)
        if self.drop != None and not self.dropAdded:
            self.game.queueSystem.addItem(self.drop)
            self.dropAdded = True
        elif self.drop == None and not self.dropAdded:
            drop = self.game.enemySystem.enemyDefaultDrop(self)
            if drop != None:
                self.game.queueSystem.addItem(drop)
            self.dropAdded = True
Esempio n. 14
0
    def __init__(self, x, y, w, h, props, game):
        self.x, self.y, self.w, self.h = x, y, w, h
        self.cs = (-8, -12)
        self.co = (4, 12)
        self.killAnimationTime = 30
        self.spritePathPrefix = './Assets/Enemies/'
        self.setProperties(props)
        self.game = game
        self.spriteBaseSize = 16
        self.hurtAmount = 1
        self.mathUtil = MathFunctions()

        self.velX = 0
        self.velY = 0

        self.state = "NORMAL"
        self.movSpeed = 0.003

        self.startXPosition = self.x / 32
        self.startYPosition = self.y / 32
        self.endXPosition = self.x / 32
        self.endYPosition = self.y / 32
        if self.have('x'):
            self.endXPosition = int(self.get('x'))
        if self.have('y'):
            self.endYPosition = int(self.get('y'))

        self.movement = [
            self.startXPosition, self.startYPosition, self.endXPosition,
            self.endYPosition
        ]
        self.movementTimer = 0
        self.drop = None
        self.dropAdded = False

        if self.have('drop'):
            attr = self.get('drop').split('|')
            self.drop = QueueItem(attr[0], attr[1] + ':' + attr[2])

        # Idle State
        self.idleSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'slime_idle.png'))
        self.idleAnimation = SpriteAnimation(5, 10, True)
        self.idleState = [
            self.idleSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.idleAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.idleAnimation)

        # Walk State
        self.walkSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'slime_walk.png'))
        self.walkAnimation = SpriteAnimation(2, 20, True)
        self.walkState = [
            self.walkSprite.getimage(self.spriteBaseSize * x, 0,
                                     self.spriteBaseSize, self.spriteBaseSize)
            for x in range(self.walkAnimation.framesQuantity)
        ]
        self.game.animationSystem.addAnimation(self.walkAnimation)

        # Kill State
        self.killSprite = SpriteSheet(
            pygame.image.load(self.spritePathPrefix + 'slime_kill.png'))
        self.killState = [
            self.killSprite.getimage(0, 0, self.spriteBaseSize,
                                     self.spriteBaseSize)
        ]