import mwpy_gameobject

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


import time
clock = time.clock

class MWPYBridge(MWPYGameObject):
	def __init__(self, gameObjectType = MWPYGameObjectType['MWGOT_BRIDGE']):
		MWPYGameObject.__init__(self, gameObjectType)
		self.state = State['AS_DOWN']
		#specific data
		self.is_flash = False
		self.max_life_time = 0
		self.contact_actor_time = 0
		self.current_time = 0#clock()

	def reset(self):
		self.state = State['AS_DOWN']
		gravity_action = True
		self.is_flash = False
		self.is_enable = False
		self.mass = 1

	def enable(self):
		self.is_enable = True
		self.is_flash = True
		self.current_time = 0#clock()
		self.mass = 1
		self.state = State['AS_DOWN']
		self.gravity_action = True

	def do_update(self, delta, currenttime, world_dict):
		#currenttime = clock()
		self.current_time += delta
		self.is_flash = True
		if self.state == State['AS_NONE'] or self.state == State['AS_PLAY']:
			self.vel_x = 0
			self.vel_y = 0
			self.mass = 0
		if self.state == State['AS_PLAY']:
			if (self.current_time - self.contact_actor_time) > 1:
				self.state = State['AS_NONE']
		d = self.current_time
		if d > self.max_life_time:
			self.reset()
		elif (d / self.max_life_time) > 0.7:
			d = int(d * 10)
			if (d % 2) == 0:
				self.is_flash = False
			else:
				self.is_flash = True

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





