##################################
#offroadwarrior
#ball
#collision point and mass
##################################

#dependency
##################################
import math

#container
##################################
class ball:
        def __init__(self,x,y,mass=10):
                self.x = x
                self.y = y
                self.mass = mass
                self.vx = 0
                self.vy = 0
                self.fx = 0
                self.fy = 0

#container
##################################
def terminal_velocity(a):
        #limiter of velocity, no greater than 1000.0
        if a.vx < -2000.0:
                a.vx = -2000.0
        if a.vx > 2000.0:
                a.vx = 2000.0
                
        if a.vy < -2000.0:
                a.vy = -2000.0
                
        if a.vy > 2000:
                a.vy = 2000.0
                print("tvy+")
        
def terminal_force(a):
        #limiter of force, no greater than 200000.0
        if a.fx < -500000.0:
                a.fx = -500000.0
                
        if a.fx > 500000.0:
                a.fx = 500000.0
                
        if a.fy < -500000.0:
                a.fy = -500000.0
               
        if a.fy > 500000.0:
                a.fy = 500000.0
                print("tfy+")

def viscous_drag(a):
        #application of air resistance (smoothing)
        a.vx *= 0.9981
        a.vy *= 0.9981

def move(a):
        #application of forces to mass, giving change in velocity:
        #       velocity_change = (forces / mass) * deltaTIME   
        a.vx += (a.fx / a.mass) * .005         #dT = system scale (1 to 0.001)
        a.vy += (a.fy / a.mass) * .005
        
        #application of velocity to time, giving change in position:
        #       position_change = velocity * delaTIME.
        a.x += a.vx * .005                      #dT = system scale  (1 to 0.001)
        a.y += a.vy * .005

def gravity(a):
        #application of gravity forces
        a.fy += a.fy + (1800 * a.mass)    #gravity = 8000-100

def reset_force(a):
        #reset of cumulative force value for next frame
        a.fx = 0
        a.fy = 0

def wall(b,w,h):
        if b.x < 0:
                b.x = 1
                b.vx = -b.vx * 0.518
                b.vy = b.vy * 0.518
        if b.x > w:
                b.x = w-1
                b.vx = -b.vx * 0.518
                b.vy = b.vy * 0.518
        if b.y < 0:
                b.y = 1
                b.vy = -b.vy * 0.518
                b.vx = b.vx * 0.518
        if b.y > h:
                b.y = h-1
                b.vy = -b.vy * 0.518
                b.vx = b.vx * 0.518
