var gravity = 9.8;
var framerate = 30;

function world(){
	this.statObj = new Array();
	this.dynObj = new Array();
	
	this.addStatic = addStatic;
	this.addDynamic = addDynamic;
}

//Internal functions attached to the world object.
	//Used for adding static objects to the world
	function addStatic(staticObject){
		this.statObj[this.statObj.length] = staticObject;
	}
		
	//Used for adding a new dynamic object to the world.
	function addDynamic(dynamicObject){
		this.dynObj[this.dynObj.length] = dynamicObject;
	}

//A circular object
function ball(x, y, width, mass, colour){
	this.x = x;
	this.y = y;
	this.radius = width;
	this.mass = mass;
	this.velocity = new velocity();
	this.type = "circle";
	this.colour = colour;
	
	//this.accelerate = accelerate;
	//this.force = force;
	this.applyAcceleration = applyAcceleration;
	this.applyForce = applyForce;
}

function rectangle(x, y, width, height, mass, colour){
	this.x = x;
	this.y = y;
	this.width = width;
	this.height = height;
	this.mass = mass;
	this.velocity = new velocity();
	this.type = "rect";
	this.colour = colour;
		
	//this.accelerate = accelerate;
	//this.force = force;
	this.applyAcceleration = applyAcceleration;
	this.applyForce = applyForce;
}

//internal functions for dynamic objects
	function applyAcceleration(x, y){
		this.velocity.x += x;
		this.velocity.y += y;
	}
	
	
	function applyForce(x, y){
		this.velocity.x += x / this.mass;
		this.velocity.y += y / this.mass;
	}
	
	//velocity object used by the dynamic objects
	function velocity(){
		this.x = 0;
		this.y = 0;
	}
	
	function boundBox(top, bottom, left, right){
		this.top = top;
		this.bottom = bottom;
		this.left = left;
		this.right = right;
	}

//external function to apply gravity to the world.
function worldGravity(curWorld){
	var tmpframe = 1 / framerate;
	for (var i = 0; i < curWorld.dynObj.length; i++){
		curWorld.dynObj[i].velocity.y -= gravity * tmpframe;
	}
}

//external function which moves objects in the world according to their velocity.
function worldMoveObjects(curWorld){
	var tmpframe = 1 / framerate;
	for (var i = 0; i < curWorld.dynObj.length; i++){
		curWorld.dynObj[i].x += curWorld.dynObj[i].velocity.x * tmpframe;
		curWorld.dynObj[i].y += curWorld.dynObj[i].velocity.y * tmpframe;
	}
}

function worldCollision(curWorld){
	for (var i = 0; i < curWorld.dynObj.length; i++){
		
	}
}
