#Jon Brennan
#Dart Game

from visual import *

#variable that checks if you missed or got close enough
check = True

while check:

#creating scene, object names are obvious

    dart = cylinder(pos=vector(0.5,6,0), axis=(0.5,0,0), radius=0.1, color=color.blue, m=0.015)
    dartboard = cylinder(pos=vector(7.77,5.67,0), axis=(0.1,0,0), radius=0.75, color=color.yellow)
    bullseye = cylinder(pos=vector(7.77,5.67,0), axis=(0.1,0,0), radius=0.1, color=color.red)
    ground = box(pos=vector(3.27,0,0), length=9, width=6, height=0.1, color=color.green)
    thrower = cylinder(pos=vector(0,0,0), axis=(0,6,0), radius=0.75, color=color.white)
    wall = box(pos=vector(7.85,4,0), length=0.1, width=6, height=8, color=color.white)

#introduction prompts, required

    print "Please enter the desired velocity in the x direction if you want to play."
    vx = input()
    print "Please enter the desired velocity in the y direction if you want to play."
    vy = input()

    g = 9.8
    
    #assigning imput values
    dart.v=vector(vx,vy,0)
    
    dart.a=vector(0,g,0)
    
    #force of gravity
    Fg= vector(0,-dart.m*g,0)

    t = 0
    dt= 0.01
    trail=curve(color=color.blue)

    while (dart.pos.x < 7.23 and dart.pos.y >= 0.1):
        trail.append(dart.pos)
        rate(100)
        if dart.pos.y >= 0.1:
        #position update
            dart.pos += dart.v*dt
        #velocity update
            dart.v += dart.a*dt
        #air drag
            Fad = (-0.0013*mag(dart.v)**2)*(dart.v/mag(dart.v))
        #net force
            Fnet= Fg + Fad
        #acceleration update
            dart.a = Fnet/dart.m
        #increment time
            t += dt
            if abs(dart.pos.y - bullseye.pos.y) < 0.25 and dart.pos.x > 7.22:
                check = False

    #this means you missed
    if check == True:
        if dart.pos.y >= 0.1:
            print "You missed, try again."
        if dart.pos.y <= 0.1:
            print "You really suck ... your dart hit the floor."
            print "Give it another try."
        if dart.pos.y > 8:
            print "Watch out for the ceiling up there."
            print "How bout another throw?"

    #this means you got close enough to win
    if check == False:
        print "You won ... its only dart game dude chill out."
