跪拜求助 击打小人flash的代码测试没有反应
这是源代码,应该是在flash8里做的stop();
VEL_SAL_LIMIT = 70;
VEL_HIT_LIMIT = 180;
DIVIDE_NUM_STRIKE = 30;
DIVIDE_NUM_HIT = 24;
DIVIDE_NUM_SAL = 12;
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.0;
cursor_old_y = 0.0;
cursor_new_x = 0.0;
cursor_new_y = 0.0;
cursor_velocity = 0.0;
HitArea = "";
divide_num = 1;
xpoint_array = new Array();
ypoint_array = new Array();
init = false;
function CalVelocity() {
cursor_old_x = cursor_new_x;
cursor_old_y = cursor_new_y;
cursor_new_x = int(this._xmouse);
cursor_new_y = int(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)));
}
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;
}
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 = cursor_old_x+(xdivide*(i+1));
ypoint_array = cursor_old_y+(ydivide*(i+1));
}
}
function HitCheck() {
for (i=0; i<divide_num; i++) {
if (Area_Head_Left.hitTest(xpoint_array, ypoint_array, true)) {
if (!Area_Head_Left.hitTest(cursor_old_x, cursor_old_y, true)) {
if (xpoint_array>cursor_old_x) {
HitArea = "Area_Head_Left";
break;
}
}
} else if (Area_Head_Right.hitTest(xpoint_array, ypoint_array, true)) {
if (!Area_Head_Right.hitTest(cursor_old_x, cursor_old_y, true)) {
if (xpoint_array<cursor_old_x) {
HitArea = "Area_Head_Right";
break;
}
}
} else if (Area_Arm_Left.hitTest(xpoint_array, ypoint_array, true)) {
if (!Area_Arm_Left.hitTest(cursor_old_x, cursor_old_y, true)) {
if (xpoint_array>cursor_old_x) {
HitArea = "Area_Arm_Left";
break;
}
}
} else if (Area_Arm_Right.hitTest(xpoint_array, ypoint_array, true)) {
if (!Area_Arm_Right.hitTest(cursor_old_x, cursor_old_y, true)) {
if (xpoint_array<cursor_old_x) {
HitArea = "Area_Arm_Right";
break;
}
}
} else if (Area_Leg_Left.hitTest(xpoint_array, ypoint_array, true)) {
if (!Area_Leg_Left.hitTest(cursor_old_x, cursor_old_y, true)) {
if (xpoint_array>cursor_old_x) {
HitArea = "Area_Leg_Left";
break;
}
}
} else if (Area_Leg_Right.hitTest(xpoint_array, ypoint_array, true)) {
if (!Area_Leg_Right.hitTest(cursor_old_x, cursor_old_y, true)) {
if (xpoint_array<cursor_old_x) {
HitArea = "Area_Leg_Right";
break;
}
}
}
}
}
function StartMotion() {
_root.Motion_all.gotoAndPlay(togo);
}
onEnterFrame = function () {
CalVelocity();
CalPoints();
HitCheck();
if (!init) {
HitArea = "";
init = true;
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
StartMotion();
HitArea = "";
break;
}
};
下面是我用cs3的2.0做的,测试hitTest这步时没反应,求达人帮忙~
stop();
w_v = 70;
s_v = 180;
s_h = 30;
m_h = 24;
w_h = 12;
head_left._visible = false;
head_right._visible = false;
arm_left._visible = false;
arm_right._visible = false;
leg_left._visible = false;
leg_right._visible = false;
m_o_x = 0.0;
m_o_y = 0.0;
m_n_x = 0.0;
m_n_y = 0.0;
m_v = 0.0;
hit_eara = "";
fj = 1;
xpoint_array = new Array();
ypoint_array = new Array();
ini = false;
function jsms() {
m_o_x = m_n_x;
m_o_y = m_n_y;
m_n_x = int(this._xmouse);
m_n_y = int(this._ymouse);
m_v = int(Math.sqrt(Math.pow(m_n_x-m_o_x, 2)+Math.pow(m_n_y-m_o_y, 2)));
}
function poinv() {
if (m_v>s_v) {
fj = s_h;
} else if (m_v>w_v) {
fj = m_h;
} else {
fj = w_h;
}
xfj = (m_n_x-m_o_x)/fj;
yfj = (m_n_y-m_o_y)/fj;
for (i=0; i<fj; i++) {
xpoint_array = m_d_x+xfj*(i+1);
ypoint_array = m_d_y+xfj*(i+1);
}
}
function hit() {
for (i=0; i<fj; i++) {
if (head_left.hitTest(xpoint_array, ypoint_array, true)) {
if (!head_left.hitTest(m_o_x, m_o_y, true)) {
if (xpoint_array>m_o_x) {
hit_eara = "head_left";
break;
}
}
} else if (arm_left.hitTest(xpoint_array, ypoint_array, true)) {
if (!arm_left.hitTest(m_o_x, m_o_y, true)) {
if (xpoint_array>m_o_x) {
hit_eara = "arm_left";
break;
}
}
} else if (leg_left.hitTest(xpoint_array, ypoint_array, true)) {
if (!leg_left.hitTest(m_o_x, m_o_y, true)) {
if (xpoint_array>m_o_x) {
hit_eara = "leg_left";
break;
}
}
} else if (head_right.hitTest(xpoint_array, ypoint_array, true)) {
if (!head_right.hitTest(m_o_x, m_o_y, true)) {
if (xpoint_array<m_o_x) {
hit_eara = "head_right";
break;
}
}
} else if (arm_right.hitTest(xpoint_array, ypoint_array, true)) {
if (!arm_right.hitTest(m_o_x, m_o_y, true)) {
if (xpoint_array<m_o_x) {
hit_eara = "arm_right";
break;
}
}
} else if (leg_right.hitTest(xpoint_array, ypoint_array, true)) {
if (!leg_right.hitTest(m_o_x, m_o_y, true)) {
if (xpoint_array<m_o_x) {
hit_eara = "leg_right";
break;
}
}
}
}
}
function action() {
_root.motion_mc.gotoAndPlay(togo);
}
onEnterFrame = function () {
jsms();
poinv();
hit();
if (!ini) {
hit_eara = "";
ini = true;
}
switch (hit_eara) {
case "head_left" :
if (fj == w_h) {
togo = "L_h_w";
} else if (fj == m_h) {
togo = "L_h_m";
} else if (fj=s_h) {
togo = "L_h_s";
}
action();
hit_eara = "";
break;
case "head_right" :
if (fj == w_h) {
togo = "R_h_w";
} else if (fj == m_h) {
togo = "R_h_m";
} else if (fj=s_h) {
togo = "R_h_s";
}
action();
hit_eara = "";
break;
case "arm_left" :
if (fj == w_h) {
togo = "L_a_w";
} else if (fj == m_h) {
togo = "L_a_m";
} else if (fj=s_h) {
togo = "L_a_s";
}
action();
hit_eara = "";
break;
case "arm_right" :
if (fj == w_h) {
togo = "R_a_w";
} else if (fj == m_h) {
togo = "R_a_m";
} else if (fj=s_h) {
togo = "R_a_s";
}
action();
hit_eara = "";
break;
case "leg_left" :
if (fj == w_h) {
togo = "L_l_w";
} else if (fj == m_h) {
togo = "l_m";
} else if (fj=s_h) {
togo = "L_l_s";
}
action();
hit_eara = "";
break;
case "right_left" :
if (fj == w_h) {
togo = "R_l_w";
} else if (fj == m_h) {
togo = "l_m";
} else if (fj=s_h) {
togo = "R_l_s";
}
action();
hit_eara = "";
break;
}
}; LZ还是把整个fla发上来吧。
或是附件或是网络硬盘dropbox.com
或者是去http://www.flash8.net求助,这里只有我一个人,有时忙就顾不及了。 谢谢哈,我传上来,帮我看看~
页:
[1]