Пример #1
0
    def __init__(
            self, screen, images, ends
    ):  # ends: idle, walk_down, walk_right, walk_left,,walk_up, spell
        super(Player, self).__init__()
        self.images = images
        self.ends = ends
        self.currentState = ends[0]

        self.image = self.images[0]
        self.rect = self.image.get_rect()
        self.rect.center = (20 * 23, 22 * 23 - 1)

        self.spellCasting = False
        self.currentSpell = None
        self.animationController = Animation(self.currentState[1], self)

        self.defaultHP = 100
        self.lives = 100

        self.defaultMana = 100
        self.mana = 100

        self.spellAnims = {
            "cutSpell": (5, 1.8),
            "lightingSpell": (6, 1),
            "explosionSpell": (6, 1)
        }

        self.timerStart = 0
Пример #2
0
 def Animation_Sequence(Object):
     return [
         Animation(Start_Value=50,
                   End_Value=500,
                   Animation_Duration=1,
                   Function=lambda New_X_Cords: Object.move(
                       New_X_Cords, Object.y())),
         Animation(Start_Value=50,
                   End_Value=310,
                   Animation_Duration=1,
                   Function=lambda New_Y_Cords: Object.move(
                       Object.x(), New_Y_Cords),
                   Time_Till_Animation_Start=1),
         Animation(Start_Value=500,
                   End_Value=50,
                   Animation_Duration=1,
                   Function=lambda New_X_Cords: Object.move(
                       New_X_Cords, Object.y()),
                   Time_Till_Animation_Start=2),
         Animation(Start_Value=310,
                   End_Value=50,
                   Animation_Duration=1,
                   Function=lambda New_Y_Cords: Object.move(
                       Object.x(), New_Y_Cords),
                   Time_Till_Animation_Start=3)
     ]
Пример #3
0
def Load_Animation():

    Animation_Name = 'Movment_Along_Border'

    Animation_Sequence = lambda Object: [
        Animation(Start_Value=50,
                  End_Value=500,
                  Animation_Duration=1,
                  Function=lambda New_X_Cords: Object.place(
                      x=New_X_Cords, y=Object.winfo_y())),
        Animation(Start_Value=50,
                  End_Value=310,
                  Animation_Duration=1,
                  Function=lambda New_Y_Cords: Object.place(x=Object.winfo_x(),
                                                            y=New_Y_Cords),
                  Time_Till_Animation_Start=1),
        Animation(Start_Value=500,
                  End_Value=50,
                  Animation_Duration=1,
                  Function=lambda New_X_Cords: Object.place(
                      x=New_X_Cords, y=Object.winfo_y()),
                  Time_Till_Animation_Start=2),
        Animation(Start_Value=310,
                  End_Value=50,
                  Animation_Duration=1,
                  Function=lambda New_Y_Cords: Object.place(x=Object.winfo_x(),
                                                            y=New_Y_Cords),
                  Time_Till_Animation_Start=3)
    ]

    # Adding Animation Sequences.
    Animation_M.Add_Animation_Sequence(Animation_Name, Animation_Sequence)
Пример #4
0
    def __init__(self, images, coords, group, offset, block_size):
        super(Decoration, self).__init__()

        self.images = images
        self.image = self.images[0]
        self.animationController = Animation(len(self.images), self)

        self.rect = pygame.Rect((offset[0] + coords[0] * block_size[0],
                                 offset[1] + coords[1] * block_size[1]),
                                (block_size[0], block_size[1]))

        group.add(self)
Пример #5
0
class Spell(pygame.sprite.Sprite):
    def __init__(self,imageSet,radius,damage, yOffset, mana, enemy, renderer, centerPos):
        super(Spell, self).__init__()
        self.images = imageSet
        self.image = self.images[0]
        self.rect = self.image.get_rect()

        self.rect.centerx, self.rect.centery = centerPos[0]//2+renderer.cameraOffset[0],centerPos[1]//2+renderer.cameraOffset[1]
        self.rect.y -= yOffset

        self.animationController = Animation(len(imageSet),self)

        self.damage = damage
        self.radius = pygame.Rect(self.rect.midbottom, (radius*2, radius*2))

        self.activated = False
        self.manaConsuptions = mana

        self.intersects(enemy)

    def intersects(self,enemy):
        if self.radius.colliderect(enemy.rect):
            enemy.dealDamage(self.damage)
            
    
    def update(self):
        if self.animationController.animateOnce(self.images, 2):
            self.kill()
