Add music

master
Lean Rada 2015-01-29 11:11:55 +08:00
parent 18a9909f43
commit d12debc625
9 changed files with 117 additions and 36 deletions

View File

@ -10,10 +10,10 @@ director.spawn_list = {
intensity_min = 0.0,
intensity_max = 0.6,
group_min = 1,
group_max = 6,
probability = 0.5,
group_max = 4,
probability = 0.4,
day_start = 0,
spawn_time = 7.0,
spawn_time = 14.0,
spawn_location = "ground",
},
{
@ -25,41 +25,41 @@ director.spawn_list = {
group_max = 24,
probability = 0.8,
day_start = 1,
spawn_time = 41.0,
spawn_time = 71.0,
spawn_location = "ground",
},
{
description = "Paniki group",
name = "defense:paniki",
intensity_min = 0.0,
intensity_max = 0.4,
intensity_max = 0.3,
group_min = 1,
group_max = 4,
probability = 0.2,
group_max = 6,
probability = 0.6,
day_start = 0,
spawn_time = 19.0,
spawn_time = 9.0,
spawn_location = "air",
},
{
description = "Sarangay",
name = "defense:sarangay",
intensity_min = 0,
intensity_max = 0.1,
intensity_min = 0.0,
intensity_max = 0.2,
group_min = 1,
group_max = 1,
probability = 0.2,
day_start = 3,
probability = 0.4,
day_start = 2,
spawn_time = 90.0,
spawn_location = "ground",
},
{
description = "Botete",
name = "defense:botete",
intensity_min = 0,
intensity_max = 0.1,
intensity_min = 0.0,
intensity_max = 0.3,
group_min = 1,
group_max = 1,
probability = 0.1,
probability = 0.4,
day_start = 1,
spawn_time = 90.0,
spawn_location = "air",
@ -80,9 +80,12 @@ end
function director:on_interval()
self:update_intensity()
if defense.debug then
minetest.chat_send_all("Intensity: " .. self.intensity)
end
if self.cooldown_timer <= 0 then
if defense:is_dark() and #minetest.luaentities < self.max_entities and not defense.debug then
if defense:is_dark() and #minetest.luaentities < self.max_entities then
self:spawn_monsters()
end
@ -236,9 +239,9 @@ function director:update_intensity()
local mob_count = #minetest.luaentities
local delta =
-0.2 * math.min(0.06, average_health - last_average_health)
+ 0.2 * math.min(0, 1 / average_health - 0.1)
+ 0.0001 * (mob_count - last_mob_count)
-0.16 * math.min(0.06, average_health - last_average_health)
+ 2.0 * math.min(0, 1 / average_health)
+ 0.006 * (mob_count - last_mob_count)
last_average_health = average_health
last_mob_count = mob_count
@ -251,15 +254,6 @@ function director:get_day_count()
return math.floor(minetest.get_gametime() * time_speed / 86400)
end
local last_call_time = 0
minetest.register_globalstep(function(dtime)
local gt = minetest.get_gametime()
if last_call_time + director.call_interval < gt then
director:on_interval()
last_call_time = gt
end
end)
function director:save()
local file = assert(io.open(minetest.get_worldpath() .. "/defense.txt", "w"))
local data = {
@ -291,4 +285,13 @@ end
minetest.register_on_shutdown(function()
director:save()
end)
director:load()
director:load()
local last_call_time = 0
minetest.register_globalstep(function(dtime)
local gt = minetest.get_gametime()
if last_call_time + director.call_interval < gt then
director:on_interval()
last_call_time = gt
end
end)

View File

@ -11,7 +11,7 @@ minetest.register_chatcommand("debug", {
regeneration.rate = 100
minetest.set_timeofday(0.3)
else
regeneration.rate = 0.1
regeneration.rate = 0.2
end
return true
end,
@ -44,4 +44,5 @@ dofile2("mobs/paniki.lua")
dofile2("mobs/botete.lua")
dofile2("director.lua")
dofile2("music.lua")
dofile2("initial_stuff.lua")

79
mods/defense/music.lua Normal file
View File

@ -0,0 +1,79 @@
defense.music = {}
local music = defense.music
music.loop_length = 6.0 - 0.1
-- State tracking stuff
local current_level = 0
local current_music = nil
local last_intensity = 0
local last_update_time = 0
function music:update()
local time = os.time()
if current_level > 0 then
if time < last_update_time + music.loop_length then
return
end
end
last_update_time = time
local intensity = defense.director.intensity
if not defense:is_dark() then
intensity = intensity * 0.1
end
last_intensity = intensity
intensity = intensity + (intensity - last_intensity) * 0.5
local il = {0.1, 0.5, 0.8, 0.99}
local last_level = current_level
if intensity <= il[1] then
if current_level > 0 then
current_level = current_level - 1
end
elseif intensity > il[1] and intensity <= il[2] then
if current_level > 1 then
current_level = current_level - 1
elseif current_level < 1 then
current_level = current_level + 1
end
elseif intensity > il[2] and intensity <= il[3] then
if current_level > 2 then
current_level = current_level - 1
elseif current_level < 2 then
current_level = current_level + 1
end
elseif intensity > il[3] and intensity <= il[4] then
if current_level > 3 then
current_level = current_level - 1
elseif current_level < 3 then
current_level = current_level + 1
end
elseif intensity > il[4] then
if current_level < 4 then
current_level = current_level + 1
end
end
if last_level ~= current_level then
if defense.debug then
minetest.chat_send_all("Level: " .. current_level)
end
minetest.sound_play("defense_music_transit", {
gain = 0.05
})
if current_music then
minetest.sound_stop(current_music)
end
if current_level > 0 then
current_music = minetest.sound_play("defense_music_level" .. current_level, {
pos = nil,
gain = 0.4 + current_level * 0.15,
loop = true,
})
end
end
end
minetest.register_globalstep(function(dtime)
music:update()
end)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,15 +1,13 @@
regeneration = {}
regeneration.rate = 0.1 -- hp per second
regeneration.rate = 0.2 -- hp per second
local counter = 0
minetest.register_globalstep(function(dtime)
counter = counter + dtime * regeneration.rate
if counter >= 1 then
while counter >= 1 do
counter = counter - 1
for _,p in ipairs(minetest.get_connected_players()) do
while counter >= 1 do
counter = counter - 1
p:set_hp(p:get_hp() + 1)
end
p:set_hp(p:get_hp() + 1)
end
end
end)