'''
Anna Petrone
Prativa Kharel
Rec1
Final Assignment
'''

#The object of the game is to roll the ball up a gentle incline at the right speed so that it can make it over a final "jump" and into one of the scoring rings. The bottom ring is 20 points, the next is 40 and the highest is 50. The player gets 9 balls to throw and recieves a final score that is the total of their scores from every roll.



print 'Welcome to Super Skee-Ball!'

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


ramp=box(pos=(0,0,-9),size=(10, 0.2, 18), up=vector(0,8.,1.))

bottom=box(pos=(0,-1,-9), size=(ramp.length,ramp.height,17.86))
back=box(pos=(0,0,-18), up=(0,0,1), width=2*ramp.up.z, height=ramp.height, length=ramp.length)
side1 = box(pos=(-ramp.length/2, 0.5, ramp.pos.z), size=(ramp.height, 3, ramp.width))
side2 = box(pos=(ramp.length/2, 0.5, ramp.pos.z), size=(ramp.height, 3, ramp.width))

jump = box(pos=(0,2.24,-17.86), size=(ramp.length, 3, ramp.height), up=(0,-4,1))

score = 0
scoreboard=box(pos=(12, 15, 0), size=(6, 2, 0.2), color=color.cyan)
scorelabel=label(pos=scoreboard.pos, text= str(score), color=(0,0,0), box=0, opacity=0)
ball=[]
nballs = 9
turn = nballs
rings=[]
nrings = 3


for i in range(nrings):
    rings.append(ring(pos=(0, 7+2*i,-20 ), axis=(0,0.05,0.25 ) , radius = (1), thickness=(0.08)))

rings[0].value=20
rings[0].color=color.yellow
rings[1].value=40
rings[1].color=color.magenta
rings[2].value=50
rings[2].color=color.cyan



hundreda = ring(pos=(-3, 11, -20), axis=(0, 0.05, 0.25), radius= 0.8, value=100, color=color.red)
hundredb = ring(pos=(-hundreda.pos.x, hundreda.pos.y, hundreda.pos.z), axis=(0, 0.05, 0.25), radius= 0.8, value=100, color=color.red)


decoration=ring(pos=rings[1].pos, radius=5, axis=(0,0,1), thickness=(0.08))

for i in range(nballs):
    ball.append( sphere(radius=0.5, m=1))
    ball[i].pos=(10, i, 0)


'''
The Game:
'''

for b in range(turn):
    t=0

    print 'enter x pos (hint, between -5 and 5)'
    x = input()

    print 'enter speed (m/s)'
    v = input()
    v0 = vector(0, v*0.124, -v*0.992)
    
    m=1
    g=9.8
    dt= 0.001
    Fg1 = vector(0, -g*0.124, g*0.922)
    a1 = Fg1/m
    
    trail = curve(color=color.yellow)

    ball[b].pos = (x, -0.8, 0)

    while (ball[b].pos.z > (jump.pos.z+1.0)):
        rate(50)
        v0 += a1*t
        ball[b].pos += v0*t
        t += dt
        trail.append(ball[b].pos)
        if ball[b].pos.y <= -1:
            print 'try harder!'
            break
        Fg2 = vector(0, -g*0.97, g*0.24) 
        a2 = Fg2/m

    v0 = mag(v0)
    v1 = vector(0, v0*0.97, -v0*0.24)
    
    while (ball[b].pos.z > (jump.pos.z-1.0)):
        rate(50)
        v1 += a2*t
        ball[b].pos += v1*t
        trail.append(ball[b].pos)
        t += dt
        if (ball[b].pos.y >= (jump.pos.y+1)):
            break
    
        Fg3 = vector(0, -ball[b].m*g, 0)
        a3 = Fg3/m
        v1 = v1
    score_yet= False
    while (ball[b].pos.y >= (jump.pos.y+1)):
        rate(75)
        v1 += a3*t
        ball[b].pos += v1*t
        trail.append(ball[b].pos)
        t += dt
        if (abs(ball[b].pos - hundreda.pos) <= 0.4 or abs(ball[b].pos - hundredb.pos) <= 0.4  and score_yet == False):
            print 'score!'
            score += hundreda.value
            scorelabel.text=str(score)
            score_yet = True
            break 
            
        for i in range(nrings):
            if (abs(ball[b].pos - rings[i].pos) <= 0.4 and score_yet == False):
                print 'score!'
                score += rings[i].value
                scorelabel.text=str(score)
                score_yet = True
                break 
