LaZeR_EyE
04-24-2005, 08:24 PM
Hi
I am making a birds-eye-view rpg game where you can move the player by mouse clicks.
My problem is, i am trying to get the player to shoot at which ever direction he is facing using the CONTROL key or if you click on a button which is grouped with the player. (click button preferably).
This is the code that i am using to navigate my player:
onClipEvent (load) {
// declare and set initial variables and properties
clickSpot_x = _x;
clickSpot_y = _y;
speed = 5;
clickMode = true;
}
onClipEvent (mouseDown) {
// set position of target spot when mouse is clicked
if (clickMode && _root._xmouse>0 && _root._xmouse<950) {
clickSpot_x = _root._xmouse;
clickSpot_y = _root._ymouse;
}
}
onClipEvent (enterFrame) {
// deterimine whether target spot is the clicked spot or the mouse pointer
if (clickMode) {
gotoSpotX = clickSpot_x;
gotoSpotY = clickSpot_y;
} else{
gotoSpotX = _root._xmouse;
gotoSpotY = _root._ymouse;
}
// calculate angle of current position to target position
delta_x = _x-gotoSpotX;
delta_y = _y-gotoSpotY;
targetRotation = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
_rotation = targetRotation;
// move ninja toward the target and stop when it gets there
if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>speed) {
_y -= speed*Math.cos(_rotation*(Math.PI/180));
_x += speed*Math.sin(_rotation*(Math.PI/180));
}
}
I would be very greatful if someone can show me how to do this. thank you
I am making a birds-eye-view rpg game where you can move the player by mouse clicks.
My problem is, i am trying to get the player to shoot at which ever direction he is facing using the CONTROL key or if you click on a button which is grouped with the player. (click button preferably).
This is the code that i am using to navigate my player:
onClipEvent (load) {
// declare and set initial variables and properties
clickSpot_x = _x;
clickSpot_y = _y;
speed = 5;
clickMode = true;
}
onClipEvent (mouseDown) {
// set position of target spot when mouse is clicked
if (clickMode && _root._xmouse>0 && _root._xmouse<950) {
clickSpot_x = _root._xmouse;
clickSpot_y = _root._ymouse;
}
}
onClipEvent (enterFrame) {
// deterimine whether target spot is the clicked spot or the mouse pointer
if (clickMode) {
gotoSpotX = clickSpot_x;
gotoSpotY = clickSpot_y;
} else{
gotoSpotX = _root._xmouse;
gotoSpotY = _root._ymouse;
}
// calculate angle of current position to target position
delta_x = _x-gotoSpotX;
delta_y = _y-gotoSpotY;
targetRotation = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
_rotation = targetRotation;
// move ninja toward the target and stop when it gets there
if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>speed) {
_y -= speed*Math.cos(_rotation*(Math.PI/180));
_x += speed*Math.sin(_rotation*(Math.PI/180));
}
}
I would be very greatful if someone can show me how to do this. thank you