WhiteEngine-专注图形渲染与游戏引擎技术的网站

新浪微薄腾讯微薄

最新碎语:暂无碎语

您的位置:WhiteEngine-专注图形渲染与游戏引擎技术的网站 >C#与Lua> 位运算实现复合状态

位运算实现复合状态

00000000

00000010

00000100

00001000

00010000

00100000

01000000

10000000


&逻辑判断状态是否在当前状态里面

|逻辑或为为增加状态

^异或为减状态,但只能减当前有的状态,必须先判断状态是否存在,或者复合状态是否存在,可以一起减


逻辑或

逻辑与

异或

真1,假0

与:同为真则为真,否者为假

或:一个为真则为真,否者为假,

异或:异为真,同为假

00000000

00000010

&

00000010

00000000

00000000



例子:

local Fight_State_Normal = 0 -- 普通
local Fight_State_FastMove = 1 -- 快速移动
local Fight_State_Jifei = 2 -- 击飞
local Fight_State_Jitui = 4 -- 击退
local Fight_State_Dingshen = 8 -- 定身
local Fight_State_Xuanyun = 16 -- 眩晕
local Fight_State_Wudi = 32 -- 无敌
local Fight_State_Hunshui = 64 -- 昏睡
local Fight_State_Bati = 128 -- 霸体
local Fight_State_Chenmo = 256 -- 沉默
--local Fight_State_UseSkill = 1024, -- 使用技能
--local Fight_State_Yinshen = 64, -- 隐身

--改变状态
function ChangeFightState(sceneid,playerid,curstate,state)
local final_state = Fight_State_Normal

if( IsDead(sceneid,playerid) ) then
return false
elseif( curstate == state ) then
return false
elseif( curstate == Fight_State_Normal or state == Fight_State_Normal) then
final_state = state
elseif( curstate == Fight_State_Wudi ) then -- 无敌
return false
elseif( curstate == Fight_State_Bati ) then -- 霸体
if(state == Fight_State_Wudi) then
final_state = Fight_State_Wudi
else
return false
end
elseif( curstate == Fight_State_Jifei or curstate == Fight_State_Jitui or curstate == Fight_State_FastMove ) then -- 击飞击退快速位移
return false
elseif( curstate == Fight_State_Xuanyun ) then -- 眩晕
if( state == Fight_State_Jifei or state == Fight_State_Jitui ) then
final_state = state
else
return false
end
elseif( curstate == Fight_State_Hunshui ) then -- 昏睡
if( state == Fight_State_Jifei or state == Fight_State_Jitui or state == Fight_State_Xuanyun ) then
final_state = state
else
return false
end
elseif( BitOperateYu(curstate,Fight_State_Chenmo) or BitOperateYu(curstate,Fight_State_Dingshen) ) then -- 沉默 定身 同优先级
if( state == Fight_State_Jifei or state == Fight_State_Jitui or state == Fight_State_Xuanyun ) then
final_state = state
elseif( state == Fight_State_Chenmo or state == Fight_State_Dingshen) then
final_state = BitOperateHuo(curstate,state)
else
return false
end
else

end

Change_Fight_State(sceneid,playerid,final_state)
return true
end



---

转载请注明本文标题和链接:《位运算实现复合状态

分享到:

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交