Sounds (through driver object).
This commit is contained in:
parent
3a87cafee0
commit
e3928fa56d
32
driver.lua
32
driver.lua
@ -3,6 +3,7 @@
|
||||
-- Driver class - manage driver execution
|
||||
--
|
||||
|
||||
|
||||
-- Class definition
|
||||
Driver = {}
|
||||
Driver.__index = Driver
|
||||
@ -13,6 +14,8 @@ setmetatable(Driver, {
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
-- private functions
|
||||
local function driver_setup(self, driver)
|
||||
self.name = driver
|
||||
self.driver = drivers[driver]
|
||||
@ -25,7 +28,20 @@ local function driver_setup(self, driver)
|
||||
end
|
||||
end
|
||||
|
||||
-- constructor
|
||||
local function driver_start(self)
|
||||
local script = self.object.script
|
||||
local sounds = script[self.name].sounds
|
||||
if sounds and sounds.start then
|
||||
local spec = script.sounds[sounds.start][1]
|
||||
local params = {max_hear_distance = script.sounds[sounds.start][2].max_hear_distance,
|
||||
object = self.object.object}
|
||||
minetest.sound_play(spec, params)
|
||||
end
|
||||
self.driver.start(self.object)
|
||||
end
|
||||
|
||||
|
||||
--- constructor
|
||||
function Driver.new(object, driver)
|
||||
local self = setmetatable({}, Driver)
|
||||
self.object = object
|
||||
@ -33,16 +49,26 @@ function Driver.new(object, driver)
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
-- public functions
|
||||
function Driver:switch(driver)
|
||||
driver_setup(self, driver)
|
||||
self.driver.start(self.object)
|
||||
driver_start(self)
|
||||
end
|
||||
|
||||
function Driver:start()
|
||||
self.driver.start(self.object)
|
||||
driver_start(self)
|
||||
end
|
||||
|
||||
function Driver:step(dtime)
|
||||
local script = self.object.script
|
||||
local sounds = script[self.name].sounds
|
||||
if math.random(1, 200) == 1 and sounds and sounds.random then
|
||||
local spec = script.sounds[sounds.random][1]
|
||||
local params = {max_hear_distance = script.sounds[sounds.random][2].max_hear_distance,
|
||||
object = self.object.object}
|
||||
minetest.sound_play(spec, params)
|
||||
end
|
||||
self.driver.step(self.object, dtime)
|
||||
end
|
||||
|
||||
|
47
init.lua
47
init.lua
@ -209,7 +209,7 @@ drivers.roam = {
|
||||
return
|
||||
end
|
||||
|
||||
minetest.add_particle({
|
||||
--[[ minetest.add_particle({
|
||||
pos = {x = pick.x, y = pick.y - 0.1, z = pick.z},
|
||||
velocity = vector.new(),
|
||||
acceleration = vector.new(),
|
||||
@ -220,6 +220,7 @@ drivers.roam = {
|
||||
texture = "wool_red.png",
|
||||
playername = nil
|
||||
})
|
||||
--]]
|
||||
|
||||
self.path = Path(self, pick)
|
||||
if not self.path:find() then
|
||||
@ -232,8 +233,6 @@ drivers.roam = {
|
||||
animation_select(self, "move")
|
||||
end,
|
||||
step = function(self, dtime)
|
||||
animation_loop(self, dtime)
|
||||
consider_factors(self, dtime)
|
||||
-- handle movement stuff
|
||||
local state = self.entity_ai_state
|
||||
if state.roam_ttl > 0 then
|
||||
@ -262,8 +261,6 @@ drivers.idle = {
|
||||
state.idle_ttl = math.random(2, 20)
|
||||
end,
|
||||
step = function(self, dtime)
|
||||
animation_loop(self, dtime)
|
||||
consider_factors(self, dtime)
|
||||
local state = self.entity_ai_state
|
||||
state.idle_ttl = state.idle_ttl - dtime
|
||||
if state.idle_ttl <= 0 then
|
||||
@ -290,8 +287,6 @@ drivers.startle = {
|
||||
state.factors.anim_end = nil
|
||||
end,
|
||||
step = function(self, dtime)
|
||||
animation_loop(self, dtime)
|
||||
consider_factors(self, dtime)
|
||||
end,
|
||||
stop = function(self)
|
||||
-- play out remaining animations
|
||||
@ -309,8 +304,6 @@ drivers.eat = {
|
||||
state.eat_ttl = math.random(30, 60)
|
||||
end,
|
||||
step = function(self, dtime)
|
||||
animation_loop(self, dtime)
|
||||
consider_factors(self, dtime)
|
||||
|
||||
local state = self.entity_ai_state
|
||||
state.eat_ttl = (state.eat_ttl or math.random(30, 30)) - dtime
|
||||
@ -344,14 +337,12 @@ drivers.flee = {
|
||||
state.factors.fleed_too_long = nil
|
||||
end,
|
||||
step = function(self, dtime)
|
||||
animation_loop(self, dtime)
|
||||
-- check timer ourselves
|
||||
local state = self.entity_ai_state
|
||||
if (minetest.get_us_time() - state.flee_start) > (15 * 1000000) then
|
||||
state.factors.got_hit = nil
|
||||
state.factors.fleed_too_long = true
|
||||
end
|
||||
consider_factors(self, dtime)
|
||||
|
||||
-- are we fleeing yet?
|
||||
if self.path and self.path.distance then
|
||||
@ -417,7 +408,7 @@ drivers.flee = {
|
||||
print("no path found!")
|
||||
return
|
||||
end
|
||||
|
||||
--[[
|
||||
minetest.add_particle({
|
||||
pos = {x = pick.x, y = pick.y - 0.1, z = pick.z},
|
||||
velocity = vector.new(),
|
||||
@ -429,6 +420,7 @@ drivers.flee = {
|
||||
texture = "wool_red.png",
|
||||
playername = nil
|
||||
})
|
||||
--]]
|
||||
|
||||
self.path = Path(self, pick)
|
||||
if not self.path:find() then
|
||||
@ -451,7 +443,6 @@ drivers.death = {
|
||||
animation_select(self, "idle")
|
||||
end,
|
||||
step = function(self, dtime)
|
||||
animation_loop(self, dtime)
|
||||
end,
|
||||
stop = function(self)
|
||||
-- play out remaining animations
|
||||
@ -516,6 +507,15 @@ local function entity_ai_on_activate(self, staticdata)
|
||||
|
||||
local state = self.entity_ai_state
|
||||
|
||||
-- driver class, has to come before path
|
||||
if state.driver_save then
|
||||
driver = state.driver_save
|
||||
state.driver_save = nil
|
||||
else
|
||||
driver = self.script.driver
|
||||
end
|
||||
self.driver = Driver(self, driver)
|
||||
|
||||
-- path class
|
||||
if state.path_save then
|
||||
self.path = Path(self, state.path_save.target)
|
||||
@ -524,17 +524,11 @@ local function entity_ai_on_activate(self, staticdata)
|
||||
state.path_save = {}
|
||||
end
|
||||
|
||||
-- driver class
|
||||
if state.driver_save then
|
||||
driver = state.driver_save
|
||||
state.driver_save = nil
|
||||
else
|
||||
driver = self.script.driver
|
||||
end
|
||||
print("loaded: " .. self.name .. ", driver=" .. driver )
|
||||
else
|
||||
-- set initial mob driver
|
||||
driver = self.script.driver
|
||||
self.driver = Driver(self, driver)
|
||||
print("activate: " .. self.name .. ", driver=" .. driver)
|
||||
end
|
||||
|
||||
@ -542,11 +536,12 @@ local function entity_ai_on_activate(self, staticdata)
|
||||
self.object:setacceleration({x = 0, y = -9.81, z = 0})
|
||||
|
||||
-- init driver
|
||||
self.driver = Driver(self, driver)
|
||||
self.driver:start()
|
||||
end
|
||||
|
||||
local function entity_ai_on_step(self, dtime)
|
||||
animation_loop(self, dtime)
|
||||
consider_factors(self, dtime)
|
||||
self.driver:step(dtime)
|
||||
end
|
||||
|
||||
@ -624,9 +619,9 @@ local sheep_script = {
|
||||
},
|
||||
-- sound samples
|
||||
sounds = {
|
||||
chatter = {name = "sheep_chatter", gain = 1.0},
|
||||
footsteps = {name = "sheep_steps", gain = 1.0},
|
||||
hurt = {name = "sheep_hurt", gain = 1.0},
|
||||
chatter = {{name = "sheep_chatter", gain = 0.2}, {max_hear_distance = 12}},
|
||||
footsteps = {{name = "sheep_steps", gain = 0.2}, {max_hear_distance = 12}},
|
||||
hurt = {{name = "sheep_hurt", gain = 0.5}, {max_hear_distance = 18}},
|
||||
},
|
||||
-- mob script states:
|
||||
roam = {
|
||||
@ -636,7 +631,7 @@ local sheep_script = {
|
||||
attractor_nearby = "attracted",
|
||||
},
|
||||
sounds = {
|
||||
random = "chatter",
|
||||
random = "footsteps",
|
||||
},
|
||||
},
|
||||
idle = {
|
||||
@ -679,7 +674,7 @@ local sheep_script = {
|
||||
fleed_too_long = "roam",
|
||||
},
|
||||
sounds = {
|
||||
random = "hurt",
|
||||
random = "footsteps",
|
||||
},
|
||||
},
|
||||
attracted = {
|
||||
|
BIN
models/sheep.b3d
BIN
models/sheep.b3d
Binary file not shown.
5
path.lua
5
path.lua
@ -65,7 +65,7 @@ function Path:find()
|
||||
local config = self.config
|
||||
self.path = minetest.find_path(pos, vector.round(self.target), config.distance, config.jump,
|
||||
config.fall, config.algorithm)
|
||||
|
||||
--[[
|
||||
if self.path ~= nil then
|
||||
for k, v in pairs(self.path) do
|
||||
minetest.add_particle({
|
||||
@ -81,6 +81,7 @@ function Path:find()
|
||||
})
|
||||
end
|
||||
end
|
||||
--]]
|
||||
|
||||
return self.path ~= nil
|
||||
end
|
||||
@ -111,6 +112,7 @@ function Path:step(dtime)
|
||||
self.path[ii] = nil
|
||||
end
|
||||
-- done pruning
|
||||
--[[
|
||||
minetest.add_particle({
|
||||
pos = {x = v.x, y = v.y + 0.2, z = v.z},
|
||||
velocity = vector.new(),
|
||||
@ -122,6 +124,7 @@ function Path:step(dtime)
|
||||
texture = "wool_yellow.png",
|
||||
playername = nil
|
||||
})
|
||||
--]]
|
||||
local vo = {x = v.x, y = v.y - 0.5, z = v.z}
|
||||
local vec = vector.subtract(vo, pos)
|
||||
local len = vector.length(vec)
|
||||
|
12
sounds/README.txt
Normal file
12
sounds/README.txt
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
sheep_chatter.1.ogg:
|
||||
- http://www.freesound.org/people/n_audioman/sounds/321967/ n_audioman CC-BY-3.0
|
||||
sheep_chatter.2.ogg:
|
||||
- http://www.freesound.org/people/confusion_music/sounds/103442/ ion_music CC-BY-3.0
|
||||
sheep_chatter.3.ogg:
|
||||
sheep_chatter.4.ogg:
|
||||
- http://www.freesound.org/people/reinsamba/sounds/57796/ reinsamba CC-BY-3.0
|
||||
sheep_hurt.1.ogg:
|
||||
- http://www.freesound.org/people/confusion_music/sounds/103441/ confusion_music CC-BY-3.0
|
||||
sheep_steps.1.ogg:
|
||||
- http://www.freesound.org/people/newagesoup/sounds/342475/ newagesoup CC-BY-3.0
|
BIN
sounds/sheep_chatter.1.ogg
Normal file
BIN
sounds/sheep_chatter.1.ogg
Normal file
Binary file not shown.
BIN
sounds/sheep_chatter.2.ogg
Normal file
BIN
sounds/sheep_chatter.2.ogg
Normal file
Binary file not shown.
BIN
sounds/sheep_chatter.3.ogg
Normal file
BIN
sounds/sheep_chatter.3.ogg
Normal file
Binary file not shown.
BIN
sounds/sheep_chatter.4.ogg
Normal file
BIN
sounds/sheep_chatter.4.ogg
Normal file
Binary file not shown.
BIN
sounds/sheep_hurt.1.ogg
Normal file
BIN
sounds/sheep_hurt.1.ogg
Normal file
Binary file not shown.
BIN
sounds/sheep_steps.1.ogg
Normal file
BIN
sounds/sheep_steps.1.ogg
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user