Пример #6
0
class Decoration(pygame.sprite.Sprite):
    def __init__(self, images, coords, group, offset, block_size):
        super(Decoration, self).__init__()

        self.images = images
        self.image = self.images[0]
        self.animationController = Animation(len(self.images), self)

        self.rect = pygame.Rect((offset[0] + coords[0] * block_size[0],
                                 offset[1] + coords[1] * block_size[1]),
                                (block_size[0], block_size[1]))

        group.add(self)

    def update(self):
        if self.animationController.animCount > 0:
            self.animationController.animateRepeat(self.images, 1.4)
Пример #7
0
    def __init__(self,imageSet,radius,damage, yOffset, mana, enemy, renderer, centerPos):
        super(Spell, self).__init__()
        self.images = imageSet
        self.image = self.images[0]
        self.rect = self.image.get_rect()

        self.rect.centerx, self.rect.centery = centerPos[0]//2+renderer.cameraOffset[0],centerPos[1]//2+renderer.cameraOffset[1]
        self.rect.y -= yOffset

        self.animationController = Animation(len(imageSet),self)

        self.damage = damage
        self.radius = pygame.Rect(self.rect.midbottom, (radius*2, radius*2))

        self.activated = False
        self.manaConsuptions = mana

        self.intersects(enemy)
Пример #8
0
def Load_Animation():

    Animation_Name = 'Movment_Side_To_Side'

    Animation_Sequence = lambda Object: [
        Animation(Start_Value=50,
                  End_Value=500,
                  Animation_Duration=1 + Object.y() / 250,
                  Function=lambda New_X_Cords: Object.move(
                      New_X_Cords, Object.y())),
        Animation(Start_Value=500,
                  End_Value=50,
                  Animation_Duration=1 + Object.y() / 250,
                  Function=lambda New_X_Cords: Object.move(
                      New_X_Cords, Object.y()),
                  Time_Till_Animation_Start=1 + Object.y() / 250)
    ]

    # Adding Animation Sequences.
    Animation_M.Add_Animation_Sequence(Animation_Name, Animation_Sequence)
Пример #9
0
    def __init__(self, pos, images, snowflakeImage, lives, player, attackdist,
                 timerController):
        super(SnowBoss, self).__init__()
        self.images = images
        self.image = images[0]
        self.rect = pygame.Rect(pos, self.image.get_size())

        self.lives = lives
        self.defaultHP = lives

        self.player = player
        self.atackdis = attackdist
        self.snowflakeImage = snowflakeImage
        self.timerController = timerController

        self.noticed = False
        self.snowflakes = pygame.sprite.Group()
        self.speed = 2.5
        self.currentlyAttack = False
        self.approaching = True
        self.animationController = Animation(2, self)
 def animate(self):
     anm = Animation(self.l, self.timestep, self.n, self.T)
     anm.generateAnimation(self.state, "anim.gif")
Пример #11
0
class Player(pygame.sprite.Sprite):
    def __init__(
            self, screen, images, ends
    ):  # ends: idle, walk_down, walk_right, walk_left,,walk_up, spell
        super(Player, self).__init__()
        self.images = images
        self.ends = ends
        self.currentState = ends[0]

        self.image = self.images[0]
        self.rect = self.image.get_rect()
        self.rect.center = (20 * 23, 22 * 23 - 1)

        self.spellCasting = False
        self.currentSpell = None
        self.animationController = Animation(self.currentState[1], self)

        self.defaultHP = 100
        self.lives = 100

        self.defaultMana = 100
        self.mana = 100

        self.spellAnims = {
            "cutSpell": (5, 1.8),
            "lightingSpell": (6, 1),
            "explosionSpell": (6, 1)
        }

        self.timerStart = 0

    def startTimer(self):
        self.timerStart = pygame.time.get_ticks()

    def timerUpdate(self):
        if not self.mana == self.defaultMana:
            seconds = (pygame.time.get_ticks() -
                       self.timerStart) / 1000  #calculate how many seconds
            if seconds > 4:
                self.mana += 1

    @property
    def currentAnimation(self):
        return self.ends.index(self.currentState)

    def dealDamage(self, damage):
        self.lives -= damage

    def changeAnimation(self, id):
        self.currentState = self.ends[id]
        self.animationController.animCount = self.currentState[
            1] - self.currentState[0]
        self.animationController.currentAnimFrame = 0
        self.animationController.currentGameFrame = 0
        self.image = self.images[self.currentState[0]:self.currentState[1]][0]
        center = self.rect.center
        self.rect = pygame.Rect((self.rect.x, self.rect.y),
                                self.image.get_size())
        self.rect.center = center

    def castingSpell(self, spellName, spell):
        self.spellCasting = spellName

        if self.currentSpell:
            self.currentSpell.activated = True

        self.currentSpell = spell
        self.mana -= self.currentSpell.manaConsuptions
        self.startTimer()
        self.changeAnimation(self.spellAnims[spellName][0])

    def freeze(self):
        pass

    def update(self):
        if not self.spellCasting:
            self.animationController.animateRepeat(
                self.images[self.currentState[0]:self.currentState[1]], 2)
        else:
            if self.animationController.animateOnce(
                    self.images[self.currentState[0]:self.currentState[1]],
                    self.spellAnims[self.spellCasting][1]):
                self.spellCasting = ''
                self.currentSpell.activated = True
                self.changeAnimation(0)

        self.timerUpdate()
