GullEnemy = 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 gulAnimation
	if not animation[1].getTexWidth then
		for i,v in ipairs(animation) do
			animation[i] = sprites['enemies'][v]
		end
	end
	local sizeScale = options.sizeScale or 0.75
	local sizex = animation[1]:getWidth()
	local sizey = animation[1]:getHeight()
	o.noFeathers = options.noFeathers or false
	o.settingName = options.settingName or 'gull_'
	o.stint = options.tint or {255, 255, 255}
	if retina then
		sizex = math.floor(sizex * r_scale/2 * sizeScale)
		sizey = math.floor(sizey * r_scale/2 * sizeScale)
	else
		sizex = math.floor(sizex * r_scale * sizeScale)
		sizey = math.floor(sizey * r_scale * sizeScale)
	end	
	Enemy.init(o,x,y,sizex,sizey)
	-- o.drawType = 'stretched'
	o.animation = AnimationModel(animation, {rate=options.rate or 80})

	o.sprite = sprites['tiles']['white.png']
	o.drawType = 'stretched'
	o:setColor(o.stint[1], o.stint[2], o.stint[3])
	o.world = world
	o.entity = BHEntity()
	GullEnemy.initialPosition(o)
	o.health = game_settings[o.settingName.."health"] or game_settings["gull_health"]
	
	o.particles = ParticleSystem(sprites['tiles']['circle.png'], sheets['tiles'], 60)
	o.particles:setPosition(bludG.camera.w/2, bludG.camera.h/2)
	o.particles:setEmissionRate(20)
	o.particles:setStartColor(255, 120, 40, 60)
	o.particles:setEndColor(255, 255, 255, 0)
	o.particles:setParticleLife(2, 3)
	o.particles:setSpeed(10, 30)
	o.particles:setDirection(math.rad(270))
	o.particles:setSpread(5)
	o.particles:setRotation(math.rad(39), math.rad(82))
	o.particles:setSize(0.01*r_scale*0.5, 0.3*r_scale*0.5, 0*r_scale*0.5)
	o.particles:setSpin(1, 2, 1)
	o.particles:setTangentialAcceleration(0)
	o.particles:start()

	o.moves = true
	o.sheet = sheets['enemies']
	o.particleOffsetPosition = Vec2(23, 73)
	o.particleOffsetPosition:mult(r_scale*0.5)
end)

-- move the missile to a random distance from the center of the building
function GullEnemy:initialPosition()
	self.canHit = false
	-- find the building center
	local rootCenter = self.world.rootRoom:center()
	local limits = self.world:getTowerLimits()
	limits.min = Vec2(limits.minX, limits.minY)
	limits.max = Vec2(limits.maxX, limits.maxY)
	local maxSize = limits.min:distance(limits.max)
	self.pos.x, self.pos.y=1,0
	self.pos:normalize()
	local rAmt = math.random()*180+180
	self.pos:rotate(math.rad(rAmt))
	self.pos:mult(maxSize*2)
	self.pos:add(rootCenter)
	self.velocity = rootCenter
	self.velocity:sub(self.pos)
	self.velocity:normalize()
	local angle = self.velocity:angle()
	self.velocity:mult(game_settings[self.settingName.."speed"] or game_settings["gull_speed"])
	-- because atan is counter clockwise, reverse it
	self.flip = 0
	if angle < 0 then
		self.flip = 1
	end
	self.velocity:mult(r_scale*0.5)
	self.b2d:setPosition(self.pos.x+self.w/2, self.pos.y+self.h/2)
end
function GullEnemy:draw()
	self.particles:draw(bludG.camera.scroll.x, bludG.camera.scroll.y, bludG.camera.scale)
	-- Object.drawDebug(self)
	if self.alive then
		if not self.o_w then self.o_w = self.w; self.o_h = self.h end
		local opx, opy = self.pos.x, self.pos.y
		-- Object.drawDebug(self)
		self.pos.x = self.pos.x+self.sprite:getSpriteX()
		self.pos.y = self.pos.y+self.sprite:getSpriteY()
		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.pos.x, self.pos.y = opx, opy
		self.w, self.h = self.o_w, self.o_h
	end
end

function GullEnemy:kill(bulletKill)
	if self.alive then
		self.killb2d = true
		self.alive = false
		self.moves = false
		self.particleTween = {}
		self.particles:stop()
		local c = self:center()
		local cx, cy = c.x, c.y
		if bulletKill then
			pd:startList("fromOF")
			pd:addSymbol("gull_bullet_kill")
			pd:addFloat(1)
			pd:finish("fromOF")
			mainState.particles:addRecycle(Explosion(cx, cy, 0.3))
		else
			pd:startList("fromOF")
			pd:addSymbol("gull_hit_building")
			pd:addFloat(1)
			pd:finish("fromOF")
			mainState.particles:addRecycle(Explosion(cx, cy))
		end
		if not self.noFeathers then
			mainState.particles:addRecycle(ParticleHandler(cx, cy, "particle_data_feathers_start.lua", sprites['tiles']['feather_1.png'], {preroll=.25, lifetime=.1, cooldown=2}))
			mainState.particles:addRecycle(ParticleHandler(cx, cy, "particle_data_feathers_start.lua", sprites['tiles']['feather_2.png'], {preroll=.25, lifetime=.1, cooldown=2}))
		end
		mainState.particles:addRecycle(DeathSpin(cx, cy, self.sprite, self.tint, self.sheet, self.flip)) 
		-- 		
		self.deathTween = Tweener:addTween(self.particleTween, {}, {onComplete=function()
			self.exists = false
		end})
	end
end
function GullEnemy:update()
	self.particles:update(bludG.elapsed)
	if Enemy.isFrozen(self) then return end
	Enemy.update(self)
	if self.alive then
		self.sprite = self.animation:getSprite()
		if self.flip == 0 then
			self.particles:setPosition(self.pos.x+self.particleOffsetPosition.x, self.pos.y+self.particleOffsetPosition.y)
		else
			self.particles:setPosition(self.pos.x+self.w-self.particleOffsetPosition.x, self.pos.y+self.particleOffsetPosition.y)
		end
	end
	self.canHit = true
end
function GullEnemy:handleCollision(other)
	if other:is_a(Room) and self.canHit then
		if self.alive then
			pd:startList("fromOF")
			pd:addSymbol("enemyHit")
			pd:addSymbol("GullEnemy") -- enemy type
			pd:finish("fromOF")
			other:hit(game_settings[self.settingName..'damage'] or game_settings["gull_damage"])
			self:kill()
		end
	end
end