# Leo Salazar
# 6/13/2024
# file containing all the classes used in swimming.py

import pygame
import random

# base class
class Block(pygame.sprite.Sprite):

    # stores group, color, x, y, w, h to make a block
    def __init__(self, group, color, x, y, width, height):
        pygame.sprite.Sprite.__init__(self, group)
        self.color = color
        self.image = pygame.Surface((width, height))
        self.rect = self.image.get_rect(center=(x, y))
        self.image.fill(color)

# player inherits block
class Player(Block):

    # asks for an image as well to represent the player instead of a color
    def __init__(self, group, image, color, x, y, width, height):
        super().__init__(group, color, x, y, width, height)
        self.image = image
        self.rect = self.image.get_rect(center=(x, y))

# enemy inherits block
class Enemy(Block):

    # stores an image as well as the row number for drawing purposes
    def __init__(self, group, image, color, row, x, y, width, height):
        super().__init__(group, color, x, y, width, height)
        self.image = image
        self.rect = self.image.get_rect(center=(x, y))
        self.rect.y -= (height + 10)*row

    # moves forward a random amount every time this method is called
    def update(self, playing):
        if playing:
            move = random.randint(20, 40)
            self.rect.x += move

# text block inheriting block
class Text(Block):

    # stores the text and font size on top of the usual
    def __init__(self, group, text, size, color, x, y, width, height):
        super().__init__(group, color, x, y, width, height)

        # stores the string and makes a font based on size
        self.text = text
        self.font = pygame.font.Font(None, size)

    # will make the message and rect for the text and blit it on to the parent block/surface
    def update(self):
        msg = self.font.render(self.text, True, "black")
        msg_box = msg.get_rect(center=(25, 25))
        self.image.blit(msg, msg_box)

# falling inherits text so I can make a falling key block
class Falling(Text):

    # same constructor
    def __init__(self, group, text, size, color, x, y, width, height):
        super().__init__(group, text, size, color, x, y, width, height)

    # moves a fixed speed based on the difficulty
    def update(self, screen, pressed, speed):
        super().update()
        self.rect.move_ip(0, speed)

        # kills the block if it goes out of bounds or gets pressed
        if pressed or self.rect.top > screen.get_height():
            self.kill()