import random
from constants import *
from settings import *

class Physics:
	def __init__(self):
		self.gravity = random.randint(2,20)
		self.gravity_orientation = random.choice([0,0,0,0,0,1,2,3])
		self.watercolor = random.randint(0, 7)
		self.skycolor = random.randint(0, 7)
		self.maximumVelocity = random.randint(5, 20)
		self.windVelocity = 0#random.randint(0,9)
		self.windDirection = random.randint(0,3)
		self.light = random.randint(-settings_mapgen['xsize'],  settings_mapgen['xsize'])
		#self.movementSpeed = random.randint(1,3)
		# for debug:
		self.movementSpeed = 5

		print "".join(["[01;3%sm%s[00m" % (i % 7, j) for i,j in enumerate("Forever Keen")])
		print "Gravity:", self.gravity
		print "Gravity orientation:", self.gravity_orientation
		print "Watercolor: [01;3%sm%s[00m" % (self.watercolor, self.watercolor)
		print "Skycolor: [01;3%sm%s[00m" % (self.skycolor, self.skycolor)
		print "Maximum Velocity:", self.maximumVelocity
		print "Movement Speed:", self.movementSpeed
		print "Wind Velocity:", self.windVelocity
		print "Wind Direction:", self.windDirection
		print "Light:", self.light

	def getGravity(self,t,newx,newy):
		if self.gravity_orientation == ORIENTATION_DOWN:
			newy += (self.gravity * t**2) / 2
		elif self.gravity_orientation == ORIENTATION_UP:
			newy -= (self.gravity * t**2) / 2
		elif self.gravity_orientation == ORIENTATION_LEFT:
			newx -= (self.gravity * t**2) / 2
		elif self.gravity_orientation == ORIENTATION_RIGHT:
			newx += (self.gravity * t**2) / 2
		return newx,newy

	def getWindEffect(self,newx,newy):
		if self.windDirection == ORIENTATION_DOWN:
			newy += self.windVelocity
		elif self.windDirection == ORIENTATION_UP:
			newy -= self.windVelocity
		elif self.windDirection == ORIENTATION_LEFT:
			newx -= self.windVelocity
		elif self.gravity_orientation == ORIENTATION_RIGHT:
			newx += self.windVelocity
		return newx,newy

	"""
	def jump(self, obj):
		if self.gravity_orientation == ORIENTATION_DOWN:
			obj.velocity.y = -5
		elif self.gravity_orientation == ORIENTATION_UP:
			obj.velocity.y = 5
		elif self.gravity_orientation == ORIENTATION_LEFT:
			obj.velocity.x = 5
		elif self.gravity_orientation == ORIENTATION_RIGHT:
			obj.velocity.x = -5
	"""
