import mwpy_gameobject
clock = mwpy_gameobject.clock

MWPYGameObject = mwpy_gameobject.MWPYGameObject
MWPYGameObjectType = mwpy_gameobject.MWPYGameObjectType
MWPYGameObjectState = mwpy_gameobject.MWPYGameObjectState


class MWPYWindLeft(MWPYGameObject):
	def __init__(self, gameObjectType = MWPYGameObjectType['MWGOT_WINDLEFT']):
		MWPYGameObject.__init__(self, gameObjectType)
		self.current_time = 0
		self.max_life_time = 10
		self.is_flash = False
		self.state = MWPYGameObjectState['AS_NONE']

	def can_render(self):
		return self.is_flash
	def can_update(self):
		return self.is_enable

	def do_update(self, delta, currenttime, world_dict):
		self.current_time += delta
		d = self.current_time
		if (d > self.max_life_time):
		      self.disable()
		      self.reset()
		elif (d / self.max_life_time > 0.7):
		      d = int(d * 10)
		      if ( (d % 2) == 0):
			      self.is_flash = True
		      else:
			      self.is_flash = False
		if(self.is_enable == True):
			actor_obj_type = MWPYGameObjectType['MWGOT_ACTOR']
			if(actor_obj_type in world_dict):
				actors = world_dict[actor_obj_type]
				for act in actors:
					if(act.is_enable == True):
						dx = act.x - self.x
						dy = act.y - self.y
						distsq = dx * dx + dy * dy + 1
						if(distsq > 1.5):
							distsq = 1.5
						frc = -25.0 / (distsq * distsq)
						act.frc_x = act.frc_x + frc






	def enable(self):
		self.is_enable = True
		self.is_flash = True
		self.current_time = 0

	def reset(self):
		self.mass = 1

