play sound when the snowball hurts an object and make damage depend on velocity differrence

This commit is contained in:
HybridDog 2015-12-30 11:31:38 +01:00
parent d8d79655af
commit 8d78cb6867

View File

@ -8,11 +8,19 @@
local creative_mode = minetest.setting_getbool("creative_mode") local creative_mode = minetest.setting_getbool("creative_mode")
local snowball_velocity = snow.snowball_velocity
local snowball_velocity, entity_attack_delay
local function update_snowball_vel(v)
snowball_velocity = v
local walkspeed = tonumber(minetest.setting_get("movement_speed_walk")) or 4
entity_attack_delay = (walkspeed+1)/v
end
update_snowball_vel(snow.snowball_velocity)
local snowball_gravity = snow.snowball_gravity local snowball_gravity = snow.snowball_gravity
snow.register_on_configuring(function(name, v) snow.register_on_configuring(function(name, v)
if name == "snowball_velocity" then if name == "snowball_velocity" then
snowball_velocity = v update_snowball_vel(v)
elseif name == "snowball_gravity" then elseif name == "snowball_gravity" then
snowball_gravity = v snowball_gravity = v
end end
@ -153,31 +161,38 @@ function snow_snowball_ENTITY.on_step(self, dtime)
--self.object:setvelocity({x=0, y=0, z=0}) --self.object:setvelocity({x=0, y=0, z=0})
pos = self.lastpos pos = self.lastpos
self.object:setpos(pos) self.object:setpos(pos)
local gain = vector.length(self.object:getvelocity())/30 minetest.sound_play("default_snow_footstep", {pos=pos, gain=vector.length(self.object:getvelocity())/30})
minetest.sound_play("default_snow_footstep", {pos=pos, gain=gain})
self.object:set_properties({physical = true}) self.object:set_properties({physical = true})
self.physical = true self.physical = true
return return
end end
self.lastpos = vector.new(pos) self.lastpos = vector.new(pos)
if self.timer > 0.15 then if self.timer < entity_attack_delay then
for _,v in pairs(minetest.get_objects_inside_radius(pos, 1.73)) do return
if v ~= self.object then end
local entity_name = v:get_entity_name() for _,v in pairs(minetest.get_objects_inside_radius(pos, 1.73)) do
if entity_name ~= "snow:snowball_entity" if v ~= self.object then
and entity_name ~= "__builtin:item" local entity_name = v:get_entity_name()
and entity_name ~= "gauges:hp_bar" then if entity_name ~= "snow:snowball_entity"
v:punch( and entity_name ~= "__builtin:item"
(self.thrower and minetest.get_player_by_name(self.thrower)) and entity_name ~= "gauges:hp_bar" then
or self.object, local vvel = v:getvelocity() or v:get_player_velocity()
1, local veldif = self.object:getvelocity()
{full_punch_interval=1, damage_groups = {fleshy=1}} if vvel then
) veldif = vector.subtract(veldif, vvel)
spawn_falling_node(pos, {name = "default:snow"})
self.object:remove()
return
end end
local gain = vector.length(veldif)/20
v:punch(
(self.thrower and minetest.get_player_by_name(self.thrower))
or self.object,
1,
{full_punch_interval=1, damage_groups = {fleshy=math.ceil(gain)}}
)
minetest.sound_play("default_snow_footstep", {pos=pos, gain=gain})
spawn_falling_node(pos, {name = "default:snow"})
self.object:remove()
return
end end
end end
end end