var nrOfStops:Number = 4 //the four instances of 'checkpoint'
var currentStop:Number = 1;
var speed:Number = 0;
var maxspeed:Number = 30;
var minspeed:Number = 0;
var acceleration:Number = 4;
updateTangent();
function updateTangent():Void{
_root.dy = _root['i'+ (currentStop + i > nrOfStops? 1 : currentStop + 1) +'_mc' ]._y - _root['i' + currentStop +'_mc']._y;
_root.dx = _root['i'+ (currentStop + i > nrOfStops? 1 : currentStop + 1) +'_mc']._x - _root['i' + currentStop +'_mc']._x;
_root.tangent = dy/dx;
}
onEnterFrame = game;
function game():Void{
input();
move();
checkpoint();
}
function input():Void{
if(Key.isDown(Key.UP)){
speed += acceleration;
}else if (Key.isDown(Key.DOWN)){
speed -= acceleration;
}
if(speed > maxspeed){
speed = maxspeed;
}else if(speed < minspeed){
speed =minspeed;
}
}
function move():Void{
train_mc._y += speed * tangent;
train_mc._x += speed / tangent;
}
function checkpoint():Void{
if(train_mc.hitTest(_root['i'+(currentStop+1) + '_mc'])){
currentStop ++;
}
if(train_mc.hitTest(_root['i'+(1 + '_mc'])){
currentStop = 1;
}
}