forked from MineClone5/MineClone5
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,
|
backface_culling = true,
|
||||||
walk_timer = 0,
|
walk_timer = 0,
|
||||||
stand_timer = 0,
|
stand_timer = 0,
|
||||||
|
wandering = true,
|
||||||
--end j4i stuff
|
--end j4i stuff
|
||||||
|
|
||||||
-- MCL2 extensions
|
-- MCL2 extensions
|
||||||
|
|
|
@ -7,24 +7,44 @@ local minetest_get_item_group = minetest.get_item_group
|
||||||
local minetest_get_node = minetest.get_node
|
local minetest_get_node = minetest.get_node
|
||||||
|
|
||||||
|
|
||||||
|
local state_list_wandering = {"stand", "walk"}
|
||||||
|
|
||||||
|
|
||||||
-- execute current state (stand, walk, run, attacks)
|
-- state switching logic (stand, walk, run, attacks)
|
||||||
-- returns true if mob has died
|
local state_switch = function(self, dtime)
|
||||||
local do_states = function(self, dtime)
|
self.state_timer = self.state_timer - dtime
|
||||||
|
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
|
||||||
|
|
||||||
|
-- states are executed here (goto would have been helpful :<)
|
||||||
|
local state_execution = function(self,dtime)
|
||||||
|
|
||||||
local yaw = self.object:get_yaw() or 0
|
local yaw = self.object:get_yaw() or 0
|
||||||
|
|
||||||
self.state_timer = self.state_timer - dtime
|
if self.state == "standing" then
|
||||||
|
|
||||||
if self.state_timer <= 0 then
|
print("stand")
|
||||||
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")
|
elseif self.state == "walking" then
|
||||||
|
|
||||||
|
print("walk")
|
||||||
|
|
||||||
|
elseif self.state == "run" then
|
||||||
|
|
||||||
|
print("run")
|
||||||
|
|
||||||
|
elseif self.state == "attack" then
|
||||||
|
|
||||||
|
print("attack")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
mobs.set_velocity(self,1)
|
--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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +91,7 @@ mobs.mob_step = function(self, dtime)
|
||||||
--end
|
--end
|
||||||
|
|
||||||
|
|
||||||
do_states(self, dtime)
|
state_switch(self, dtime)
|
||||||
|
|
||||||
jump_check(self)
|
jump_check(self)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ mobs.mob_staticdata = function(self)
|
||||||
return ""-- nil
|
return ""-- nil
|
||||||
end
|
end
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
self.remove_ok = true
|
self.remove_ok = true
|
||||||
self.attack = nil
|
self.attack = nil
|
||||||
self.following = nil
|
self.following = nil
|
||||||
|
@ -53,11 +54,9 @@ end
|
||||||
mobs.mob_activate = function(self, staticdata, def, dtime)
|
mobs.mob_activate = function(self, staticdata, def, dtime)
|
||||||
|
|
||||||
-- remove monsters in peaceful mode
|
-- remove monsters in peaceful mode
|
||||||
if self.type == "monster"
|
if self.type == "monster" and minetest_settings:get_bool("only_peaceful_mobs", false) then
|
||||||
and minetest_settings:get_bool("only_peaceful_mobs", false) then
|
|
||||||
mcl_burning.extinguish(self.object)
|
mcl_burning.extinguish(self.object)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,6 +69,11 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--set up wandering
|
||||||
|
if not self.wandering then
|
||||||
|
self.wandering = true
|
||||||
|
end
|
||||||
|
|
||||||
-- select random texture, set model and size
|
-- select random texture, set model and size
|
||||||
if not self.base_texture then
|
if not self.base_texture then
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue