Example #1
0
 def __init__(self, screen, x, y, angle):
     # Make water balloon sprite
     pygame.sprite.Sprite.__init__(self, self.containers)
     # Set up water balloon variable
     self.screen = screen
     self.x = x
     self.y = y
     self.angle = angle
     self.image = pygame.image.load("../assets/BalloonSmallEdited.png")
     self.explosionImages = []
     self.explosionImages.append(
         pygame.image.load("../assets/SplashSmall1.png"))
     self.explosionImages.append(
         pygame.image.load("../assets/SplashSmall2.png"))
     self.explosionImages.append(
         pygame.image.load("../assets/SplashSmall3.png"))
     self.rect = self.image.get_rect()
     self.rect.center = (self.x, self.y)
     self.image, self.rect = toolbox.getRotatedImage(
         self.image, self.rect, self.angle)
     self.speed = 10
     self.angleRads = math.radians(self.angle)
     self.xMove = math.cos(self.angleRads) * self.speed
     self.yMove = -math.sin(self.angleRads) * self.speed
     self.damage = 6
Example #2
0
 def __init__(self, screen, x, y, angle):
     WaterBalloon.__init__(self, screen, x, y, angle)
     self.image = pygame.image.load("../assets/DropSmall.png")
     self.rect = self.image.get_rect()
     self.image, self.rect = toolbox.getRotatedImage(
         self.image, self.rect, self.angle)
     self.damage = 3
Example #3
0
    def update(self, enemies):
        self.rect.center = (self.x, self.y)
        for enemy in enemies:
            if self.rect.colliderect(enemy.rect):
                enemy.getHit(0)
                self.getHit(enemy.damage)

        if self.hurtTimer <= 0:
            imageToRotate = self.image
        else:
            imageToRotate = self.hurtImage
            self.hurtTimer -= 1

        image_to_draw, image_rect = toolbox.getRotatedImage(
            imageToRotate, self.rect, self.angle)
        self.screen.blit(image_to_draw, image_rect)

        self.health_bar_red.x = self.rect.x
        self.health_bar_red.bottom = self.rect.y + 600
        pygame.draw.rect(self.screen, (255, 0, 0), self.health_bar_red)
        self.health_bar_green.topleft = self.health_bar_red.topleft
        health_percentage = self.health / self.health_max
        self.health_bar_green.width = self.health_bar_width * health_percentage
        pygame.draw.rect(self.screen, (0, 255, 0), self.health_bar_green)
        print(self.health_bar_green.top)
        print(self.health_bar_green.topleft)
Example #4
0
    def update(self, projectiles):
        self.angle = toolbox.angleBetweenPoints(self.x, self.y, self.target.x,
                                                self.y)
        angle_rads = math.radians(self.angle)
        self.x_move = (math.cos(angle_rads) / 5) * self.speed
        self.y_move = 0
        self.x += self.x_move
        self.y += self.y_move
        self.rect.center = (self.x, self.y)
        self.image = self.normalImage

        for projectile in projectiles:
            if self.rect.colliderect(projectile.rect):
                self.getHit(projectile.damage)
                projectile.explode()

        if self.hurtTimer <= 0:
            imageToRotate = self.image
        else:
            imageToRotate = self.hurtImage
            self.hurtTimer -= 1

        image_to_draw, image_rect = toolbox.getRotatedImage(
            imageToRotate, self.rect, self.angle)
        self.screen.blit(image_to_draw, image_rect)
Example #5
0
    def update(self, projectiles, crates, explosions):
        # Figure out the angle between the enemy and the player
        self.angle = toolbox.angleBetweenPoints(self.x, self.y, self.player.x,
                                                self.player.y)

        # Move the enemy in the direction it is facing
        angleRads = math.radians(self.angle)
        self.xMove = math.cos(angleRads) * self.speed
        self.yMove = -math.sin(angleRads) * self.speed

        # Check to see if the enemy is gonna run into a crate
        testRect = self.rect
        newX = self.x + self.xMove
        newY = self.y + self.yMove

        testRect.center = (newX, self.y)
        for crate in crates:
            if testRect.colliderect(crate.rect):
                newX = self.x
                self.getAngry(crate)

        testRect.center = (self.x, newY)
        for crate in crates:
            if testRect.colliderect(crate.rect):
                newY = self.y
                self.getAngry(crate)

        self.x = newX
        self.y = newY
        self.rect.center = (self.x, self.y)

        # Check for collisions with explosions
        for explosion in explosions:
            if explosion.damage:
                if self.rect.colliderect(explosion.rect):
                    self.getHit(explosion.damage)

        # Checks for collisions with projectiles
        for projectile in projectiles:
            if self.rect.colliderect(projectile.rect):
                self.getHit(projectile.damage)
                projectile.explode()

        if self.hurtTimer <= 0:
            imageToRotate = self.image
        else:
            imageToRotate = self.imageHurt
            self.hurtTimer -= 1

        imageToDraw, imageRect = toolbox.getRotatedImage(
            imageToRotate, self.rect, self.angle)

        self.screen.blit(imageToDraw, imageRect)
Example #6
0
 def __init__(self, screen, x, y, angle):
     WaterBalloon.__init__(self, screen, x, y, angle)
     self.image = pygame.image.load("../assets/BalloonTNT.png")
     self.rect = self.image.get_rect()
     self.image, self.rect = toolbox.getRotatedImage(
         self.image, self.rect, self.angle)
     self.explosionImages = []
     self.explosionImages.append(
         pygame.image.load("../assets/LargeExplosion1.png"))
     self.explosionImages.append(
         pygame.image.load("../assets/LargeExplosion2.png"))
     self.explosionImages.append(
         pygame.image.load("../assets/LargeExplosion3.png"))
Example #7
0
    def update(self):
        self.rect.center = (self.x, self.y)

        if self.shoot_cooldown > 0:
            self.shoot_cooldown -= 1

        mouse_x, mouse_y = pygame.mouse.get_pos()
        self.angle = toolbox.angleBetweenPoints(self.x, self.y, mouse_x,
                                                mouse_y)

        image_to_draw, image_rect = toolbox.getRotatedImage(
            self.image, self.rect, self.angle)
        self.screen.blit(image_to_draw, image_rect)
Example #8
0
 def __init__(self, screen, x, y, angle):
     pygame.sprite.Sprite.__init__(self, self.containers)
     self.screen = screen
     self.x = x
     self.y = y
     self.angle = angle
     self.image = pygame.image.load(image_util.getImage("bullet.png"))
     self.rect = self.image.get_rect()
     self.x += 5
     self.rect.center = (self.x, self.y)
     self.image, self.rect = toolbox.getRotatedImage(
         self.image, self.rect, self.angle)
     self.speed = 20
     self.angle_rads = math.radians(self.angle)
     self.x_move = math.cos(self.angle_rads) * self.speed
     self.y_move = -math.sin(self.angle_rads) * self.speed
     self.damage = 15
Example #9
0
    def update(self, enemies, explosions):
        self.rect.center = (self.x, self.y)

        # Check for collision with players
        for explosion in explosions:
            if explosion.damage and explosion.damagePlayer:
                if self.rect.colliderect(explosion.rect):
                    self.getHit(explosion.damage)

        # Check for collision with Enemies
        for enemy in enemies:
            if self.rect.colliderect(enemy.rect):
                enemy.getHit(0)
                self.getHit(enemy.damage)

        if self.shootCooldown > 0:
            self.shootCooldown -= 1

        if self.crateCooldown > 0:
            self.crateCooldown -= 1

        # Stop the player from leaving the game screen
        if self.rect.left < 0:
            self.rect.left = 0
        if self.rect.right > self.screen.get_width():
            self.rect.right = self.screen.get_width()
        if self.rect.top < 0:
            self.rect.top = 0
        if self.rect.bottom > self.screen.get_height():
            self.rect.bottom > self.screen.get_height()
        self.x = self.rect.centerx
        self.y = self.rect.centery

        if self.alive:
            # Get the angle between the player and the mouse
            mouseX, mouseY = pygame.mouse.get_pos()
            self.angle = toolbox.angleBetweenPoints(self.x, self.y, mouseX,
                                                    mouseY)

        # Figure out which picture to draw
        if self.alive:
            if self.hurtTimer > 0:
                imageToRotate = self.hurtImage
                self.hurtTimer -= 1
            else:
                imageToRotate = self.image
        else:
            imageToRotate = self.defeatedImage

        # Get the rotated version of the player picture
        imageToDraw, imageRect = toolbox.getRotatedImage(
            imageToRotate, self.rect, self.angle)

        self.screen.blit(imageToDraw, imageRect)

        # Move and draw health bar
        self.healthbarRed.x = self.rect.x
        self.healthbarRed.bottom = self.rect.y - 5
        pygame.draw.rect(self.screen, (255, 0, 0), self.healthbarRed)
        self.healthbarGreen.topleft = self.healthbarRed.topleft
        healthPercentage = self.health / self.maxHealth
        self.healthbarGreen.width = self.healthbarWidth * healthPercentage
        if self.alive:
            pygame.draw.rect(self.screen, (0, 255, 0), self.healthbarGreen)