forked from VoxeLibre/VoxeLibre
Add in state switch and state execution for mobs
This commit is contained in:
parent
626c30de6d
commit
94ca7e8b89
|
@ -305,6 +305,7 @@ function mobs:register_mob(name, def)
|
|||
backface_culling = true,
|
||||
walk_timer = 0,
|
||||
stand_timer = 0,
|
||||
wandering = true,
|
||||
--end j4i stuff
|
||||
|
||||
-- MCL2 extensions
|
||||
|
|
|
@ -7,24 +7,44 @@ local minetest_get_item_group = minetest.get_item_group
|
|||
local minetest_get_node = minetest.get_node
|
||||
|
||||
|
||||
local state_list_wandering = {"stand", "walk"}
|
||||
|
||||
|
||||
-- execute current state (stand, walk, run, attacks)
|
||||
-- returns true if mob has died
|
||||
local do_states = function(self, dtime)
|
||||
local yaw = self.object:get_yaw() or 0
|
||||
|
||||
-- state switching logic (stand, walk, run, attacks)
|
||||
local state_switch = function(self, dtime)
|
||||
self.state_timer = self.state_timer - dtime
|
||||
|
||||
if self.state_timer <= 0 then
|
||||
self.state_timer = math.random(0,2) + math.random()
|
||||
--let's do a random state
|
||||
self.yaw = (math_random() * (math.pi * 2))
|
||||
|
||||
mobs.set_animation(self, "walk")
|
||||
if self.wandering and self.state_timer <= 0 then
|
||||
self.state_timer = math.random(4,10) + math.random()
|
||||
self.state = state_list_wandering[math.random(1,#state_list_wandering)]
|
||||
end
|
||||
end
|
||||
|
||||
mobs.set_velocity(self,1)
|
||||
-- states are executed here (goto would have been helpful :<)
|
||||
local state_execution = function(self,dtime)
|
||||
|
||||
local yaw = self.object:get_yaw() or 0
|
||||
|
||||
if self.state == "standing" then
|
||||
|
||||
print("stand")
|
||||
|
||||
elseif self.state == "walking" then
|
||||
|
||||
print("walk")
|
||||
|
||||
elseif self.state == "run" then
|
||||
|
||||
print("run")
|
||||
|
||||
elseif self.state == "attack" then
|
||||
|
||||
print("attack")
|
||||
|
||||
end
|
||||
|
||||
--mobs.set_animation(self, state_list_wandering[math.random(1,#state_list_wandering)])
|
||||
--mobs.set_velocity(self,1)
|
||||
--self.yaw = (math_random() * (math.pi * 2))
|
||||
end
|
||||
|
||||
|
||||
|
@ -71,7 +91,7 @@ mobs.mob_step = function(self, dtime)
|
|||
--end
|
||||
|
||||
|
||||
do_states(self, dtime)
|
||||
state_switch(self, dtime)
|
||||
|
||||
jump_check(self)
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ mobs.mob_staticdata = function(self)
|
|||
return ""-- nil
|
||||
end
|
||||
--]]
|
||||
|
||||
self.remove_ok = true
|
||||
self.attack = nil
|
||||
self.following = nil
|
||||
|
@ -53,11 +54,9 @@ end
|
|||
mobs.mob_activate = function(self, staticdata, def, dtime)
|
||||
|
||||
-- remove monsters in peaceful mode
|
||||
if self.type == "monster"
|
||||
and minetest_settings:get_bool("only_peaceful_mobs", false) then
|
||||
if self.type == "monster" and minetest_settings:get_bool("only_peaceful_mobs", false) then
|
||||
mcl_burning.extinguish(self.object)
|
||||
self.object:remove()
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -70,6 +69,11 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
|
|||
end
|
||||
end
|
||||
|
||||
--set up wandering
|
||||
if not self.wandering then
|
||||
self.wandering = true
|
||||
end
|
||||
|
||||
-- select random texture, set model and size
|
||||
if not self.base_texture then
|
||||
|
||||
|
|
Loading…
Reference in New Issue