import pygame
import sys
from pygame.locals import *

pygame.init()
vec = pygame.math.Vector2  

HEIGHT = 450
WIDTH = 400
ACC = 0.5
FRIC = -0.12
FPS = 60

FramePerSecond = pygame.time.Clock()

displaysurface = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Game")

class Player(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.surf = pygame.Surface((30, 30))
        self.surf.fill((128, 255, 40))
        self.rect = self.surf.get_rect(center=(10, 420))
        self.vel = vec(0, 0)  # Velocity vector

    def move(self):
        self.acc = vec(0, 0)

        pressed_keys = pygame.key.get_pressed()

        if pressed_keys[K_LEFT]:
            self.acc.x = -ACC
        if pressed_keys[K_RIGHT]:
            self.acc.x = ACC

        # Apply friction
        self.acc.x += self.vel.x * FRIC

        # Equations of motion
        self.vel += self.acc
        self.rect.move_ip(self.vel)

    def update(self):
        self.move()

class Platform(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.surf = pygame.Surface((WIDTH, 20))
        self.surf.fill((255, 0, 0))
        self.rect = self.surf.get_rect(center=(WIDTH / 2, HEIGHT))

PT1 = Platform()
P1 = Player()

# Game Loop
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    displaysurface.fill((0, 0, 0))
    displaysurface.blit(P1.surf, P1.rect)
    displaysurface.blit(PT1.surf, PT1.rect)

    P1.update()

    pygame.display.update()
    FramePerSecond.tick(FPS)