AttackBot = {hit = 0}
AttackBot.__index = AttackBot

function AttackBot.LoadAssets(me)
	LoadModel(me,"Guardian","Animated")
end

function AttackBot:Create(me)
	SetHealth(me,8)
	--SetHealth(me,20)	
	SetPower(me,2)
	--ChangeAnimation(me,"Stand")
	--self.Update = Instance.CustomUpdate
	SetState(me,0)
	--playerDirection = GetPlayerDirection(me)
	
end

function AttackBot:FinishAnimAttack(me)
	ChangeAnimation(me,"Attack2")
	
end

function AttackBot:Update(me)
	if ( GetLifetime(me) == 0)
	then
		SetVelocity(me,7*GetDirection(me),0)
		ChangeAnimation(me,"Attack")
		TargetPlayer(me)
	end
	
	--Returning from against the wall
	if(self.hit == 1)
	then
		SetDirection(me, DirectionToPlayer(me))
		SetVelocity(me,7*GetDirection(me),0)
		ChangeAnimation(me,"Attack")
		TargetPlayer(me)
	end

	if(self.hit > 0 )
	then
		self.hit = self.hit - 1
		
	end
end

function AttackBot:Collide(me, you)
	power = GetPower(you)
	TakeDamage(me, power)

	if power > 0
	then
		self.hit = 24
		Stop(me)
		ChangeAnimation(me,"Stand")

	elseif self.hit == 0
	then
		Smash(you,24*GetDirection(me),-8)
		self.hit = 20
		Stop(me)
	end
end


function AttackBot:CollideWorld(me)
	ShakeScreen(8)
	TakeDamage(me, 2);
	SetVelocity(me,0,0)
	PlaySoundEffect(1)
	self.hit = 120
	ChangeAnimation(me,"Stand")
end

function AttackBot:CollideWall(me)
	ShakeScreen(8)
	TakeDamage(me, 2);
	--SetVelocity(me,0,0)
	PlaySoundEffect(1)
	self.hit = 120
	ChangeAnimation(me,"Stand")
	SetState(me,0)
end

function AttackBot:Death(me)
	x,y = GetPosition(me)
	y = y - 32
	CreateEmitter("Explosion", x,y)
end