From e7a90971fe41dc60363a3ec7999195cfb98aaa78 Mon Sep 17 00:00:00 2001 From: adrido Date: Sun, 1 Dec 2013 06:24:17 +0100 Subject: [PATCH] added particles \n \n thanks to Hybrid Dog \n particles spawn now if the cannon is firing and if the cannonball hits a node. --- cannonballs.lua | 9 +++++++-- functions.lua | 27 +++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/cannonballs.lua b/cannonballs.lua index 1d06ce9..606d499 100644 --- a/cannonballs.lua +++ b/cannonballs.lua @@ -30,6 +30,7 @@ local exploding={ self.object:remove() end, on_node_hit = function(self,pos,node) + cannons.nodehitparticles(pos,minetest.registered_nodes[node.name].tiles[1]) cannons.destroy({x=pos.x, y=pos.y, z=pos.z},self.range) minetest.sound_play("cannons_shot", {pos = pos, gain = 1.0, max_hear_distance = 32,}) @@ -65,6 +66,7 @@ local fire={ self.object:remove() end, on_node_hit = function(self,pos,node) + cannons.nodehitparticles(pos,minetest.registered_nodes[node.name].tiles[1]) pos = self.lastpos minetest.env:set_node({x=pos.x, y=pos.y, z=pos.z},{name="fire:basic_flame"}) minetest.sound_play("default_break_glass", @@ -78,7 +80,7 @@ if cannons.enable_fire then end --++++++++++++++++++++++++++++++++++++ ---+ Stone Cannon ball + +--+ Wooden Cannon ball + --++++++++++++++++++++++++++++++++++++ @@ -110,6 +112,7 @@ local ball_wood={ self.object:remove() end, on_node_hit = function(self,pos,node) + cannons.nodehitparticles(pos,minetest.registered_nodes[node.name].tiles[1]) if node.name == "default:dirt_with_grass" then minetest.env:set_node({x=pos.x, y=pos.y, z=pos.z},{name="default:dirt"}) minetest.sound_play("cannons_hit", @@ -162,6 +165,7 @@ local ball_stone={ self.object:remove() end, on_node_hit = function(self,pos,node) + cannons.nodehitparticles(pos,minetest.registered_nodes[node.name].tiles[1]) if node.name == "default:dirt_with_grass" then minetest.env:set_node({x=pos.x, y=pos.y, z=pos.z},{name="default:dirt"}) minetest.sound_play("cannons_hit", @@ -214,6 +218,7 @@ local ball_steel={ self.object:remove() end, on_node_hit = function(self,pos,node) + cannons.nodehitparticles(pos,minetest.registered_nodes[node.name].tiles[1]) if node.name == "default:dirt_with_grass" then minetest.env:set_node({x=pos.x, y=pos.y, z=pos.z},{name="default:dirt"}) minetest.sound_play("cannons_hit", @@ -231,4 +236,4 @@ local ball_steel={ end, } -cannons.register_muni("cannons:ball_steel",ball_steel) \ No newline at end of file +cannons.register_muni("cannons:ball_steel",ball_steel) diff --git a/functions.lua b/functions.lua index 6e466ed..42b6e4a 100644 --- a/functions.lua +++ b/functions.lua @@ -123,6 +123,24 @@ cannons.stand_nodebox = { function cannons.meseconsfire(pos,node) cannons.fire(pos,node) end +function cannons.nodehitparticles(pos,texture) + minetest.add_particlespawner( + 30, --amount + 0.5, --time + {x=pos.x-0.3, y=pos.y+0.3, z=pos.z-0.3}, --minpos + {x=pos.x+0.3, y=pos.y+0.5, z=pos.z+0.3}, --maxpos + {x=0, y=2, z=0}, --minvel + {x=0, y=3, z=0}, --maxvel + {x=-4,y=-4,z=-4}, --minacc + {x=4,y=-4,z=4}, --maxacc + 0.1, --minexptime + 1, --maxexptime + 1, --minsize + 3, --maxsize + false, --collisiondetection + texture --texture + ) +end function cannons.fire(pos,node,puncher) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() @@ -137,14 +155,12 @@ function cannons.fire(pos,node,puncher) if puncher ~= nil then dir=puncher:get_look_dir() meta:set_string("dir", minetest.serialize(dir)) - pr(dir) else dir = {} dir = minetest.deserialize(meta:get_string("dir")); if dir == nil then return end - pr(dir) end minetest.sound_play("cannons_shot", {pos = pos, gain = 1.0, max_hear_distance = 32,}) @@ -159,6 +175,13 @@ function cannons.fire(pos,node,puncher) local obj=minetest.env:add_entity(pos, cannons.get_entity(muni.name)) obj:setvelocity({x=dir.x*settings.velocity, y=-1, z=dir.z*settings.velocity}) obj:setacceleration({x=dir.x*-3, y=-settings.gravity, z=dir.z*-3}) + minetest.add_particlespawner(50,0.5, + pos, pos, + {x=dir.x*settings.velocity, y=-1, z=dir.z*settings.velocity}, {x=dir.x*settings.velocity/2, y=-1, z=dir.z*settings.velocity/2}, + {x=dir.x*-3/4, y=-settings.gravity*2, z=dir.z*-3/4}, {x=dir.x*-3/2, y=-settings.gravity, z=dir.z*-3/2}, + 0.1, 0.5,--time + 0.5, 1, + false, "cannons_gunpowder.png") end end