write funcitons to fix my control issues import pygame
from auxiliar.helpers import Auxiliar
from auxiliar.constants import open_configs, screen_w, screen_h
from models.arrow import Arrow


class Player:
    def __init__(self, x, y, speed_walk, speed_run, gravity, jump, stage_name) -> None:
        self.walk_r = Auxiliar.getSurfaceFromSpriteSheet(
            open_configs()[stage_name]['player']['player_cross_run'],
            columns=20,
            rows=1,
            step=2
        )
        self.walk_l = Auxiliar.getSurfaceFromSpriteSheet(
            open_configs()[stage_name]['player']['player_cross_run'],
            flip=True,
            columns=20,
            rows=1,
            step=2
        )
        self.stay = Auxiliar.getSurfaceFromSpriteSheet(
            open_configs()[stage_name]['player']['player_cross_idle'],
            columns=1,
            rows=1,
            step=1
        )[:1]
        self.jump_r = Auxiliar.getSurfaceFromSpriteSheet(
            open_configs()[stage_name]['player']['player_cross_jump'],
            columns=17,
            rows=1,
            delay=3

        )

        self.jump_l = Auxiliar.getSurfaceFromSpriteSheet(
            open_configs()[stage_name]['player']['player_cross_jump'],
            columns=16,
            rows=1,
            flip=True
        )

        self.land = Auxiliar.getSurfaceFromSpriteSheet(
            open_configs()[stage_name]['player']['player_cross_land'],
            columns=17,
            rows=1,
            delay=3
        )

        self.frame = 0
        self.move_x = x
        self.move_y = y
        self.speed_walk = speed_walk
        self.gravity = gravity
        self.jump = jump
        self.animation = self.stay
        self.image = self.animation[self.frame]
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
        self.is_jumping = False

        self.last_jump_time = pygame.time.get_ticks()  # Initialize with the current time
        self.jump_cooldown = 500  # Set the cooldown time in milliseconds

        # Atributos para disparar y recargar
        self.ready = True
        self.arrow_time = 0
        self.arrow_cooldown = 600
        self.bullet_group = pygame.sprite.Group()
        self.puntaje = 0

    @property
    def get_bullets(self) -> list[Arrow]:
        return self.bullet_group

    def shoot_arrow(self):
        self.bullet_group.add(self.create_bullet())

    def create_bullet(self):
        return Arrow(self.rect.x,
                     self.rect.top)  # Crea y devuelve un objeto de la clase Arrow en la posición actual del ratón

    def recharge(self):
        if not self.ready:
            current_time = pygame.time.get_ticks()
            if current_time - self.arrow_time >= self.arrow_cooldown:
                self.ready = True

    def control(self, keys, events):
        current_time = pygame.time.get_ticks()

        # Default values
        self.move_x = 0
        self.move_y = 0

        if keys[pygame.K_RIGHT]:
            self.move_x = self.speed_walk
            self.animation = self.walk_r
        elif keys[pygame.K_LEFT]:
            self.move_x = -self.speed_walk
            self.animation = self.walk_l

        elif not keys[pygame.K_SPACE] and not keys[pygame.K_RIGHT] and not keys[pygame.K_LEFT]:
            self.frame = 0
            self.animation = self.stay

        if keys[pygame.K_SPACE] and (not self.is_jumping):
            self.move_y = -self.jump
            self.last_jump_time = current_time
            self.animation = self.jump_r
            self.is_jumping = True
        if (self.is_jumping == True):
            self.is_jumping = False
            self.move_y = 0
        if (self.rect.y < screen_h - self.rect.height):
            self.move_y += self.gravity
        else:
            self.rect.y = screen_h - self.rect.height
            self.move_y = 0
            self.is_jumping = False

        # Shoot arrow logic
        if keys[pygame.K_e] and self.ready:
            self.shoot_arrow()
            self.ready = False
            self.arrow_time = pygame.time.get_ticks()

    def constraint(self):
        # Stop when reaching the right edge of the screen
        if self.rect.x > screen_w - self.rect.width:
            self.rect.x = screen_w - self.rect.width
            self.move_x = 0

        # Stop when reaching the left edge of the screen
        if self.rect.x < -200:
            self.rect.x = -200
            self.move_x = 0

        # Stop when reaching the top edge of the screen
        if self.rect.y < 0:
            self.rect.y = 0
            self.move_y = 0

    def draw(self, screen):
        self.image = self.animation[self.frame]
        screen.blit(self.image, self.rect)

    def update(self, screen: pygame.surface.Surface):
        current_time = pygame.time.get_ticks()
        self.recharge()
        self.bullet_group.draw(screen)
        self.bullet_group.update()
        self.constraint()

        if (self.is_jumping == True):
            self.is_jumping = False
            self.move_y = 0

        if (self.frame < len(self.animation) - 1):
            self.frame += 1
        else:
            self.frame = 0

        self.rect.x += self.move_x
        self.rect.y += self.move_y

        # Apply gravity if the player is above the ground
        if self.rect.y < screen_h - self.rect.height:
            self.move_y += self.gravity
        else:
            # Snap the player to the ground when they reach the bottom of the screen
            self.rect.y = screen_h - self.rect.height
            self.move_y = 0
            self.is_jumping = False