ENT.id = 64

if CLIENT

ENT.anims = {
	{ -- Idle
		{{0,0},{0,16},-1}
	},
	{ -- Looking
		{{16,0},{16,16},-1}
	},
	{ -- Jumping
		{{32,0},{32,16},-1}
	}
}

function ENT:think()
	self:gravity(0x50)
end

else -- SERVER

function ENT:init()
	self.grounded = true
end

function ENT:think()
	self:gravity(0x50)

	if self.target and (not self.target:goodTarget(self) or math.abs(self.x - self.target.x) > 7*16 or math.abs(self.y - self.target.y) > 7*16)
		-- Target moved out of range.
		self.target = nil
	end

	if not self.target
		for id,player in pairs(self.stage.players)
			if player:goodTarget(self) and math.abs(self.x - player.x) < 7*16 and math.abs(self.y - player.y) < 7*16
				self.target = player
				break
			end
		end
	end

	if self.grounded
		self.mx = 0
		if self.anim == 3
			self:set_anim(1)
			self.landed = self.life
			return
		end
		if self.anim == 1 and self.landed and self.landed+25 >= self.life
			return
		end
		if self.target
			if self.target.x < self.x
				self.flip = false
			else
				self.flip = true
			end
			if math.abs(self.x - self.target.x) < 5*16 and math.abs(self.y - self.target.y) < 5*16
				self:set_anim(3)
				if self.flip
					self.mx = 0.5
				else
					self.mx = -0.5
				end
				self.my = -3
			else
				self:set_anim(2)
			end
		end
	else
		if self.flip
			self.mx = 0.5
		else
			self.mx = -0.5
		end
	end
end

end
