Grenades
parent
f79b761ae9
commit
b185bc4159
|
@ -0,0 +1,37 @@
|
|||
quake.register_grenade("quake:grenade", {
|
||||
description = "grenade",
|
||||
--mesh = "quake_railgun.obj",
|
||||
--tiles = {"quake_railgun.png"},
|
||||
wield_scale = {x=1.5, y=1.5, z=1.5},
|
||||
inventory_image = "quake_railgun.png",
|
||||
wield_image = "quake_railgun.png",
|
||||
|
||||
entity = {
|
||||
throw_speed = 12,
|
||||
explosion_damage = 16,
|
||||
physical = true,
|
||||
collide_with_objects = true,
|
||||
visual = "item",
|
||||
wield_item = "quake:grenade",
|
||||
visual_size = {x = 0.3, y = 0.3, z = 0.3},
|
||||
--mesh = "quake_rocket.obj",
|
||||
explosion_texture = "quake_rocket_particle.png",
|
||||
--textures = {"quake_bullet_rocket.png"},
|
||||
collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
|
||||
explosion_range = 4,
|
||||
duration = 3,
|
||||
gravity = true,
|
||||
on_destroy = quake.explode,
|
||||
particle = {
|
||||
image = "quake_bullet_rocket.png",
|
||||
life = 1,
|
||||
size = 4,
|
||||
glow = 0,
|
||||
interval = 5,
|
||||
},
|
||||
acceleration = 13,
|
||||
|
||||
},
|
||||
|
||||
|
||||
})
|
|
@ -0,0 +1,276 @@
|
|||
-- definisco le proprietà e i costruttori delle entità 'proiettili' e le registro alla fine
|
||||
function quake.register_grenade(name, def)
|
||||
|
||||
if not def.entity.throw_speed then return end
|
||||
|
||||
minetest.register_tool(name, {
|
||||
description = def.description,
|
||||
--drawtype = "mesh",
|
||||
--mesh = def.mesh,
|
||||
--tiles = def.tiles,
|
||||
wield_scale = def.wield_scale,
|
||||
inventory_image = def.inventory_image,
|
||||
wield_image = def.wield_image,
|
||||
on_drop = function() end,
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
grenade_throw(itemstack, user, pointed_thing)
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
itemstack:take_item()
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||
grenade_throw(itemstack, user, pointed_thing)
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
itemstack:take_item()
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
|
||||
})
|
||||
|
||||
local grenade_entity = grenade_set_entity(name, def)
|
||||
|
||||
minetest.register_entity(name .. "_entity", grenade_entity)
|
||||
|
||||
end
|
||||
|
||||
function grenade_throw(itemstack, player, pointed_thing)
|
||||
|
||||
local dir = player:get_look_dir()
|
||||
local yaw = player:get_look_horizontal()
|
||||
local pitch = player:get_look_vertical()
|
||||
local pos = player:get_pos()
|
||||
local grenade = itemstack:get_name() .. '_entity'
|
||||
local obj = minetest.add_entity({x = pos.x + dir.x, y = pos.y + 1.6, z = pos.z + dir.z}, grenade, player:get_player_name())
|
||||
|
||||
local throw_speed = obj:get_luaentity().initial_properties.throw_speed
|
||||
local player_vel = player:get_player_velocity()
|
||||
obj:set_velocity(vector.add(player_vel, vector.multiply(dir, throw_speed)))
|
||||
--obj:set_velocity({x = dir.x * m, y = dir.y * m/1.5, z = dir.z * m})
|
||||
--obj:set_acceleration({x = 0, y = -13, z = 0})
|
||||
local rotation = vector.new(0, yaw + math.pi/2, pitch + math.pi/6)
|
||||
obj:set_rotation(rotation)
|
||||
--[[
|
||||
local grenade = itemstack:get_name() .. '_entity'
|
||||
local player_pos = player:get_pos()
|
||||
local head_pos = vector.new(player_pos.x, player_pos.y + player:get_properties().eye_height, player_pos.z)
|
||||
local direction = player:get_look_dir()
|
||||
local throw_pos = vector.add(head_pos, vector.multiply(direction,0.5))
|
||||
local pitch = player:get_look_vertical()
|
||||
local yaw = player:get_look_horizontal()
|
||||
local rotation = vector.new(0, yaw + math.pi/2, pitch + math.pi/6)
|
||||
local grenade_object = minetest.add_entity(throw_pos, grenade, player:get_player_name())
|
||||
local throw_speed = grenade_object:get_luaentity().initial_properties.throw_speed
|
||||
local player_vel = player:get_player_velocity()
|
||||
grenade_object:set_velocity(vector.add(player_vel, vector.multiply(direction, throw_speed)))
|
||||
|
||||
|
||||
grenade_object:set_rotation(rotation)
|
||||
grenade_object:set_rotation(vector.new(0, 0, 0))
|
||||
]]
|
||||
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function grenade_set_entity(name, def)
|
||||
local grenade_entity = {
|
||||
initial_properties = {
|
||||
name = name,
|
||||
throw_speed = def.entity.throw_speed,
|
||||
explosion_damage = def.entity.explosion_damage, --danno dell'esplosione
|
||||
physical = def.entity.physical, --se è fisica
|
||||
collide_with_objects = def.entity.collide_with_objects, --se collide con gli oggetti
|
||||
visual = def.entity.visual, --che tipo di visualizzazione fare
|
||||
wield_item = def.entity.wield_item, --apparenza della granata
|
||||
visual_size = def.entity.visual_size, --grandezza visiva della granata
|
||||
--mesh = def.entity.mesh,
|
||||
explosion_texture = def.entity.explosion_texture, --texture dell'esplosione
|
||||
--textures = def.entity.textures,
|
||||
collisionbox = def.entity.collisionbox, --grandezza della collisionbox
|
||||
explosion_range = def.entity.explosion_range, --in che raggio fa danno l'esplosione
|
||||
duration = def.entity.duration, --quanto dura il volo
|
||||
gravity = def.entity.gravity, --se la gravità è attiva o no
|
||||
on_destroy = def.entity.on_destroy, --cosa succede alla distruzione
|
||||
particle = def.entity.particle,
|
||||
acceleration = def.entity.acceleration,
|
||||
},
|
||||
}
|
||||
|
||||
function grenade_entity:_destroy()
|
||||
|
||||
if self.initial_properties.on_destroy then
|
||||
self.initial_properties.on_destroy(self)
|
||||
end
|
||||
|
||||
-- spawna le particelle
|
||||
spawn_particles_sphere(self.object:get_pos(), self.initial_properties.explosion_texture)
|
||||
self.object:remove()
|
||||
|
||||
end
|
||||
|
||||
function grenade_entity:get_staticdata(self)
|
||||
if self == nil or self.p_name == nil then return end
|
||||
return self.p_name
|
||||
end
|
||||
|
||||
function grenade_entity:on_punch()
|
||||
self:_destroy()
|
||||
return
|
||||
end
|
||||
|
||||
-- quando si istanzia un'entità
|
||||
function grenade_entity:on_activate(staticdata)
|
||||
|
||||
if staticdata ~= "" and staticdata ~= nil then
|
||||
self.p_name = staticdata -- nome utente come staticdata
|
||||
self.lifetime = 0
|
||||
self.sliding = 1
|
||||
self.particle = 0
|
||||
self.object:set_armor_groups({immortal = 1})
|
||||
else
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
function grenade_entity:on_step(dtime, moveresult)
|
||||
self.lifetime = self.lifetime + dtime
|
||||
|
||||
|
||||
if self.initial_properties.gravity then
|
||||
local obj = self.object
|
||||
local velocity = obj:get_velocity()
|
||||
|
||||
local pos = obj:getpos()
|
||||
if moveresult.collides and moveresult.collisions[1] and vector.distance(moveresult.collisions[1].old_velocity, velocity) > 2 then
|
||||
--print("collido")
|
||||
velocity[moveresult.collisions[1].axis] = moveresult.collisions[1].old_velocity[moveresult.collisions[1].axis] * -0.6 -- Invert velocity and reduce it a bit
|
||||
obj:set_velocity(velocity)
|
||||
--print(velocity.y)
|
||||
end
|
||||
|
||||
|
||||
|
||||
if self.sliding == 1 and velocity.y == 0 then -- Check if grenade is sliding
|
||||
self.sliding = 2 -- Multiplies drag by 2
|
||||
elseif self.sliding > 1 and velocity.y ~= 0 then
|
||||
self.sliding = 1 -- Doesn't affect drag
|
||||
end
|
||||
|
||||
if self.sliding > 1 then -- Is the grenade sliding?
|
||||
if vector.distance(vector.new(), velocity) <= 1 and not vector.equals(velocity, vector.new()) then -- Grenade is barely moving
|
||||
obj:set_velocity(vector.new(0, 0, 0)) -- Make sure it stays unmoving
|
||||
obj:set_acceleration(vector.new())
|
||||
end
|
||||
else
|
||||
local norm_velocity = vector.normalize(velocity)
|
||||
local node = minetest.get_node(pos)
|
||||
local drag = math.max(minetest.registered_nodes[node.name].liquid_viscosity, 1)
|
||||
--print(drag)
|
||||
--local acceleration = vector.multiply(velocity, -drag)
|
||||
--print(acceleration.y)
|
||||
--acceleration.y = acceleration.y - 10 * ((7 - drag) / 7)
|
||||
--obj:set_acceleration(acceleration)
|
||||
obj:set_acceleration({
|
||||
x = -norm_velocity.x * self.initial_properties.throw_speed * self.sliding,
|
||||
y = -9.8 * drag,
|
||||
z = -norm_velocity.z * self.initial_properties.throw_speed * self.sliding,
|
||||
})
|
||||
|
||||
|
||||
|
||||
local yaw = minetest.dir_to_yaw(norm_velocity)
|
||||
local speed = vector.length(velocity)
|
||||
local pitch = math.acos(velocity.y/speed) - math.pi/3
|
||||
obj:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch})
|
||||
|
||||
--[[
|
||||
local norm_velocity = vector.normalize(velocity)
|
||||
obj:set_acceleration({
|
||||
x = -norm_velocity.x * self.initial_properties.acceleration * self.sliding,
|
||||
y = -9.8,
|
||||
z = -norm_velocity.z * self.initial_properties.acceleration * self.sliding,
|
||||
})]]
|
||||
end
|
||||
|
||||
if self.initial_properties.particle and self.particle >= 4 then
|
||||
self.particle = 0
|
||||
|
||||
minetest.add_particle({
|
||||
pos = obj:get_pos(),
|
||||
velocity = vector.divide(velocity, 2),
|
||||
acceleration = vector.divide(obj:get_acceleration(), -5),
|
||||
expirationtime = self.initial_properties.particle.life,
|
||||
size = self.initial_properties.particle.size,
|
||||
collisiondetection = false,
|
||||
collision_removal = false,
|
||||
vertical = false,
|
||||
texture = self.initial_properties.particle.image,
|
||||
glow = self.initial_properties.particle.glow
|
||||
})
|
||||
elseif self.initial_properties.particle and self.particle < self.initial_properties.particle.interval then
|
||||
self.particle = self.particle + 1
|
||||
end
|
||||
|
||||
if self.lifetime >= self.initial_properties.duration then
|
||||
self:_destroy()
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
|
||||
local speed = vector.length(velocity)
|
||||
local direction = vector.normalize(velocity)
|
||||
local yaw = minetest.dir_to_yaw(direction)
|
||||
local pitch = math.acos(velocity.y/speed) - math.pi/3
|
||||
local pos = self.object:get_pos()
|
||||
local node = minetest.get_node(pos)
|
||||
local drag = math.max(minetest.registered_nodes[node.name].liquid_viscosity, 0.1)
|
||||
if velocity.y == 0 then
|
||||
drag = drag * 2
|
||||
end
|
||||
local acceleration = vector.multiply(velocity, -drag)
|
||||
acceleration.y = acceleration.y - 10 * ((7 - drag) / 7)
|
||||
if tostring(acceleration) ~= 'nan' then
|
||||
self.object:set_acceleration(acceleration)
|
||||
end
|
||||
if tostring(yaw) ~= 'nan' and tostring(pitch) ~= 'nan' then
|
||||
self.object:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch})
|
||||
end
|
||||
]]
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
return grenade_entity
|
||||
end
|
||||
|
||||
|
||||
--aggiunge le particelle dell'esplosione
|
||||
function spawn_particles_sphere(pos, particle_texture)
|
||||
|
||||
minetest.add_particlespawner({
|
||||
amount = 80,
|
||||
time = .1,
|
||||
minpos = {x=pos.x,y=pos.y,z=pos.z},
|
||||
maxpos = {x=pos.x,y=pos.y,z=pos.z},
|
||||
minvel = {x=-4, y=-4, z=-4},
|
||||
maxvel = {x=4, y=4, z=4},
|
||||
minacc = {x=0, y=-0.4, z=0},
|
||||
maxacc = {x=0, y=-0.8, z=0},
|
||||
minexptime = .5,
|
||||
maxexptime = .5,
|
||||
minsize = 1,
|
||||
maxsize = 5,
|
||||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = particle_texture,
|
||||
})
|
||||
|
||||
end
|
3
init.lua
3
init.lua
|
@ -57,5 +57,8 @@ dofile(minetest.get_modpath("quake") .. "/_weapons/railgun.lua")
|
|||
dofile(minetest.get_modpath("quake") .. "/_weapons/rocket_launcher.lua")
|
||||
dofile(minetest.get_modpath("quake") .. "/_weapons/shotgun.lua")
|
||||
dofile(minetest.get_modpath("quake") .. "/_weapons/rocket.lua")
|
||||
dofile(minetest.get_modpath("quake") .. "/_weapons/grenades.lua")
|
||||
dofile(minetest.get_modpath("quake") .. "/_weapons/grenade.lua")
|
||||
|
||||
|
||||
quake.init_storage()
|
||||
|
|
Loading…
Reference in New Issue