import pygame
import globals
import anim
import time

import Collision
import CollisionData

class Flipper:
	def __init__(self, position, length, orient, offset):
		self.position = position
		self.length = length
		self.orient = orient
		self.flipperimg = []
		self.firstframe = 1
		
		if self.orient == "l":
			self.coll = Collision.Collider()
			self.coll.AddLinesWithOffset(CollisionData.TableTwo[3], offset)
			self.flipperimg.append(pygame.image.load("../anims/leftflipper.png"))

		if self.orient == "r":
			self.coll = Collision.Collider()
			self.coll.AddLinesWithOffset(CollisionData.TableTwo[4], offset)
			self.flipperimg.append(pygame.image.load("../anims/rightflipper.png"))

		self.frame = anim.Interp(3, 20, 0)
		self.is_activated = False
		self.oldcount = -1

	def activate(self):
		if(self.is_activated == False): self.frame.Start()
		self.is_activated = True
	
	def deactivate(self):
		self.is_activated = False
		self.frame.Stop()
		self.frame.Reset()
		self.firstframe = 1

	def Update(self, ms):
		self.oldcount = self.frame.count
		self.frame.Update(ms)
		globals.UpdateRegions.append([self.position[0], self.position[1], 64, 50])

	def draw(self, ms):
		if(self.orient == "l"):
			globals.screen.blit(self.flipperimg[0], self.position, [self.frame.count * 64, 0, 64, 50])           
		if(self.orient == "r"):
			globals.screen.blit(self.flipperimg[0], self.position, [self.frame.count * 64, 0, 64, 50])            
