# LIM TZE YEE
# 11675492
# Recitation 8
# PHYS 113

from visual import *
from random import *

# Characters and attributes
me = sphere (radius=5, color=color.blue)
friend = sphere (pos=vector(20,0,0),radius=5, color=color.red)
scene.autoscale = 0

# Definitions
n    = 0
dt   = 0.1
tmax = 10
t    = 0
g    = 9.8
x    = z = 0
y    = g
a    = vector(0,-g,0)
Fo   = .1*a

# Introduction to game
M = raw_input("Please enter your name = ")            # me
print "Hi,",
print M,
print "!"
F = raw_input("Please enter a friend's name = ")      # friend
print "Great! Now grab some biscuits, read a short story and we're ready to play!"
print "Now here's the story..."
print "Once upon a time, there were 2 one-quarter people,",
print M,
print "and",
print F,
print "."
print "Now you see,",
print M,
print "and",
print F,
print "aren't really real people."
print "For they are the heads of the headless horsemen."
print M,
print "is a big blue head and",
print F,
print "is a big red head."
print "While their bodies galloped on the face of earth,"
print M,
print "and",
print F,
print "just bobbed around in the land of nowhere."
print "Being colorful heads with nothing to do, they were bored out of their minds."
print "So,",
print M,
print "decided to conjure some biscuits and throw them at",
print F,
print ","
print "and",
print F,
print "is to catch it in the mouth, or at least lick it."
print "(As to why",
print M,
print "did not conjure a PS3 instead is beyond me)"
print "Anyway,",
print M,
print "and",
print F,
print "played throw-the-biskie over and over,"
print "and they lived happily ever after (until they were buried in a sea of biscuits)..."
print "Now, game time, M!"
print "Fast hint: Zoom out for a better view."
print "If you think you hit but your friend does not seem to get it,"
print "the biscuit probably hit the eye instead of into the mouth."
print "Another fast hint: The land of nowhere is almost like outer space,"
print "except torso-less colorful heads can live perfectly well for eternity in it."
print "Hence, air resistance do not have to be taken into consideration."
print "One more fast hint (I promise this is the last, you'd get to play soon):"
print "The law of projectile motion still apply,"
print "for It is one of the Physics Laws that govern the whole Universe."
print "Okay, that's it,",
print M,
print "! Ready, set, go!"

# Loop
while True:   

    # velocity in x-direction
    print "How fast will you throw the biscuit forward?" 
    vx = input()
    # velocity in y-direction
    print "How fast will you throw the biscuit up?"      
    vy = input()
    
    biscuit  = sphere(pos=vector(0,0.7,0), radius=2, m=0.1, p=.1*vector(vx,vy), color=color.yellow)
        
    while biscuit.pos.y >= 0:

        xpos = random()*50 + 50 # for the friend to move around trying to catch the biscuit 
        friend.pos = vector(xpos,0,0)      
        
        if biscuit.pos.y <= 0:
            n += 1
        if n <= 1:
            rate(1./dt)
            t += dt

            # Physics principles involved
            biscuit.pos += (biscuit.p/biscuit.m)*dt
            biscuit.p   += Fo*dt

        # To win
        if biscuit.pos.x - friend.pos.x >= 0 and biscuit.pos.x - friend.pos.x <= 5 and biscuit.pos.y <= 5:
            print "Yum!" 


            
            
