Frame 1
grav = 0.2;
car = new Object();
car.spd = 0.2;
car.max_spd = 10;
car.acc = 0;
car.yv = 0;
car.xv = 0;
car.w_rad = 15;
car.w_frc = 0.98;
car.fric = 0.99;
car.w_dis = 53;
car.w_cir = (2 * car.w_rad) * Math.PI;
w1.spd = 0;
w1.xv = 0;
w1.yv = 0;
w1.slope = 0;
w2.spd = 0;
w2.xv = 0;
w2.yv = 0;
w2.slope = 0;
w1.x = w1._x;
w2.x = w2._x;
frame.swapDepths(2);
track_dis = 10000;
track_int = 200;
vects = track_dis / track_int;
g_height = 340;
g_rand = 50;
flag.swapDepths(_root.getNextHighestDepth());
sflag.swapDepths(_root.getNextHighestDepth());
xs = 0;
alpha = (Math.PI/180);
generate_terrain = function () {
old_height = (g_height + random(g_rand)) - random(g_rand);
i = 0;
while (i < vects) {
rand_h = (g_height + random(g_rand)) - random(g_rand);
this["v" + i] = {p0:{x:i * track_int, y:old_height}, p1:{x:(i + 1) * track_int, y:rand_h}};
old_height = rand_h;
i++;
}
this["v" + (vects - 3)].p1.y = this["v" + (vects - 3)].p0.y - 20;
this["v" + (vects - 2)].p0.y = this["v" + (vects - 3)].p1.y;
this["v" + (vects - 2)].p1.y = this["v" + (vects - 2)].p0.y - 40;
this["v" + (vects - 1)].p0.y = this["v" + (vects - 2)].p1.y;
this["v" + (vects - 1)].p1.y = this["v" + (vects - 1)].p0.y - 60;
fv = this["v" + (vects - 3)];
flag._rotation = Math.atan2(fv.p1.y - fv.p0.y, fv.p1.x - fv.p0.x) / (Math.PI/180);
flag.x = fv.p0.x;
slag.x = v2.p0.x;
};
draw_ground = function () {
line = _root.createEmptyMovieClip("line", 1);
line.lineStyle(1, 0, 100);
line.beginFill(6710886, 100);
if (vector_mn < 0) {
vector_mn = 0;
line.moveTo(v0.p0.x - xs, 400);
}
if (vector_mx >= vects) {
vector_mx = vects - 1;
}
line.moveTo(this["v" + vector_mn].p0.x - xs, 400);
i = vector_mn;
while (i <= vector_mx) {
v = this["v" + i];
line.lineTo(v.p0.x - xs, v.p0.y);
line.lineTo(v.p1.x - xs, v.p1.y);
i++;
}
line.lineTo(this["v" + vector_mx].p1.x - xs, 400);
line.endFill();
flag._y = fv.p0.y;
slag._y = v2.p0.y;
};
onMouseDown = function () {
drag_vect = Math.round((xs + _root._xmouse) / track_int);
if (Math.abs(this["v" + drag_vect].p1.y - this["v" + (drag_vect + 1)].p0.y) < 100) {
if (_root._xmouse <= ((this["v" + drag_vect].p0.x - xs) + (track_int / 2))) {
this["v" + drag_vect].p0.y = _root._ymouse;
this["v" + (drag_vect - 1)].p1.y = _root._ymouse;
} else {
this["v" + drag_vect].p1.y = _root._ymouse;
this["v" + (drag_vect + 1)].p0.y = _root._ymouse;
}
}
};
generate_terrain();
onEnterFrame = function () {
per_done = Math.round((xs / track_dis) * 100);
if ((per_done <= 100) && (per_done >= 0)) {
track_per = ("Completed: " + per_done) + "%";
} else if (per_done > 100) {
track_per = "Completed: 100%";
} else {
track_per = "Completed: 0%";
}
if (Key.isDown(37)) {
car.acc = (-car.spd) / 2;
} else if (Key.isDown(39)) {
car.acc = car.spd;
} else {
car.acc = 0;
}
if (w1.spd > car.max_spd) {
w1.spd = car.max_spd;
w2.spd = car.max_spd;
}
if (w1.spd < (-(car.max_spd / 2))) {
w1.spd = -(car.max_spd / 2);
w2.spd = -(car.max_spd / 2);
}
j = 1;
while (j <= 2) {
ob = this["w" + j];
ob.ground = 0;
vector_mn = Math.floor(xs / track_int);
vector_mx = Math.round((xs + 550) / track_int);
i = vector_mn;
while (i <= vector_mx) {
v = this["v" + i];
vx = (v.p1.x - xs) - (v.p0.x - xs);
vy = v.p1.y - v.p0.y;
slope = vy / vx;
xd = ob.x - (v.p0.x - xs);
ground = v.p0.y + (xd * slope);
if (((((ob._y + car.w_rad) + ob.yv) >= ground) && (ob.x >= (v.p0.x - xs))) && (ob.x < (v.p1.x - xs))) {
ob.ground = 1;
ob._y = ground - car.w_rad;
w1.spd = w1.spd + ((slope / 5) * car.fric);
w2.spd = w1.spd;
w1.vx = vx;
w1.vy = vy;
}
i++;
}
ob.spd = ob.spd + car.acc;
if (ob.ground) {
ob.dir = Math.atan2(w1.vy, w1.vx) / alpha;
ob.xv = ob.spd * Math.cos(ob.dir * alpha);
ob.yv = ob.spd * Math.sin(ob.dir * alpha);
ob.spd = ob.spd * car.w_frc;
}
xs = xs + ob.xv;
ob.yv = ob.yv + grav;
ob._y = ob._y + ob.yv;
ob._rotation = ob._rotation + ((ob.spd / car.w_cir) * 360);
j++;
}
body.ro = Math.atan2(w2._y - w1._y, w2._x - w1._x);
body._rotation = body.ro / alpha;
w_xd = w2._x - w1._x;
w_yd = w2._y - w1._y;
w_dis = Math.sqrt((w_xd * w_xd) + (w_yd * w_yd));
w2._x = w1._x + (Math.cos(body._rotation * alpha) * car.w_dis);
w2._y = w1._y + (Math.sin(body._rotation * alpha) * car.w_dis);
body._x = w1._x;
body._y = w1._y;
draw_ground();
flag._x = flag.x - xs;
slag._x = slag.x - xs;
};
Symbol 12 Button
on (release) {
vects = track_dis / track_int;
generate_terrain();
xs = 0;
w1.spd = (w2.spd = 0);
w1.xv = (w2.xv = 0);
}