Today I make camera and states for hero/enemies.They can be in 6 states.(idle,walk,make_hit,block,get_hit,dead). I make a module that encapsulation all logic of changing states.It make very simple to change states logic in future, or add more states.
State have 2 parameters id and prioritet.
M.state_idle={id=0,prior=0}
M.state_walk={id=1,prior=1}
M.state_make_hit={id=2,prior=2}
M.state_block={id=3,prior=2}
M.state_end_block={id=4,prior=2} --work only if current_state == block
M.state_get_hit={id=5,prior=3}
M.state_dead={id=99,prior=99}
...
function M:change_state(state_id)
local state=id_to_state(state_id)
if(state==M.state_end_block and self.current_state==M.state_block) then
return M.set_state(self,M.state_idle)
elseif(state.prior>self.current_state.prior) then
return M.set_state(self,state)
else
return false
end
end
...
Tomorrow I want to add enemy and write simple ai.