求助帖,200毫秒内双击两次方向键进入奔跑状态
部分步事件代码
/// @description 人物状态更新
#region 按键输入
CtrlArr[PRO_CTRL.Null] = keyboard_check(vk_nokey);
CtrlArr[PRO_CTRL.Left] = keyboard_check(vk_left);
CtrlArr[PRO_CTRL.Right] = keyboard_check(vk_right);
CtrlArr[PRO_CTRL.Up] = keyboard_check(vk_up);
CtrlArr[PRO_CTRL.Down] = keyboard_check(vk_down);
CtrlArr[PRO_CTRL.Fight] = keyboard_check(ord("X"));
CtrlArr[PRO_CTRL.DeputyFight] = keyboard_check_pressed(ord("Z"));
CtrlArr[PRO_CTRL.Elude] = keyboard_check_pressed(vk_space);
CtrlArr[PRO_CTRL.DeputyAction] = keyboard_check_pressed(ord("V"));
CtrlArr[PRO_CTRL.Jump] = keyboard_check_pressed(ord("C"));
CtrlArr[PRO_CTRL.Rest] = keyboard_check_pressed(ord("E"));
#endregion
JumpTrigger = CtrlArr[PRO_CTRL.Jump];//跳跃触发
IsTop = place_meeting(x,y-1,obj_land);//头顶
IsGround = place_meeting(x,y+1,obj_land);//地面
#region 垂直状态判定
switch (InitializeYState)
{
case PRO_YACTION.Stop :
if (!IsTop && JumpTrigger && (JumpMin < JumpMax))//跳跃按键和跳跃次数
{
InitializeYState = PRO_YACTION.Skip;
}else if (!IsGround)
{
InitializeYState = PRO_YACTION.Fall;
}
break;
case PRO_YACTION.Skip :
{
InitializeYState = PRO_YACTION.Rise;//上升状态
}
break;
case PRO_YACTION.Rise :
{
if (IsTop)
{
InitializeYState = PRO_YACTION.Stop;
}else if (!IsTop && JumpTrigger && (JumpMin < JumpMax))//按下跳跃且跳跃次数大于可跳跃次数
{
InitializeYState = PRO_YACTION.Skip;
}else if (Vsp >= 0)
{
InitializeYState = PRO_YACTION.Fall;//Y向上大于0,大于零在空中
}
}
break;
case PRO_YACTION.Fall :
{
if (JumpTrigger && (JumpMin < JumpMax))//按下跳跃且跳跃次数大于可跳跃次数
{
InitializeYState = PRO_YACTION.Skip;
}else if (IsGround)
{
InitializeYState = PRO_YACTION.Stop;
}
}
break;
}
#endregion
LeftHold = CtrlArr[PRO_CTRL.Left];
RightHold = CtrlArr[PRO_CTRL.Right];
SquatHold = CtrlArr[PRO_CTRL.Down];
LeftMeet = place_meeting(x-1,y,obj_land);
RightMeet = place_meeting(x+1,y,obj_land);
#region 水平状态判定
switch (InitializeXState)
{
case PRO_XACTION.Stand :
{
if (!LeftMeet && LeftHold && !RightHold && IsGround )//左边没碰到仅左键按下
{
InitializeXState = PRO_XACTION.LeftRush;
......
夜太深,脑子转不过来.如果有志同道合的人士,请赐教
左右移动,C跳跃,下蹲,X攻击.问双击方向键的想法分享.
# ====规则====
# 动作组 <== 条件组,当条件组满足时执行动作组;
# *verb(…) 表示 函数断言。
# verb(…) 表示状态断言。
# 在条件组里, verb(…) 表示当状态断言成立,~verb(…) 表示当状态断言不成立。
# 在动作组里,verb(…) 表示使状态断言成立,~verb(…) 表示使状态断言不成立。
# verb(x) 表示对确定的x, 使verb(x) 成立。
# verb(X) 表示至少存在一个a,a属于X, 使 verb(a) 成立。
#
# ====方案 ====
# start: idle
==> state(idle);
#idle —> walk
~state(idle) & state(walk) & run_threshold(T+0.2) <== state(idle) & *click(X) & *is_dir_key (X) & *time(T);
#time elapse
~run_threshold(X) <== state(walk) & run_threshold(X) & *time(T) & T > X;
#walk —> run
~state(walk) &state(run) & ~run_threshold(T) <== state(walk) & *click(Y) & *is_dir_key(Y) & run_threshold(T);
#direction key
pressing_dir_key(X) <== *pressing_key(X) & *is_dir_key(X) & ~pressing_dir_key(Y)
~pressing_dir_key(Y) & pressing_dir_key(X) <== *pressing_key(X) & *is_dir_key(X) & pressing_dir_key(Y);
#run —> idle
~state(run) & state(idle) <== state(run) & ~pressing_dir_key(X);
============
分析了一下。
希望可以给你启发。
FSM可以解决