Example #1
0
    def __init__(self, engine, image=None, velocity=(0, 0),
                 speed=40, destination=None, health=100):

        self.velocity = velocity
        self.sprite = None
        self.engine = engine

        self.numCandiesCrushed = 0

        self.frames = [pygame.image.load(img).convert_alpha() for img in MOLARR_SWINGING_IMGS]
        if image is None:
            self.image = self.frames[0]
        else:
            self.image = image

        # Keeps track of whether or not Mo'Larr is swinging his hammer
        self.isSwinging = False
        # To keep track of which animation frame we're on
        self.swingFrameCounter = 0
        # Toggles whether the hammer is going down or going back up
        self.isSwingingDown = True


        # Are we facing right or left?
        self.facingRight = True
        # Signals to the renderer that the direction has changed
        self.flipImage = False
        # If true, there is no flipping
        self.overrideFlip = False

        Entity.__init__(self, engine, self.image,
                        velocity, speed, (0, 0), destination, health)
Example #2
0
    def __init__(self, engine, image=None, speed=None, health=1, isSeeker=None):

        self.engine = engine

        self.damage = self.engine.timeKeeper.candyDamage()

        if speed is None:
            self.maxSpeed = self.engine.timeKeeper.candySpeed()
        else:
            self.maxSpeed = speed

        self.destination = None

        if isSeeker is None:
            self.isSeeker = self.engine.timeKeeper.isCandyASeeker()
        else:
            self.isSeeker = isSeeker

        if image is None:
            self.image = choice(self.engine.allCandies)
        else:
            self.image = image

        self.rect = self.image.get_rect()

        # Equal chance of appearing on the top, right, or bottom sides
        rand = randint(1, 3)
        x, y = (0, 0)

        velX = choice(list(range(-10, 0)) + list(range(1, 10)))
        velY = choice(list(range(-10, 0)) + list(range(1, 10)))

        velocity = np.array([velX, velY], np.float64)
        if rand == 1:
            x = randint(0, SCREEN_SIZE[0] - self.rect.width)
            velocity[1] = abs(velocity[1])
        elif rand == 2:
            x = SCREEN_SIZE[0] - self.rect.width
            y = randint(0, SCREEN_SIZE[1] - self.rect.height)
            velocity[0] = abs(velocity[0])
        else:
            y = SCREEN_SIZE[1] - self.rect.height
            x = randint(0, SCREEN_SIZE[1] - self.rect.width)
            velocity[1] = abs(velocity[1])

        velocity /= np.linalg.norm(velocity)
        velocity *= self.maxSpeed

        self.velocity = np.round(velocity).astype(np.int32)

        self.initialPosition = (x, y)

        Entity.__init__(self, engine, self.image,
                        self.velocity, self.maxSpeed, self.initialPosition,
                        destination=self.destination, health=health)
Example #3
0
    def __init__(self, engine):
        self.engine = engine
        self.image = pygame.image.load(TOOTHBRUSH_IMG)
        self.rect = self.image.get_rect()

        x = randint(0, SCREEN_SIZE[0] - self.rect.width)
        y = randint(0, SCREEN_SIZE[1] - self.rect.height)

        self.initialPosition = [x, y]

        Entity.__init__(self, engine, self.image, [0, 0], 0, self.initialPosition)
Example #4
0
    def update(self):
        if self.isSeeker:
            velocity = np.array(self.engine.player.centerOfBody(), np.float64) - \
                np.array(self.getCenter(), np.float64)

            velocity /= np.linalg.norm(velocity)
            velocity *= self.maxSpeed

            self.velocity = velocity


        Entity.update(self)