mirror of
https://github.com/pandorabox-io/spacecannon.git
synced 2024-12-21 05:15:47 +01:00
particles, on_blast(), luacheckrc
This commit is contained in:
parent
655d4bb191
commit
b60bc6328f
22
.luacheckrc
Normal file
22
.luacheckrc
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
unused_args = false
|
||||||
|
allow_defined_top = true
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
"minetest",
|
||||||
|
"spacecannon"
|
||||||
|
}
|
||||||
|
|
||||||
|
read_globals = {
|
||||||
|
-- Stdlib
|
||||||
|
string = {fields = {"split"}},
|
||||||
|
table = {fields = {"copy", "getn"}},
|
||||||
|
|
||||||
|
-- mod deps
|
||||||
|
"technic", "default",
|
||||||
|
|
||||||
|
-- Minetest
|
||||||
|
"minetest",
|
||||||
|
"vector", "ItemStack",
|
||||||
|
"dump"
|
||||||
|
|
||||||
|
}
|
13
cannon.lua
13
cannon.lua
@ -57,13 +57,13 @@ local register_spacecannon = function(def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if collided then
|
if collided then
|
||||||
spacecannon.destroy(pos, def.range)
|
spacecannon.destroy(pos, def.range, def.intensity)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif node.name ~= "air" and node.name ~= "vacuum:vacuum" then
|
elseif node.name ~= "air" and node.name ~= "vacuum:vacuum" then
|
||||||
-- collision
|
-- collision
|
||||||
spacecannon.destroy(pos, def.range)
|
spacecannon.destroy(pos, def.range, def.intensity)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -71,8 +71,8 @@ local register_spacecannon = function(def)
|
|||||||
|
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata)
|
||||||
minetest.after(def.timeout,
|
minetest.after(def.timeout,
|
||||||
function(self)
|
function(me)
|
||||||
self.object:remove()
|
me.object:remove()
|
||||||
end,
|
end,
|
||||||
self)
|
self)
|
||||||
end
|
end
|
||||||
@ -143,8 +143,6 @@ local register_spacecannon = function(def)
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
local meta = minetest.get_meta(pos);
|
|
||||||
|
|
||||||
if fields.fire then
|
if fields.fire then
|
||||||
spacecannon.fire(pos, def.color, def.speed, def.range)
|
spacecannon.fire(pos, def.color, def.speed, def.range)
|
||||||
end
|
end
|
||||||
@ -170,6 +168,7 @@ end
|
|||||||
register_spacecannon({
|
register_spacecannon({
|
||||||
color = "green",
|
color = "green",
|
||||||
range = 1,
|
range = 1,
|
||||||
|
intensity = 1,
|
||||||
timeout = 8,
|
timeout = 8,
|
||||||
speed = 10,
|
speed = 10,
|
||||||
desc = "fast,low damage",
|
desc = "fast,low damage",
|
||||||
@ -179,6 +178,7 @@ register_spacecannon({
|
|||||||
register_spacecannon({
|
register_spacecannon({
|
||||||
color = "yellow",
|
color = "yellow",
|
||||||
range = 3,
|
range = 3,
|
||||||
|
intensity = 2,
|
||||||
timeout = 8,
|
timeout = 8,
|
||||||
speed = 5,
|
speed = 5,
|
||||||
desc = "medium speed, medium damage",
|
desc = "medium speed, medium damage",
|
||||||
@ -188,6 +188,7 @@ register_spacecannon({
|
|||||||
register_spacecannon({
|
register_spacecannon({
|
||||||
color = "red",
|
color = "red",
|
||||||
range = 5,
|
range = 5,
|
||||||
|
intensity = 4,
|
||||||
timeout = 15,
|
timeout = 15,
|
||||||
speed = 3,
|
speed = 3,
|
||||||
desc = "slow, heavy damage",
|
desc = "slow, heavy damage",
|
||||||
|
50
util.lua
50
util.lua
@ -20,7 +20,6 @@ spacecannon.fire = function(pos, color, speed, range)
|
|||||||
|
|
||||||
-- check fuel/power
|
-- check fuel/power
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local owner = meta:get_string("owner")
|
|
||||||
|
|
||||||
if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then
|
if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then
|
||||||
-- not enough power
|
-- not enough power
|
||||||
@ -45,12 +44,14 @@ end
|
|||||||
|
|
||||||
-- destroy stuff in range
|
-- destroy stuff in range
|
||||||
-- TODO: resilient material list
|
-- TODO: resilient material list
|
||||||
spacecannon.destroy = function(pos,range)
|
spacecannon.destroy = function(pos, range, intensity)
|
||||||
|
|
||||||
if not spacecannon.can_destroy(pos) then
|
if not spacecannon.can_destroy(pos) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local particle_texture = nil
|
||||||
|
|
||||||
for x=-range,range do
|
for x=-range,range do
|
||||||
for y=-range,range do
|
for y=-range,range do
|
||||||
for z=-range,range do
|
for z=-range,range do
|
||||||
@ -64,14 +65,28 @@ spacecannon.destroy = function(pos,range)
|
|||||||
local n = minetest.get_node_or_nil(np)
|
local n = minetest.get_node_or_nil(np)
|
||||||
|
|
||||||
if n and n.name ~= "air" then
|
if n and n.name ~= "air" then
|
||||||
minetest.set_node(np, {name="air"})
|
local node_def = minetest.registered_nodes[n.name]
|
||||||
local itemstacks = minetest.get_node_drops(n.name)
|
|
||||||
for _, itemname in ipairs(itemstacks) do
|
if node_def and node_def.tiles and node_def.tiles[1] then
|
||||||
if math.random(5) == 5 then
|
particle_texture = node_def.tiles[1]
|
||||||
-- chance drop
|
end
|
||||||
minetest.add_item(np, itemname)
|
|
||||||
|
if node_def.on_blast then
|
||||||
|
-- custom on_blast
|
||||||
|
node_def.on_blast(np, intensity)
|
||||||
|
|
||||||
|
else
|
||||||
|
-- default behavior
|
||||||
|
minetest.set_node(np, {name="air"})
|
||||||
|
local itemstacks = minetest.get_node_drops(n.name)
|
||||||
|
for _, itemname in ipairs(itemstacks) do
|
||||||
|
if math.random(5) == 5 then
|
||||||
|
-- chance drop
|
||||||
|
minetest.add_item(np, itemname)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -98,6 +113,25 @@ spacecannon.destroy = function(pos,range)
|
|||||||
glow = 5
|
glow = 5
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if particle_texture then
|
||||||
|
minetest.add_particlespawner({
|
||||||
|
amount = 64,
|
||||||
|
time = 0.5,
|
||||||
|
minpos = vector.subtract(pos, radius / 2),
|
||||||
|
maxpos = vector.add(pos, radius / 2),
|
||||||
|
minvel = {x = -10, y = -10, z = -10},
|
||||||
|
maxvel = {x = 10, y = 10, z = 10},
|
||||||
|
minacc = vector.new(),
|
||||||
|
maxacc = vector.new(),
|
||||||
|
minexptime = 1,
|
||||||
|
maxexptime = 2.5,
|
||||||
|
minsize = radius * 3,
|
||||||
|
maxsize = radius * 5,
|
||||||
|
texture = particle_texture,
|
||||||
|
glow = 5
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
minetest.sound_play("tnt_explode", {pos = pos, gain = 1.5, max_hear_distance = math.min(radius * 20, 128)})
|
minetest.sound_play("tnt_explode", {pos = pos, gain = 1.5, max_hear_distance = math.min(radius * 20, 128)})
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user