Distance Travelled

My car is moving on a maze.

The movement of car is through Arrow keys.

**I have to calculate KM. **i.e., the distance travelled.

Current frame rate is 12 and 1km =40px

Please help.

Here is the script

onClipEvent (enterFrame) {

    with (_root.car) {
        if (Key.isDown(40)) {
            _y = _y+3;
         
        }
        // end if               
        if (Key.isDown(38)) {
            _y = _y-3;
          
        }
        // end if               
        if (Key.isDown(37)) {
            _x = _x-3;
          
        }
        // end if               
        if (Key.isDown(39)) {
            _x = _x+3;
         
        }
        // end if               
        // end if 
        if (walls.hitTest(getBounds(_root).xMax, _y, true)) {
            _x = _x-3;
        }
        // end if               
        if (walls.hitTest(getBounds(_root).xMin, _y, true)) {
            _x = _x+3;
        }
        // end if               
        if (walls.hitTest(_x, getBounds(_root).yMax, true)) {
            _y = _y-3;
        }
        // end if               
        if (walls.hitTest(_x, getBounds(_root).yMin, true)) {
            _y = _y+3;
        }
        // end if               
        if (_root.goal.hitTest(_x, getBounds(_root).yMax, true)) {
            _root.gotoAndStop(3);
        }
        // end if               
    }
    // End of with

}

Can any one help me…

search the forums bag head:P

pythagorus is your friend

Here’s a hint, the distance traveled each frame is equal to:

xDif = Math.abs(old_x_position-this._x);
yDif = Math.abs(old_y_position-this._y);
distance = Math.sqrt((xDif*xDif)+(yDif*yDif))

Thanks for the hint.

[quote=ShadowViper;2328688]Here’s a hint, the distance traveled each frame is equal to:

xDif = Math.abs(old_x_position-this._x);
yDif = Math.abs(old_y_position-this._y);
distance = Math.sqrt((xDif*xDif)+(yDif*yDif))

[/quote]

Can you give me the complete code.

I realize that the forums are a place to ask for help, but they aren’t a place for people to make your game for you. Look up some source code examples on the net, search the forums and experiment. I learned this way and I feel relatively comfortable with my grasp of Flash. If you really want to learn how to use Flash, you’ll be able to do it this way. If all you want is for us to make your game, then sorry I think your out of luck.

Not trying to be too harsh, but the best way to learn is through doing. IF you do come here and show that you have taken what I gave you and tried to apply it, I’ll be happy to help you fix problems and work out bugs.

~Cody

I apologize for not showing the code and simply asking for help.

Here is the code:

onClipEvent (enterFrame) {
with (_root.car) {
xDif = Math.abs(old_x_position-this._x);
yDif = Math.abs(old_y_position-this._y);
distance = Math.sqrt((xDifxDif)+(yDifyDif));
if (Key.isDown(40)) {
_y = _y+3;
trace(_root.i);
_root.srt._visible = false;
}
// end if
if (Key.isDown(38)) {
_y = _y-3;
}
// end if
if (Key.isDown(37)) {
_x = _x-3;
}
// end if
if (Key.isDown(39)) {
_x = _x+3;
}
// end if
}
}