CloudEnemy = class(Enemy, function(o, x, y, world, ...)
	local arg = {...}
	if arg[1] == nil then
		options = {}
	else
		options = arg[1]
	end
	local animation = options.animation or cloudAnimation
	local attackAnimation = options.attackAnimation or cloudAttackAnimation
	o.settingName = options.settingName or 'cloud_'
	o.shootTime = options.shootTime or .369
	o.shootEnemy = options.shootEnemy or LightningEnemy
	o.stint = options.tint or {255, 255, 255}
	local size = 100*r_scale/2
	local ow = options.w or size
	local oh = options.h or size
	
	Enemy.init(o,x,y,ow,oh)
	
	if not animation[1].getTexWidth then
		for i,v in ipairs(animation) do
			animation[i] = sprites['enemies'][v]
		end
	end

	if not attackAnimation[1].getTexWidth then
		for i,v in ipairs(attackAnimation) do
			attackAnimation[i] = sprites['enemies'][v]
		end
	end

	o.drawType = 'stretched'
	
	o.idleAnimation = AnimationModel(animation)
	o.currentAnimation = o.idleAnimation
	o.shootAnimation = AnimationModel(attackAnimation, {rate=41, loop=false, endCallback=function()
		o.currentAnimation = o.idleAnimation
	end})
	o:setColor(o.stint[1], o.stint[2], o.stint[3])

	o.world = world
	o:initialPosition()
	o.moveCount = 0
	o.moves = true;
	o.drag = Vec2(10,0)
	o.acceleration.y = 20
	o.dirChange = math.random(2, 8)*2
	o.timeWaits = Group()
	o.shootRate = game_settings[o.settingName.."shoot_rate"] or game_settings["cloud_shoot_rate"]
	o.shootCount = o.shootRate
	o.health = game_settings[o.settingName.."health"] or game_settings["cloud_health"]
	o.sheet = sheets['enemies']
	o.entity:setSheet(o.sheet)

end)
function CloudEnemy:sync()
	if not Enemy.sync(self) then return end
	local moveSpeed = 40
	self.moveCount = self.moveCount+1
	local limits = self.world:getTowerLimits()
	if self.moveCount%self.dirChange == 0 then
		if self.pos.y > limits.minY then
			self.velocity.y = -moveSpeed;
		end
	end
	if self.shootCount > 0 then
		self.shootCount = self.shootCount - 1
	else
		self.shootCount = self.shootRate
		-- shoot a lightning!
		self.shootAnimation:startAnimation()
		self.currentAnimation = self.shootAnimation
		-- wait for a little bit before shooting
		self.timeWaits:addRecycle(TimeWait(function()
			local l = self.world.enemyBullets:addRecycle(self.shootEnemy(self.pos.x, self.pos.y, self.world))
			if self.flip == 1 then
				l.velocity.x = -100
			else
				l.velocity.x = 100
			end
			-- measure the distance from the center of the hotel, and apply gravity based on that
			l.velocity = l:center()
			l.velocity:sub(self.world.rootRoom:center())
			l.velocity:normalize()
			l.velocity.x = l.velocity.x*2
			l.velocity:mult(-80*r_scale)
			pd:startList("fromOF")
			pd:addSymbol("lightning_shoot")
			pd:addFloat(1)
			pd:finish("fromOF")
		end, self.shootTime))
	end
end
function CloudEnemy:initialPosition()
	local limits = self.world:getTowerLimits()
	limits.min = Vec2(limits.minX, limits.minY)
	limits.max = Vec2(limits.maxX, limits.maxY)
	if math.random() < 0.5 then
		self.pos.x, self.pos.y=limits.min.x-math.random(100, 200),math.random(limits.min.y, limits.max.y)
	else
		self.pos.x, self.pos.y=limits.max.x+math.random(100, 200),math.random(limits.min.y, limits.max.y)
		self.flip = 1
	end
end
function CloudEnemy:kill()
	mainState.particles:addRecycle(ParticleHandler(self:center().x, self:center().y, "particle_data_cloudExplosion.lua", sprites['tiles']['circle.png'], {preroll=.25, lifetime=0.1, cooldown=2}))
	pd:startList("fromOF")
	pd:addSymbol("cloud_kill")
	pd:addFloat(1)
	pd:finish("fromOF")
	Object.kill(self)
end
function CloudEnemy:update( ... )
	if Enemy.isFrozen(self) then return end
	self.sprite = self.currentAnimation:getSprite()
	Enemy.update(self)
	self.timeWaits:update()
	self.world.groundPlane:overlap(self, cloudBounce)
	self:overlap(self.world.rooms, cloudBounce)
	-- should check if we are within a certain distance of the building and push away if so
end
function cloudBounce(b, self)
	self.velocity.y = -self.velocity.y
	self.pos.y = b.pos.y - self.h
end
function CloudEnemy:draw()
	if self.alive and self.sprite then
		if not self.o_w then self.o_w = self.w; self.o_h = self.h end
		self.w = (self.o_w/self.sprite:getWidth())*self.sprite:getTexWidth()
		self.h = (self.o_h/self.sprite:getHeight())*self.sprite:getTexHeight()
		Object.draw(self)
		self.w, self.h = self.o_w, self.o_h
	end
end
-- function WaveController:addEnemyOffscreen()
-- 	self.enemies:add(CloudEnemy(0, bludG.camera.h/2, self.parent))
-- end

-- mainState = WrapperState(Group());
-- ps = LevelSelectState()
-- mainState:changeState(ps)
-- -- press the button on the level selector
-- ps.buttons.members[1].onPress()

