Esempio n. 1
0
    def __init__(self, midbottom, data):
        Entity.__init__(self, data)
        self.add(data.playerGroup)
        self.add(data.mobs)

        # red theme colour  - currently unused
        colourDict = {
            (206, 209, 138): (206, 138, 138),  # robe
            (170, 192, 171): (191, 170, 170),  # shoes and hat
            (206, 201, 175): (204, 184, 173),  # skin
            (233, 234, 232): (233, 234, 232)
        }  # moustache

        animImages = {}
        for animName in [
                'run', 'jump', 'idle', 'cast', 'push', 'pull', 'grab'
        ]:
            animImages[animName] = pygame.image.load(
                'assets/mobs/player/%s.png' % (animName))
        #animImages = self.setColours(colourDict, animImages)
        self.initAnimations(animImages)

        collisionRect = pygame.Rect((0, 0), (83, 120))
        collisionRect.midbottom = midbottom
        self.collisions = CollisionComponent(self, collisionRect, True)
        self.gravity = GravityComponent(self)
        self.obeysGravity = True
        self.weight = 1
        self.movedThisFrame = False

        self.moveSpeedModifier = {
            'left': 0,
            'right': 0
        }  # a number added on to the player's moveSpeed every frame
        # eg when pushing a crate

        self.xVel = self.yVel = 0
        self.facing = 'R'
        self.isOnGround = False
        self.lastTimeOnGround = 0
        self.releasedJumpButton = True

        self.animation.play('idleR')
        self.animation.update()

        self.rect = self.image.get_rect(midbottom=midbottom)

        self.pullRect = pygame.Rect((0, 0), (40, self.rect.height))
        self.pullStartFacing = None
        self.isPulling = False
Esempio n. 2
0
    def __init__(self, data, image, center, avgLifeSpan, velocity,
                 obeysGravity):
        """obeysGravity: 0 is no gravity, 1 is falling particle, -1 is upward floating particle"""
        Entity.__init__(self, data)
        self.add(data.particles)

        self.image = image
        self.rect = image.get_rect(center=center)
        self.coords = list(center)

        self.velocity = list(velocity)
        self.obeysGravity = obeysGravity
        if obeysGravity:
            self.gravity = GravityComponent(self)
            self.weight = Particle.weight

        self.birthTime = time.time()
        self.lifeTime = random.uniform(avgLifeSpan - 0.3, avgLifeSpan + 0.3)
        if self.lifeTime < 0: self.lifeTime = 0.05