#Trisha Ruiz
#6/13/2023
#Platformer Movements

#constants
WINDOW_HEIGHT = 700
WINDOW_WIDTH = 1000

FLOOR_HEIGHT = 300
FLOOR_SURFACE = WINDOW_HEIGHT - FLOOR_HEIGHT

#character constants
radius = 40
chara_x = radius + 20
chara_y = FLOOR_SURFACE - radius - 100
gravity = 1
touched_floor = False

#enemy constants
enemy_radius = 30
enemy_x = WINDOW_WIDTH - enemy_radius - 50
enemy_y = 0
speed = 5
sin_y = 200
sin_height = 50

#initialization
import pygame, sys, math
from pygame.locals import *
pygame.init()
clock = pygame.time.Clock()

#set window
DISPLAYSURF = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption("platformer movements")

#game loop
while True:
    clock.tick(60) #sets fps
    
    #event handler
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    #fill background
    DISPLAYSURF.fill("light blue")
    
    #platform - floor surface is WINDOW_HEIGHT - FLOOR_HEIGHT
    pygame.draw.rect(DISPLAYSURF, "light green", (0, FLOOR_SURFACE, WINDOW_WIDTH, FLOOR_HEIGHT))

    #CHARACTER

    #falling
    gravity += 1 #constantly falling
    chara_y += gravity

    #floor touch
    if chara_y >= FLOOR_SURFACE-radius :
        chara_y = FLOOR_SURFACE - radius
        touched_floor = True

    #move forward
    chara_x += 3
    
    if chara_x % 10 == 0 and touched_floor:
        gravity = -5
        
    
    #wrap around
    if chara_x >= WINDOW_WIDTH + radius:
        chara_x = -radius
    
    #draw chara
    pygame.draw.circle(DISPLAYSURF, "red", (chara_x, chara_y), radius)

    #ENEMY : BIRD SINE MOVEMENT
    
    t = pygame.time.get_ticks() / speed 
    enemy_y = math.sin(t/50.0) * sin_height + sin_y

    pygame.draw.circle(DISPLAYSURF, "blue", (enemy_x, enemy_y), enemy_radius)
    
    
    pygame.display.update()
