from JMSSGraphics import *
import time 

jmss = Graphics(width = 1000, height = 600, title = "Final Game!", fps = 60)

ypos = 265
yvel = 0
xpos = 460
xvel = 0
ball_image = jmss.loadImage("basketball.png")
bg_image = jmss.loadImage("basketball court.png")
paddle_image = jmss.loadImage("paddle.png")

print("Use W key for up, S key for down, A key for left, D key for right")
start = input("ARE YOU READY???? 'yes' will commence the game")

@jmss.mainloop
def game():
    global ypos, yvel, xpos, xvel, paddle_image, bg_image, ball_image 

    if start == "yes":
        
        if jmss.isKeyDown(KEY_S):                                                       #inputs from the W and S keys that control the ball's variable for vertical velocity
            yvel -= 1/2
        if jmss.isKeyDown(KEY_W):
            yvel += 1/2
        if jmss.isKeyDown(KEY_A):                                                       #inputs from the A and D keys that control the ball's variable for horizontal velocity
            xvel -= 1/2
        if jmss.isKeyDown(KEY_D):
            xvel += 1/2
            
        ypos += yvel                                                                    #maps the motion of the ball
        xpos += xvel
    
        if ypos < 0:                                                                    #setting constraints to make the ball bounce back if it hits a wall
            yvel = -yvel
        if ypos > 520:
            yvel = -yvel
        if xpos < 0:
            xvel = -xvel
        if xpos > 920:
            xvel = -xvel

        if jmss.isKeyDown(KEY_P):
            time.sleep(10)

        jmss.clear()
        jmss.drawImage(bg_image, x = 0, y = 0, width = 1000, height = 600)
        jmss.drawImage(paddle_image, x = 0, y = 0, width = 16, height = 120)
        jmss.drawImage(ball_image, x = xpos, y = ypos, width = 80, height = 80)
    

jmss.run()

