#Justin Sochor
#Rec 2
#Final Project

from visual import *
scene.autoscale = 0
scene.center = vector(5,12,5)

print "Well here we are, the final Recitation. I cant say it hasnt been an experience, but all things must come to an end, and thus we come to the end game.  The object here is pretty much obvious; just send the ball through the hoop.  Shouldnt be too hard, as the hoop is just a figment of your imagination.  Youll see what I mean. "

print "Enter v_y, v_z (ft/s)"
vy=input()
vz=input()


the_paint=box(pos=vector(0,0,0),length=20,height=.5,width=20,color=(1,.7,.3))
#Creates the court


hoop     = ring(pos=vector(0,10,-10),axis=(0,1,0),radius=1,thickness=.2,color=(3,1,0))
backboard= box(pos=vector(0,11,-11),length=4,height=2.75,width=.5)
the_box  = box(pos=vector(0,11,-11),length=1.5,height=1.2,width=.6,color=(1,0,0))
pole     = box(pos=vector(0,10,-12),length=20,height=20,width=1,color=color.blue)
#The previous section constructs a standard basketball hoop

head=sphere(pos=vector(0,6,10),radius=.5,color=(1,.5,0))
body=ellipsoid(pos=(0,3,10),length=1.75,height=6,width=1,color=(1,.5,0))
#The previous section creates a charater to provide visual appeal



t   = 0
tmax= 100
dt  = .015
g   = -9.8
#Sets a few hard coded constants


ball   = sphere(pos=vector(0,6.5,9),m=4,radius=.45,color=(3,1,0))
ball.p = vector(0,(vy*ball.m),(-vz*ball.m))
fg     = ball.m*g
ball.dp= vector(0,(fg*dt),0)
trail  = curve(color=(3,1,0))
#Creates a ball, the item which will suffer physics
trail.append(ball.pos)

has_scored = False

while (t<tmax):
    rate(1./dt)
    t        += dt

    if ((ball.pos.z-ball.radius)<((backboard.width/2.0)+backboard.pos.z)):
            ball.p = vector(0, ball.p.y,-ball.p.z)
#Lets the ball rebound off the backboard


    if mag(ball.pos-hoop.pos) < .1 and has_scored==False:
        print "Score!"
        has_scored = True
#Tells us that you made the shot


    if ((ball.pos.y-ball.radius)<(the_paint.height/2.0+the_paint.pos.y)):
        ball.p = vector(0,-ball.p.y,ball.p.z)
        go   = label(pos=vector(0,20,0),height=2,color=color.red,font='Arial',text='Play Again? Yeah Right! I cant do that?! Blame Ana.')
        gobox= box(pos=vector(0,20,0),length=30,height=2.5,width=1)
        print "Rotate the Camera to see the Hidden Message"
#That nasty bit of business tells the game to display some stuff once the ball has hit the floor   


    if ball.pos.z > the_paint.width/2:
        t=tmax
        print "Cease!"
#Stops the action when the ball exits the court

    ball.p   += ball.dp
    ball.pos += (ball.p/ball.m)*dt
    trail.append(ball.pos)
#Updates the ball until one of the above statments stop it
