# Calculate Kilometers

**URL:** <https://forum.kirupa.com/t/calculate-kilometers/259845>\
**Category:** flash\
**Created:** [May 9, 2008, 9:59am UTC](https://forum.kirupa.com/t/calculate-kilometers/259845 "2008-05-09T09:59:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikrant29nov](https://avatars.discourse-cdn.com/v4/letter/v/eb9ed0/32.png) [@vikrant29nov](https://forum.kirupa.com/u/vikrant29nov)\
**Post date:** [May 9, 2008, 9:59am UTC](https://forum.kirupa.com/t/calculate-kilometers/259845/1 "2008-05-09T09:59:01Z")

</div>

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.

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

```

}

---

<div class="post-metadata">

**Author:** ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)\
**Post date:** [May 9, 2008, 6:33pm UTC](https://forum.kirupa.com/t/calculate-kilometers/259845/2 "2008-05-09T18:33:43Z")

</div>

how far is a KM? since your using px you can say 1km = 90px or something to that affect and eachtime you move  
movedDistance = movedDistance+3 //3 is howmany px it moves  
then km = movedDistance/90  
its all dependent on the scale your using…  
if you have 20fps and you hold right for 1 second it moves 3px\*20 or 60px so just decide how many px in a km and use it

---

<div class="post-metadata">

**Author:** ![vikrant29nov](https://avatars.discourse-cdn.com/v4/letter/v/eb9ed0/32.png) [@vikrant29nov](https://forum.kirupa.com/u/vikrant29nov)\
**Post date:** [May 12, 2008, 4:32am UTC](https://forum.kirupa.com/t/calculate-kilometers/259845/3 "2008-05-12T04:32:44Z")

</div>

Current fps is 20 and and the distance travelled 80px = 1km
