AlienEnemy = class(KidEnemy, function(o, x, y, world)
	KidEnemy.init(o, x, y, world, {runAnimation=alienRunAnimation, hitAnimation=alienHitAnimation, settingName='alien_'})
	o.aiMode = 'towardsBuilding'
	o.shotRate = o.hitRate
	o.shotCount = o.shotRate
end)
function AlienEnemy:handleCollision(other)
	if other:is_a(Room) then
		Object.separate(self, other)
	end
end
function AlienEnemy:update()
	if self.particles then self.particles:update(bludG.elapsed) end
	if Enemy.isFrozen(self) then return end
	self.sprite = self.currentAnimation:getSprite()
	self.acceleration.x = 0;
	self.hittingRoom = nil
	-- check the distances to the rooms.
	-- run a check to see if we are touching a room
	local touchingRoom = false
	self.hittingRoom = false
	if self.touching.other then
		for i,v in ipairs(self.touching.other) do
			if v:is_a(Room) then touchingRoom = v; break; end
		end
	end
	if self.aiMode == 'towardsBuilding' then
		self:towardsBuilding()
		-- check the distances
	end
	self:checkDistance()
end
function AlienEnemy:sync()
	if not Enemy.sync(self) then return end
	if self.alive and self.aiMode == 'shoot' and self.target and self.target.alive then
		self.shotCount = self.shotCount - 1
		if self.shotCount < 0 then
			self.shotCount = self.shotRate
			mainState.particles:addRecycle(AlienLightning(self, self.target))
			self.target:hit(self.hit_power)				
				pd:startList("fromOF")
				pd:addSymbol("alien_shoot")
				pd:addFloat(1)
				pd:finish("fromOF")
		end
	end
end
function AlienEnemy:checkDistance()
	self.target, distance = findNearest(self.world.rooms.members, self:center())
	if distance and distance < 120*r_scale then
		self.aiMode = 'shoot'
		self.currentAnimation = self.hitAnimation
	else
		self.aiMode = 'towardsBuilding'
	end
end
function AlienEnemy:towardsBuilding()
	if self.touching.DOWN then
		self.currentAnimation = self.runAnimation
		-- if we are on the ground, then we should move towards the nearest room
		if not self.nearestRoom or not self.nearestRoom.alive then
			self.nearestRoom = findNearest(self.world.rooms.members, self:center())
		end
		if self.nearestRoom then
			-- if the room is within a certain distance, then jump at it.
			if self.nearestRoom:center().x < self:center().x then
				self.flip = 1
				self.acceleration.x = -self.x_speed
			elseif self.nearestRoom:center().x > self:center().x then
				self.flip = 0
				self.acceleration.x = self.x_speed
			end
		end
	end
	Enemy.update(self)
	-- bang the kid off the groundplane, and the building, and the other enemies
	self.world.groundPlane:overlap(self, nil, Object.separate)
end