Mine = class(CenteredObject, function(o, x, y, parent, fuse_start, fuse_end, radius, power, ...)
	local arg = {...}
	if arg[1] == nil then
		options = {}
	else
		options = arg[1]
	end
	local scale = options.scale or 1
	local size = 60* r_scale * scale
	if r_scale == 4 then
		scale = scale*2
	end
	CenteredObject.init(o, x, y, size, size)
	o.scale = scale
	o.drawType = 'stretched'
	o.parent = parent
	o.svgClosed = sprites['tiles']['mine_closed_' .. player.currentWorld.id .. '.png']
	o.svgOpen = sprites['tiles']['mine_open_' .. player.currentWorld.id .. '.png']
	o.sprite = o.svgClosed
	o.h = o.sprite:getTexHeight()*scale
	o.w = o.sprite:getTexWidth()*scale
	o.alive = false
	o.moves = true
	o.openTime = fuse_start or 0.5
	o.maxWait = fuse_end or 5
	o.areaEffectRadius = radius or 150
	o.damageAmount = power or game_settings["mine_damage"]
	o.areaEffectRadius = o.areaEffectRadius * r_scale
	if box2d then
		o.b2d = BludBox2dRect(box2d, o.pos.x, o.pos.y, o.w/2, o.h/2, 0, 0.4, 0.4, true)
		o.b2d:setData(o)
	end
end)
function Mine:update()
	Object.update(self)
	if self.b2d then
		self.b2d:setPosition(self.pos.x, self.pos.y)
	end
	if self.sprite == self.svgClosed then
		self.openTime = self.openTime - bludG.elapsed
		if self.openTime <= 0 then
			self.alive = true
			self.sprite = self.svgOpen
			-- check to see if we have a list of enemies that we need to hit
			if self.enemiesOver then 
				self:kill()
			end
		end
	end
	if self.sprite == self.svgOpen and self.alive then
		self.maxWait = self.maxWait - bludG.elapsed
		if self.maxWait <= 0 then
			self:kill(true)
			pd:startList("fromOF")
			pd:addSymbol("mine_time_out")
			pd:addFloat(1.0)
			pd:finish("fromOF")
		end
	end
	self.velocity:mult(0.98)
end
function Mine:handleCollision(other)
	if (self.alive or self.sprite == self.svgClosed) and other:is_a(Enemy) then
		if self.sprite == self.svgOpen then
			self:kill()
		else
			print('adding to list')
			-- add the enemy to a list of enemies that we should hit if we open while we are still over
			if not self.enemiesOver then self.enemiesOver = Group() end
			self.enemiesOver:add(other)
		end
	end
end
function Mine:handleCollisionEnd(other)
	if self.sprite == self.svgClosed and other:is_a(Enemy) then
		print('removing from list')
		if not self.enemiesOver then self.enemiesOver = Group() end
		self.enemiesOver:remove(other)
	end
end
function Mine:kill(harmless)
	if not self.alive then return nil end
	self.alive = false
	Object.kill(self)
	if harmless then
		mainState.particles:addRecycle(Explosion(self.pos.x, self.pos.y, 0.3))
	elseif self.parent then
		pd:startList("fromOF")
		pd:addSymbol("mine_hit_enemy")
		pd:addFloat(1.0)
		pd:finish("fromOF")
		mainState.particles:addRecycle(Explosion(self.pos.x, self.pos.y))
		-- check for enemies within the kill radius and hit them if they exist
		-- first convert to a rectangle, then check for overlaps
		self.pos.x = self.pos.x
		self.pos.y = self.pos.y
		self.w, self.h = self.areaEffectRadius, self.areaEffectRadius
		self.parent.enemies:overlap(self, function(a, b)
			if a.hit then
				a:hit(self.damageAmount, self.damageType)
			else
				a:kill(true)
			end
		end)
	end
end
function Mine:draw()
	CenteredObject.draw(self)
	-- Object.draw(self)
end

MiniMine = class(Mine, function(o, x, y, parent, fuse_start, fuse_end, radius, power)
	Mine.init(o, x, y, parent, fuse_start, fuse_end, radius, power, {scale=game_settings["mini_mine_scale"] or 0.5})
end)