Toggle sound traveler display.

master
James Stevenson 2017-11-23 21:18:21 -05:00
parent 745dd67051
commit 5a915d0c2f
1 changed files with 123 additions and 133 deletions

256
init.lua
View File

@ -3,6 +3,8 @@
-- GPL3+
gen_music = {}
local show_st = minetest.settings:get_bool("show_sound_traveler")
gen_music.songs = {}
local mod_name = minetest.get_current_modname()
local mod_path = minetest.get_modpath(mod_name)
@ -99,7 +101,24 @@ for i = 1, #extra_sounds do
end
end
-- Sound Traveller
local jitter = function(j, p)
local r = math.random()
local s = j * -1
if r > 0.5 then
s = j * 1
if math.random() > r then
return p + (1 * s)
else
return p - (1 * s)
end
elseif math.random() < r then
return p + (1 * s)
else
return p - (1 * s)
end
end
-- Sound Traveler
local ps = function(pos)
if math.random() < 0.8 then
return
@ -110,38 +129,47 @@ local ps = function(pos)
end
minetest.add_particle({
pos = {
x = math.random() * s + pos.x,
y = math.random() * s + pos.y,
z = math.random() * s + pos.z
x = jitter(math.random(), math.random() * s + pos.x),
y = jitter(math.random(), math.random() * s + pos.y),
z = jitter(math.random(), math.random() * s + pos.z)
},
velocity = {
x = math.random() * s,
y = math.random() * s,
z = math.random() * s
x = jitter(math.random(), math.random() * s),
y = jitter(math.random(), math.random() * s),
z = jitter(math.random(), math.random() * s)
},
acceleration = {
x = math.random() * s,
y = math.random() * s,
z = math.random() * s
x = jitter(math.random(), math.random() * s),
y = jitter(math.random(), math.random() * s),
z = jitter(math.random(), math.random() * s)
},
expirationtime = 1,
size = 2,
texture = "xdecor_glyph" .. math.random(1, 18) .. ".png",
glow = 10,
})
end
-- if show_sound_traveller
minetest.register_entity("gen_music:sound_traveller", {
local st_textures = {"empty.png"}
local st_on_activate = function(self, staticdata, dtime_s) end
local st_on_step = function(self, dtime) end
if show_st then
print("Showing Sound Travelers")
st_textures = {"default_mese_crystal.png"}
st_on_activate = function(self, staticdata, dtime_s)
self.pos = self.object:get_pos()
end
st_on_step = function(self, dtime)
ps(self.pos)
end
end -- ^ nil these after registry?
minetest.register_entity("gen_music:sound_traveler", {
visual = "sprite",
visual_size = {x = 0.5, y = 0.5},
collisionbox = {0},
physical = false,
textures = {"empty.png"},--default_mese_crystal.png"},
on_activate = function(self, staticdata, dtime_s)
--self.pos = self.object:get_pos()
end,
on_step = function(self, dtime)
--ps(self.pos)
end,
textures = st_textures,
on_activate = st_on_activate,
on_step = st_on_step,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
end,
on_death = function(self, killer)
@ -153,8 +181,6 @@ minetest.register_entity("gen_music:sound_traveller", {
})
gen_music.gs = function(object, song, loop)
-- TODO Generate random sequence and ensemble based on
-- found sounds, and extra_sounds.txt.
if type(song) == "string" then
song = gen_music.songs[song]
end
@ -169,121 +195,85 @@ gen_music.gs = function(object, song, loop)
local play = minetest.sound_play
local seq = {}
local obj = {}
if math.random() < 0.67 then
minetest.after(math.random(), function()
local p_pos = object:get_pos()
if not p_pos then
return
end
local jitter = function(j, p)
local r = math.random()
local s = j * -1
if r > 0.5 then
s = j * 1
if math.random() > r then
return p + (1 * s)
else
return p - (1 * s)
end
elseif math.random() < r then
return p + (1 * s)
else
return p - (1 * s)
end
end
p_pos.x = jitter(math.random(), p_pos.x)
p_pos.y = jitter(math.random(), p_pos.y)
p_pos.z = jitter(math.random(), p_pos.z)
local function play_variable(ensemble, positional)
-- New object.
local obj_idx = #obj + 1
obj[obj_idx] = minetest.add_entity(p_pos,
"gen_music:sound_traveller", "")
local o_pos = obj[obj_idx]:get_pos()
local d = vector.direction(p_pos, o_pos)
d.x = jitter(math.random(), d.x)
d.y = jitter(math.random(), d.y)
d.z = jitter(math.random(), d.z)
obj[obj_idx]:set_velocity(d)
obj[obj_idx]:set_acceleration(d)
-- New sound attached to new object.
local pitch = math.random()
if math.random() > 0.5 or
pitch > 0.66 then
pitch = pitch - 0.5
end
local idx = #seq + 1
local fade = math.random(1)
local n
if not ensemble then
n = ""
else
n = ensemble[math.random(1, #song)]
end
seq[idx] = play(n, {
gain = gain * 0.1,
pitch = pitch * 1.33,
fade = fade,
object = obj[obj_idx],
})
--print("Starting " .. seq[idx])
if fade == 1 then
minetest.sound_fade(seq[idx], 0.1, gain)
end
end
local score = song.seq
for i = 1, #score do
local e = score[i]
if e == "0" then
minetest.after(math.random(), function()
play_variable()
end)
else
local g = song.ins[e]
if g then
minetest.after(math.random(), function()
play_variable{g}
end)
end
end
end
-- `Mese Music' by jas
--[[
if math.random() < 0.33 then
play_variable({"phit", "phit", "phit", "phit"})
minetest.after(math.random(), function()
play_variable({"phit", "phit", "walkie_blip", "xdecor_enchanting", "mobs_spell"}, true)
end)
end
if math.random() > 0.33 then
minetest.after(math.random(), function()
play_variable({"walkie_blip", "walkie_blip", "phit"}, true)
end)
end
if math.random() > 0.5 then
minetest.after(math.random(), function()
play_variable({"xdecor_enchanting", "phit", "walkie_blip"}, false)
end)
end
--]]
minetest.after(math.random(), function()
for k, v in pairs(obj) do
v:remove()
end
end)
end)
end
-- r1
--local prob = math.random()
--if prob < 0.67 then
minetest.after(math.random(), function()
local p_pos = object:get_pos()
if not p_pos then
return
end
p_pos.x = jitter(math.random(), p_pos.x)
p_pos.y = jitter(math.random(), p_pos.y)
p_pos.z = jitter(math.random(), p_pos.z)
local function play_variable(ensemble)
-- New object.
local obj_idx = #obj + 1
obj[obj_idx] = minetest.add_entity(p_pos,
"gen_music:sound_traveler", "")
local o_pos = obj[obj_idx]:get_pos()
local d = vector.direction(p_pos, o_pos)
d.x = jitter(math.random(), d.x)
d.y = jitter(math.random(), d.y)
d.z = jitter(math.random(), d.z)
obj[obj_idx]:set_velocity(d)
obj[obj_idx]:set_acceleration(d)
-- New sound attached to new object.
local pitch = math.random()
if math.random() > 0.5 or
pitch > 0.66 then
pitch = pitch - 0.5
end
local idx = #seq + 1
local fade = math.random(1)
local n
if not ensemble then
n = ""
else
n = ensemble[math.random(1, #song)]
end
seq[idx] = play(n, {
gain = gain * 0.1,
pitch = pitch * 1.33,
fade = fade,
object = obj[obj_idx],
})
print("Starting " .. seq[idx])
if fade == 1 then
minetest.sound_fade(seq[idx], 0.1, gain)
end
end
local score = song.seq
for i = 1, #score do
local e = score[i]
if e == "0" then
minetest.after(math.random(), function()
play_variable()
end)
else
local g = song.ins[e]
if g then
minetest.after(math.random(), function()
play_variable{g}
end)
end
end
end
minetest.after(math.random(), function()
for k, v in pairs(obj) do
v:remove()
end
end)
end)
--end
minetest.after(1 + math.random() + math.random(), function()
for idx = 1, #seq do
minetest.after(math.random(), function()
--print("Stopping " .. seq[idx])
print("Stopping " .. seq[idx])
minetest.sound_fade(seq[idx], -0.1, 0.0)
minetest.after(math.random(), function()
minetest.sound_stop(seq[idx])