WoodBossEnemy = class(Enemy, function(o, x, y, world, ...)
	pd:startList("fromOF")
	pd:addSymbol("mountain_boss_on")
	pd:addFloat(1)
	pd:finish("fromOF")			
	local arg = {...}
	if arg[1] == nil then
		options = {}
	else
		options = arg[1]
	end
	o.svg = SvgLoader(svg_root .. "boss/boss_saw_1.svg", true)
	o.mainSvg = o.svg
	o.drawType = 'svg'
	o.settingName = 'wood_boss_'
	o.stint = options.tint or {255, 255, 255}
	local size = o.svg:getMaxX()
	o.world = world
	Enemy.init(o,x, y,size,size)
	o.moves = true
	o.immovable = false
	o.saw = CenteredObject(0,0, 10, 10)
	o.saw.svg = SvgLoader(svg_root .. "boss/saw.svg", true)
	o.saw.drawType = 'svg'
	o.sawoff = Vec2(218, 110)
	o.sawoff:mult(r_scale*0.5)
	o:setColor(255, 255, 255, 255)
	o.rotationPoint = Vec2(60, 70)
	o.rotationPoint:mult(r_scale)
	o.sawoff:sub(o.rotationPoint)
	o.health = game_settings[o.settingName.."health"] or 80
	o.healthbar = o.world:add(BossHealthBar())
	o.healthbar:setValue(1)
	o.elasticity = .75
	o.aiState = 'toBuilding'
	o.y_speed = 1200
	o.x_speed = game_settings[o.settingName.."run_rate"] or 120
	o.y_speed = o.y_speed *r_scale / 2; o.x_speed = r_scale*o.x_speed/2;
	o.hitPower = game_settings[o.settingName.."hit_power"] or 10
	o:initialPosition()
	o.backupDistance = game_settings[o.settingName.."backup_distance"] or 120
	o.backupDistance = o.backupDistance*r_scale
	bludG.camera:shake(1.5)
end)

-- move the missile to a random distance from the center of the building
function WoodBossEnemy:initialPosition()
	local limits = self.world:getTowerLimits()
	limits.min = Vec2(limits.minX, limits.minY)
	limits.max = Vec2(limits.maxX, limits.maxY)
	self.pos.x=limits.min.x-self.w-60*r_scale
	self.pos.y=self.world.rootRoom:center().y-self.h*0.5
	-- start by running towards the building
	self.acceleration.x = self.x_speed
					pd:startList("fromOF")
					pd:addSymbol("mountain_boss_run")
					pd:addFloat(1)
					pd:finish("fromOF")
end

function WoodBossEnemy:draw()
	if self.exists then
		local rot = math.min(.25*math.pi, math.max(-.25*math.pi, self.velocity.x*0.002*r_scale))
		if self.alive then
			self.svg:resetTransform()
		end
		self.saw:setPosition(self.pos.x, self.pos.y)
		self.saw.pos:add(self.rotationPoint)
		local so = self.sawoff:copy()
		so:rotate(rot)
		self.saw.pos:add(so)
		-- move the saw to the correct position
		self.saw:draw()
		-- draw the main guy
		if self.alive then
			self.svg:rotateAround(rot, self.rotationPoint.x, self.rotationPoint.y)
		end
		Object.draw(self)
	end
end
function WoodBossEnemy:update()
	self.saw.rot = self.saw.rot + bludG.elapsed*3
	Enemy.update(self)
	self.world.rooms:overlap(self, nil, Object.separate)
	if self[self.aiState] then self[self.aiState](self) end
end
function WoodBossEnemy:toBuilding()
	-- check to see if we have hit the building yet... when we do, attack it
	if self.touching.other then
		for i,v in ipairs(self.touching.other) do
			if v:is_a(Room) then
				if self.alive then
					v:hit(self.hitPower)
				end
				self.aiState = 'awayBuilding'
				self.acceleration.x = -self.x_speed
					pd:startList("fromOF")
					pd:addSymbol("mountain_boss_run")
					pd:addFloat(1)
					pd:finish("fromOF")
			end
		end
	end
end
function WoodBossEnemy:kill()
	if not self.alive then return end
	-- self.svg = self.currentAnimation:getSprite()
	-- self.svg:resetTransform()
	-- if self.moveDirection == 'left' then
	-- 	self.pos.x = self.pos.x+self.w
	-- 	self.svg:scale(-1, 1)
	-- end

	self.svg:explode()
	self.saw.svg:explode()
	pd:startList("fromOF")
	pd:addSymbol("mountain_boss_kill")
	pd:addFloat(1)
	pd:finish("fromOF")
	self.alive = false
	self.killb2d = true
	Tweener:addTween(self.tint, {a=255}, {time=1, onComplete=function()
		Tweener:addTween(self.tint, {a=0}, {time=2.5, onComplete=function()
			self.exists = false
		end})
	end})
end
function WoodBossEnemy:awayBuilding()
	print('going away from building')
	-- check to see if we have hit the building yet... when we do, attack it
	local limits = self.world:getTowerLimits()
	limits.min = Vec2(limits.minX, limits.minY)
	limits.max = Vec2(limits.maxX, limits.maxY)
	if self.pos.x < limits.min.x - self.backupDistance then
		self.aiState = 'toBuilding'
		self.acceleration.x = self.x_speed
		pd:startList("fromOF")
		pd:addSymbol("mountain_boss_run")
		pd:addFloat(1)
		pd:finish("fromOF")
	end
end

-- mainState = WrapperState(Group());
-- mainState:changeState(TitleScreenState())
-- mainState.substate.playButton.onPress()
-- mainState.substate.playButton.onPress()
-- mainState.substate.playButton.onPress()

-- mainState.substate.enemies:addRecycle(WoodBossEnemy(0, bludG.camera.h/2, mainState.substate))