//捕捉鼠标划过的速度和划过的位置
function CalVelocity()
{
cursor_old_x = cursor_new_x;
cursor_old_y = cursor_new_y;
cursor_new_x = this._xmouse;
cursor_new_y = this._ymouse;
cursor_velocity = int(Math.sqrt(Math.pow(cursor_new_x - cursor_old_x, 2) + Math.pow(cursor_new_y - cursor_old_y, 2)));
} // End of the function
//判断鼠标划过地速度,分别为强、中、弱
function CalPoints()
{
if (cursor_velocity > VEL_HIT_LIMIT)
{
divide_num = DIVIDE_NUM_STRIKE;
}
else if (cursor_velocity > VEL_SAL_LIMIT)
{
divide_num = DIVIDE_NUM_HIT;
}
else
{
divide_num = DIVIDE_NUM_SAL;
} // end else if
xdivide = (cursor_new_x - cursor_old_x) / divide_num;
ydivide = (cursor_new_y - cursor_old_y) / divide_num;
for (i = 0; i < divide_num; i++)
{
xpoint_array[i] = cursor_old_x + xdivide * (i + 1);
ypoint_array[i] = cursor_old_y + ydivide * (i + 1);
} // end of for
} // End of the function
//播放鼠标动作所触发的相应场景
function StartMotion()
{
_root.Motion_all.gotoAndPlay(togo);
} // End of the function
//判断鼠标划过的位置,分别对应场景中的对象的头、手、脚
function HitCheck()
{
for (i = 0; i < divide_num; i++)
{
if (Area_Head_Left.hitTest(xpoint_array[i], ypoint_array[i], true))
{
if (!Area_Head_Left.hitTest(cursor_old_x, cursor_old_y, true))
{
if (xpoint_array[i] > cursor_old_x)
{
HitArea = "Area_Head_Left";
break;
} // end if
} // end if
continue;
} // end if
if (Area_Head_Right.hitTest(xpoint_array[i], ypoint_array[i], true))
{
if (!Area_Head_Right.hitTest(cursor_old_x, cursor_old_y, true))
{
if (xpoint_array[i] < cursor_old_x)
{
HitArea = "Area_Head_Right";
break;
} // end if
} // end if
continue;
} // end if
if (Area_Arm_Left.hitTest(xpoint_array[i], ypoint_array[i], true))
{
if (!Area_Arm_Left.hitTest(cursor_old_x, cursor_old_y, true))
{
if (xpoint_array[i] > cursor_old_x)
{
HitArea = "Area_Arm_Left";
break;
} // end if
} // end if
continue;
} // end if
if (Area_Arm_Right.hitTest(xpoint_array[i], ypoint_array[i], true))
{
if (!Area_Arm_Right.hitTest(cursor_old_x, cursor_old_y, true))
{
if (xpoint_array[i] < cursor_old_x)
{
HitArea = "Area_Arm_Right";
break;
} // end if
} // end if
continue;
} // end if
if (Area_Leg_Left.hitTest(xpoint_array[i], ypoint_array[i], true))
{
if (!Area_Leg_Left.hitTest(cursor_old_x, cursor_old_y, true))
{
if (xpoint_array[i] > cursor_old_x)
{
HitArea = "Area_Leg_Left";
break;
} // end if
} // end if
continue;
} // end if
if (Area_Leg_Right.hitTest(xpoint_array[i], ypoint_array[i], true))
{
if (!Area_Leg_Right.hitTest(cursor_old_x, cursor_old_y, true))
{
if (xpoint_array[i] < cursor_old_x)
{
HitArea = "Area_Leg_Right";
break;
} // end if
} // end if
} // end if
} // end of for
} // End of the function
if (_root.d_display)
{
_level100.on_off.gotoAndStop("on");
}
else
{
_level100.on_off.gotoAndStop("off");
} // end else if
stop ();
//隐藏用来捕捉鼠标动作的对象。
Area_Head_Left._visible = false;
Area_Head_Right._visible = false;
Area_Arm_Left._visible = false;
Area_Arm_Right._visible = false;
Area_Leg_Left._visible = false;
Area_Leg_Right._visible = false;
//初始化鼠标的参数。
cursor_old_x = 0;
cursor_old_y = 0;
cursor_new_x = 0;
cursor_new_y = 0;
cursor_velocity = 0;
HitArea = "";
divide_num = 1;
xpoint_array = new Array();
ypoint_array = new Array();
init = false;
//定义一些变量,分别用来判断鼠标是否以比较慢、中等、比较快的速度划过对象。
VEL_SAL_LIMIT = 70;
VEL_HIT_LIMIT = 180;
DIVIDE_NUM_STRIKE = 30;
DIVIDE_NUM_HIT = 24;
DIVIDE_NUM_SAL = 12;
//整个场景的启动函数,不断的循环,不断地对鼠标动作产生响应
onEnterFrame = function ()
{
CalVelocity();
CalPoints();
HitCheck();
if (!init)
{
HitArea = "";
init = true;
} // end if
switch (HitArea)
{
case "Area_Head_Left":
{
if (divide_num == DIVIDE_NUM_SAL)
{
togo = "TL_w";
}
else if (divide_num == DIVIDE_NUM_HIT)
{
togo = "TL_m";
}
else if (divide_num == DIVIDE_NUM_STRIKE)
{
togo = "TL_s";
} // end else if
StartMotion();
HitArea = "";
break;
}
case "Area_Head_Right":
{
if (divide_num == DIVIDE_NUM_SAL)
{
togo = "TR_w";
}
else if (divide_num == DIVIDE_NUM_HIT)
{
togo = "TR_m";
}
else if (divide_num == DIVIDE_NUM_STRIKE)
{
togo = "TR_s";
} // end else if
StartMotion();
HitArea = "";
break;
}
case "Area_Arm_Left":
{
if (divide_num == DIVIDE_NUM_SAL)
{
togo = "ML_w";
}
else if (divide_num == DIVIDE_NUM_HIT)
{
togo = "ML_s";
}
else if (divide_num == DIVIDE_NUM_STRIKE)
{
togo = "ML_s";
} // end else if
StartMotion();
HitArea = "";
break;
}
case "Area_Arm_Right":
{
if (divide_num == DIVIDE_NUM_SAL)
{
togo = "MR_w";
}
else if (divide_num == DIVIDE_NUM_HIT)
{
togo = "MR_s";
}
else if (divide_num == DIVIDE_NUM_STRIKE)
{
togo = "MR_s";
} // end else if
StartMotion();
HitArea = "";
break;
}
case "Area_Leg_Left":
{
if (divide_num == DIVIDE_NUM_SAL)
{
togo = "BL_w";
}
else if (divide_num == DIVIDE_NUM_HIT)
{
togo = "B_m";
}
else if (divide_num == DIVIDE_NUM_STRIKE)
{
togo = "BL_s";
} // end else if
StartMotion();
HitArea = "";
break;
}
case "Area_Leg_Right":
{
if (divide_num == DIVIDE_NUM_SAL)
{
togo = "BR_w";
}
else if (divide_num == DIVIDE_NUM_HIT)
{
togo = "B_m";
}
else if (divide_num == DIVIDE_NUM_STRIKE)
{
togo = "BR_s";
} // end else if
StartMotion();
HitArea = "";
break;
}
} // End of switch
};