sounds + loop

master
BuckarooBanzay 2019-10-11 10:45:40 +02:00
parent cf7088ba9a
commit 3da88b6e1c
7 changed files with 114 additions and 9 deletions

View File

@ -70,8 +70,8 @@ minetest.register_node("epic:set_weather", {
epic = {
on_enter = function(_, meta, player, ctx)
--local weathername = meta:get_string("weathername")
-- TODO
local weathername = meta:get_string("weathername")
epic_weather.current_weather[player:get_player_name()] = weathername
ctx.next()
end
}

View File

@ -1,10 +1,17 @@
local MP = minetest.get_modpath("epic_weather")
epic_weather = {}
epic_weather = {
current_weather = {}
}
dofile(MP.."/register.lua")
dofile(MP.."/block.lua")
dofile(MP.."/weather.lua")
dofile(MP.."/rain.lua")
dofile(MP.."/snow.lua")
epic.register_hook({
on_epic_exit = function(playername)
epic_weather.current_weather[playername] = nil
end
})

55
rain.lua Normal file
View File

@ -0,0 +1,55 @@
epic_weather.register_weather({ name = "Rain" })
local function do_rain(player)
local ppos = player:get_pos()
local player_name = player:get_player_name()
if math.random(2) == 1 then
minetest.sound_play("epic_weather_rain", {
to_player = player_name,
gain = 1.0,
fade = 0.5,
pos = vector.add(ppos, {x=0, y=5, z=0})
})
end
minetest.add_particlespawner({
amount = 1000,
time = 2,
minpos = vector.add(ppos, {x=-20, y=10, z=-20}),
maxpos = vector.add(ppos, {x=20, y=10, z=20}),
minvel = {x=2, y=-5, z=0},
maxvel = {x=2, y=-12, z=0},
minacc = {x=0, y=0, z=0},
maxacc = {x=0, y=0, z=0},
minexptime = 1,
maxexptime = 5,
minsize = 20,
maxsize = 30.7,
collisiondetection = true,
collision_removal = true,
object_collision = true,
vertical = true,
texture = "epic_weather_rain.png",
playername = player_name
})
end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 2 then return end
timer=0
for _, player in ipairs(minetest.get_connected_players()) do
local playername = player:get_player_name()
local weathername = epic_weather.current_weather[playername]
if weathername == "Rain" then
do_rain(player)
end
end
end)

View File

@ -3,8 +3,7 @@ epic_weather.weatherdefs = {} -- list<weatherdef>
--[[
weatherdef = {
name = "",
on_step = function() end
name = ""
}
--]]
@ -13,5 +12,3 @@ epic_weather.register_weather = function(def)
end
epic_weather.register_weather({ name = "None" })

46
snow.lua Normal file
View File

@ -0,0 +1,46 @@
epic_weather.register_weather({ name = "Snow" })
local function do_snow(player)
local ppos = player:get_pos()
local player_name = player:get_player_name()
minetest.add_particlespawner({
amount = 1000,
time = 5,
minpos = vector.add(ppos, {x=-20, y=5, z=-20}),
maxpos = vector.add(ppos, {x=20, y=10, z=20}),
minvel = {x=0.5, y=-1, z=0},
maxvel = {x=1, y=-3, z=0},
minacc = {x=0, y=0, z=0},
maxacc = {x=0, y=0, z=0},
minexptime = 1,
maxexptime = 5,
minsize = 20,
maxsize = 30.7,
collisiondetection = true,
collision_removal = true,
object_collision = true,
vertical = true,
texture = "epic_weather_snow.png",
playername = player_name
})
end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 2 then return end
timer=0
for _, player in ipairs(minetest.get_connected_players()) do
local playername = player:get_player_name()
local weathername = epic_weather.current_weather[playername]
if weathername == "Snow" then
do_snow(player)
end
end
end)

Binary file not shown.

View File