sorcery  Diff

Differences From Artifact [e1c11d0a7c]:

To Artifact [936cc31413]:


     1      1   sorcery.vfx = {}
     2      2   local L = sorcery.lib
            3  +
            4  +sorcery.vfx.particle = {
            5  +	flicker = { fw = 64 };
            6  +	crackle = { fw = 64 };
            7  +	sparking = { fw = 16 };
            8  +	spark = { fw = 16 };
            9  +	sputter = { fw = 16 };
           10  +	glitter = { fw = 16 };
           11  +	poof = { fw = 16 };
           12  +	fog = { fw = 16};
           13  +}
           14  +
           15  +sorcery.vfx.show = function(def)
           16  +	local sp = {}
           17  +	local p
           18  +	if def.kind then
           19  +		p = sorcery.vfx.particle[def.kind]
           20  +		local img = L.image(p.img or string.format('sorcery_%s.png', def.kind))
           21  +		if def.color then img = img:glow(def.color) end
           22  +		if def.warp then img = def:warp(img) end
           23  +		sp.texture = img:render()
           24  +	else
           25  +		sp.texture = def.texture
           26  +	end
           27  +
           28  +	sp.collisiondetection = def.collisiondetection
           29  +	sp.collision_removal  = def.collision_removal
           30  +	sp.object_collision = def.object_collision
           31  +
           32  +	local function q(bp, rp, ao, so)
           33  +		ao = ao or bp
           34  +		so = so or bp
           35  +		local min, max
           36  +
           37  +		if def[bp] or def[rp] then
           38  +			local b = def[bp] or vector.new(0,0,0)
           39  +			if def[rp] then
           40  +				local r
           41  +				if type(def[rp]) == 'number' then
           42  +					r = vector.new(def[rp],def[rp],def[rp])
           43  +				else r = def[rp] end
           44  +				min = vector.subtract(b, r)
           45  +				max = vector.add     (b, r)
           46  +			else
           47  +				min, max = b,b
           48  +			end
           49  +		else
           50  +			local dflt = vector.new(0,0,0)
           51  +			min, max = def['min'..bp] or dflt, def['max'..bp] or dflt
           52  +		end
           53  +
           54  +		if def.amount and def.amount > 1 then
           55  +			sp['min'..ao], sp['max'..ao] = min, max
           56  +		else
           57  +			if vector.equals(min,max) then sp[so] = min else
           58  +				local d = vector.subtract(max, min)
           59  +				sp[so]  = vector.add(min, vector.multiply(d, math.random()))
           60  +			end
           61  +		end
           62  +	end
           63  +	q('pos','radius')
           64  +	q('vel','velrange',   'vel', 'velocity')
           65  +	q('acc','accrange',   'acc', 'acceleration')
           66  +	local vary = def.varysize or 0
           67  +	if def.amount and def.amount > 1 then
           68  +		sp.amount = def.amount
           69  +		sp.time = def.time or def.life or 1
           70  +		def.life = def.life or sp.time
           71  +
           72  +		sp.minsize = def.minsize or ((def.size or 1) - vary)
           73  +		sp.maxsize = def.maxsize or ((def.size or 1) + vary)
           74  +		sp.attached = def.attached
           75  +	else
           76  +		if def.minsize and def.maxsize then
           77  +			sp.size = def.minsize + ((def.maxsize - def.minsize) * math.random())
           78  +		elseif vary > 0 then
           79  +			sp.size = ((def.size or 1) - vary) + (vary*2*math.random())
           80  +		else sp.size = def.size end
           81  +		if def.attached then
           82  +			sp.pos = vector.add(
           83  +				vector.rotate(sp.pos,
           84  +					{x = 0, y = def.attached:get_yaw() or def.attached:get_look_horizontal(), z = 0}
           85  +				),
           86  +				def.attached:get_pos()
           87  +			)
           88  +
           89  +			sp.velocity = vector.add(sp.velocity, def.attached:get_velocity())
           90  +		end
           91  +	end
           92  +	sp.node = def.node
           93  +	sp.playername = def.playername
           94  +	sp.vertical = def.vertical
           95  +	sp.glow = def.glow
           96  +	if def.life then
           97  +		if sp.amount then
           98  +			if def.varylife then
           99  +				sp.minexptime = def.life - def.varylife
          100  +				sp.maxexptime = def.life + def.varylife
          101  +			else
          102  +				sp.minexptime, sp.maxexptime = def.life, def.life
          103  +			end
          104  +		else
          105  +			sp.expirationtime = def.life
          106  +		end
          107  +	end
          108  +	if p and p.fw then
          109  +		sp.animation = {
          110  +			type = 'vertical_frames';
          111  +			aspect_w = p.fw, aspect_h = p.fh or p.fw;
          112  +			length = (sp.maxexptime or sp.life or 1) + 0.1;
          113  +		}
          114  +	end
          115  +	if sp.amount then
          116  +		minetest.add_particlespawner(sp)
          117  +	else
          118  +		minetest.add_particle(sp)
          119  +	end
          120  +end
     3    121   
     4    122   sorcery.vfx.glowspark = function(color)
     5    123   	local spark = L.image('sorcery_spark.png')
     6    124   	return spark:blit(spark:multiply(color))
     7    125   end
     8    126   
     9    127   sorcery.vfx.cast_sparkle = function(caster,color,strength,duration,pos)
    10    128   	local ofs = pos
    11    129   		and function(x) return vector.add(pos,x) end
    12    130   		or  function(x) return x end
    13    131   	local height = caster:get_properties().eye_height
    14         -	minetest.add_particlespawner {
    15         -		amount = 70 * strength;
    16         -		time = duration or 1.5;
          132  +	sorcery.vfx.show {
          133  +		amount = 4 * (0.5+strength*0.5), time = duration or 1.5;
          134  +		kind = 'spark', color = color, glow = 14, life = 0.5;
          135  +		-- minpos = ofs({ x =  0.0, z =  0.6, y =  height - 0.7});
          136  +		-- maxpos = ofs({ x =  0.4, z =  0.2, y =  height - 0.3});
          137  +		pos = ofs(vector.new(0.2, height - 0.5, 0.4)), radius = 0.2;
          138  +		vel = vector.new(0,0,0.8);
          139  +		velrange = 0.7, acc = vector.new(0,0.5,0);
          140  +		minsize = 5, maxsize = 10;
    17    141   		attached = caster;
    18         -		-- texture = L.image('sorcery_spark.png'):multiply(color):render();
    19         -		texture = sorcery.vfx.glowspark(color):render();
    20         -		minpos = ofs({ x =  0.0, z =  0.6, y =  height*0.7});
    21         -		maxpos = ofs({ x =  0.4, z =  0.2, y =  height*1.1});
    22         -		minvel = { x = -0.5, z = -0.5, y = -0.5};
    23         -		maxvel = { x =  0.5, z =  0.5, y =  0.5};
    24         -		minacc = { x =  0.0, z =  0.0, y =  0.5};
    25         -		maxacc = { x =  0.0, z =  0.0, y =  0.5};
    26         -		minsize = 0.4, maxsize = 0.8;
    27         -		minexptime = 1, maxexptime = 1;
    28         -		glow = 14;
    29         -		animation = {
    30         -			type = 'vertical_frames';
    31         -			aspect_w = 16;
    32         -			aspect_h = 16;
    33         -			length = 1.1;
    34         -		};
          142  +	}
          143  +	sorcery.vfx.show {
          144  +		amount = 140 * strength, time = 0.3 + (duration or 1.5);
          145  +		kind = 'sputter', color = color, glow = 14, life = 3;
          146  +		pos = ofs(vector.new(0.2, height - 0.5, 0.5)), radius = 0.3;
          147  +		vel = vector.new(0,0,1.2);
          148  +		velrange = 0.4, acc = vector.new(0,0.5,-0.7);
          149  +		minsize = 0.05, maxsize = 0.4;
          150  +		attached = caster;
    35    151   	}
          152  +	-- minetest.add_particlespawner {
          153  +	-- 	amount = 40 * strength;
          154  +	-- 	time = duration or 1.5;
          155  +	-- 	attached = caster;
          156  +	-- 	-- texture = L.image('sorcery_spark.png'):multiply(color):render();
          157  +	-- 	texture = sorcery.vfx.glowspark(color):render();
          158  +	-- 	minvel = { x = -0.5, z = -0.5, y = -0.5};
          159  +	-- 	maxvel = { x =  0.5, z =  0.5, y =  0.5};
          160  +	-- 	minacc = { x =  0.0, z =  0.0, y =  0.5};
          161  +	-- 	maxacc = { x =  0.0, z =  0.0, y =  0.5};
          162  +	-- 	minsize = 0.2, maxsize = 1.5;
          163  +	-- 	minexptime = 1, maxexptime = 1;
          164  +	-- 	glow = 14;
          165  +	-- 	animation = {
          166  +	-- 		type = 'vertical_frames';
          167  +	-- 		aspect_w = 16;
          168  +	-- 		aspect_h = 16;
          169  +	-- 		length = 1.1;
          170  +	-- 	};
          171  +	-- }
    36    172   end
    37    173   
    38    174   sorcery.vfx.body_sparkle = function(body,color,str,pos)
    39    175   	local tex = L.image('sorcery_spark.png')
    40    176   	local pi = tex:blit(tex:multiply(color)):render()
    41    177   	local ofs = pos
    42    178   		and function(x) return vector.add(pos,x) end