Пример #12
0
class SnowBoss(pygame.sprite.Sprite):
    def __init__(self, pos, images, snowflakeImage, lives, player, attackdist,
                 timerController):
        super(SnowBoss, self).__init__()
        self.images = images
        self.image = images[0]
        self.rect = pygame.Rect(pos, self.image.get_size())

        self.lives = lives
        self.defaultHP = lives

        self.player = player
        self.atackdis = attackdist
        self.snowflakeImage = snowflakeImage
        self.timerController = timerController

        self.noticed = False
        self.snowflakes = pygame.sprite.Group()
        self.speed = 2.5
        self.currentlyAttack = False
        self.approaching = True
        self.animationController = Animation(2, self)

    def dealDamage(self, damage):
        self.lives -= damage
        if self.lives <= 0:
            self.kill()

    @property
    def xDistance(self):
        return self.player.rect.centerx - self.rect.centerx

    @property
    def yDistance(self):
        return self.player.rect.centery - self.rect.centery

    def approach(self, untilDist=60):
        sign = lambda x: x and (1, -1)[x < 0]

        direction = (sign(self.xDistance) * self.speed,
                     sign(self.yDistance) * self.speed)
        distance = math.sqrt((self.xDistance)**2 + (self.yDistance)**2)

        if distance <= untilDist:
            if not self.currentlyAttack:
                self.timerController.createTimer(1, self.iceFreeze, False)
                self.currentlyAttack = True
            return True

        self.rect.move_ip(direction)
        return False

    def checkPlayer(self):
        distance = math.sqrt((self.xDistance)**2 + (self.yDistance)**2)
        if distance <= self.atackdis:
            self.noticed = True
            self.snowBall()

    def snowBall(self):
        sign = lambda x: x and (1, -1)[x < 0]
        direction = (sign(self.xDistance), sign(self.yDistance))
        snowflake = Snowflake(self.rect.center, self.snowflakeImage,
                              self.player, direction, 400, 15, self.snowflakes)
        self.currentlyAttack = False

    def snowRing(self):
        diresctions = [(-1, 1), (0, 1), (1, 1), (-1, 0), (1, 0), (-1, -1),
                       (0, -1), (1, -1)]
        for direction in diresctions:
            snowFlake = Snowflake(self.rect.center, self.snowflakeImage,
                                  self.player, direction, 300, 5,
                                  self.snowflakes)
        self.currentlyAttack = False

    def iceFreeze(self):
        radius = pygame.Rect(self.rect.center, (75, 75))
        if radius.colliderect(self.player.rect):
            self.player.freeze()
            self.timerController.createTimer(1, self.snowBall, False)
        else:
            self.timerController.createTimer(1, self.snowRing, False)

    def aproachVar(self):
        self.approaching = True

    def update(self):
        if not self.noticed:
            self.checkPlayer()
        else:
            if self.approaching:
                if self.approach():
                    self.approaching = False
                    self.timerController.createTimer(3, self.aproachVar, False)

        self.snowflakes.update()

        self.timerController.updateTimers()

        self.animationController.animateRepeat(self.images, 2)