Hello,

I am new here and thought I might could find some help here. I followed a tutorial to create a small race game, but it is in AS2 and I need to have it in AS3. Is there anybody who could help me? I am not very good in coding and would be happy with any kind of help.

Thanks in advance

sechbert

function step(who) {

//check if the car is controlled by the computer or by the player (i started like that to leave the possibility to have enemies)

if (_root["car"+who].code == "player") {

//constantly decrease speed by multiplying it with a number below 1

if (this["speed"+who]>0.3) {

this["speed"+who] *= _root.speedDecay;

} else {

this["speed"+who] = 0;

}

//key controllment

//accelerate

if (Key.isDown(Key.UP) && this["speed"+who]<_root.maxSpeed) {

this["speed"+who] += _root.acceleration;

}

//brake (reverse)

if (Key.isDown(Key.DOWN)) {

this["speed"+who] -= _root.backSpeed;

}

//steer left

if (Key.isDown(Key.LEFT) && Math.abs(this["speed"+who])>0.3) {

_root["car"+who]._rotation -= _root.rotationStep*(this["speed"+who]/_root.maxSpeed);

}

//math.abs means only positive numbers

//steer right

if (Key.isDown(Key.RIGHT) && Math.abs(this["speed"+who])>0.3) {

_root["car"+who]._rotation += _root.rotationStep*(this["speed"+who]/_root.maxSpeed);

}

this["rotation"+who] = _root["car"+who]._rotation;

//calculate the two components of speed (X axis and Y axis)

this["speedx"+who] = Math.sin(this["rotation"+who]*(Math.PI/180))*this["speed"+who];

this["speedy"+who] = Math.cos(this["rotation"+who]*(Math.PI/180))*this["speed"+who]*-1;

//apply the components on the actual position of the car

_root["car"+who]._x += this["speedx"+who];

_root["car"+who]._y += this["speedy"+who];

//the collisions

//define the four collision points

_root["car"+who].pointLeft = {x:-20, y:0};

_root["car"+who].localToGlobal(_root["car"+who].pointLeft);

_root["car"+who].pointRight = {x:20, y:0};

_root["car"+who].localToGlobal(_root["car"+who].pointRight);

_root["car"+who].pointFront = {x:0, y:-25};

_root["car"+who].localToGlobal(_root["car"+who].pointFront);

_root["car"+who].pointBack = {x:0, y:25};

_root["car"+who].localToGlobal(_root["car"+who].pointBack);

//using some shorter variable names

this["lpx"+who] = _root["car"+who].pointLeft.x;

this["lpy"+who] = _root["car"+who].pointLeft.y;

this["rpx"+who] = _root["car"+who].pointRight.x;

this["rpy"+who] = _root["car"+who].pointRight.y;

this["fpx"+who] = _root["car"+who].pointFront.x;

this["fpy"+who] = _root["car"+who].pointFront.y;

this["bpx"+who] = _root["car"+who].pointBack.x;

this["bpy"+who] = _root["car"+who].pointBack.y;

//check for collisions

if (_root.terrain.hitTest(this["lpx"+who], this["lpy"+who], true)) {

_root["car"+who]._rotation += 5;

this["speed"+who] *= 0.85;

}

if (_root.terrain.hitTest(this["rpx"+who], this["rpy"+who], true)) {

_root["car"+who]._rotation -= 5;

this["speed"+who] *= 0.85;

}

if (_root.terrain.hitTest(this["fpx"+who], this["fpy"+who], true)) {

this["speed"+who] = -1;

}

if (_root.terrain.hitTest(this["bpx"+who], this["bpy"+who], true)) {

this["speed"+who] = 1;

}

//checkpoints

if (_root["car"+who].hitTest(_root["checkpoint"+_root["currentCheckpoint"+who]])) {

//if the current checkpoint is the start line - increase the lap number

if (_root["currentCheckpoint"+who] == 1) {

if (_root["currentLap"+who] != 0) {

_root.setBestLap();

}

if (_root["currentLap"+who] == _root.totalLaps){

_root.gotoAndStop("finish");

}else{

_root["currentLap"+who]++;

}

_root.currentLapTXT = _root["currentLap"+who]+"/10";

}

_root["currentCheckpoint"+who]++;

//if the current checkpoint is the last checkpoint - set the next checkpoint to the start line

if (_root["currentCheckpoint"+who]>_root.checkpoints) {

_root["currentCheckpoint"+who] = 1;

}

}

}

if (_root["car"+who].code == "computer") {

}

}

function setTimes() {

timeElapsed = getTimer()-_root.initialTime;

milliseconds = timeElapsed;

seconds = Math.floor(milliseconds/1000);

minutes = Math.floor(seconds/60);

minutesTXT = minutes;

secondsTXT = seconds-minutes*60;

tensTXT = Math.round((milliseconds-seconds*1000)/10);

if (minutesTXT<10) {

minutesTXT = "0"+minutesTXT;

}

if (secondsTXT<10) {

secondsTXT = "0"+secondsTXT;

}

if (tensTXT<10) {

tensTXT = "0"+tensTXT;

}

_root.totalTimeTXT = minutesTXT+"."+secondsTXT+"."+tensTXT;

}

function setBestLap() {

bestTime = getTimer()-_root.lapTime;

milliseconds = bestTime;

if (oldMilliseconds>milliseconds || oldMilliseconds==null) {

oldMilliseconds = milliseconds;

seconds = Math.floor(milliseconds/1000);

minutes = Math.floor(seconds/60);

minutesTXT = minutes;

secondsTXT = seconds-minutes*60;

tensTXT = Math.round((milliseconds-seconds*1000)/10);

if (minutesTXT<10) {

minutesTXT = "0"+minutesTXT;

}

if (secondsTXT<10) {

secondsTXT = "0"+secondsTXT;

}

if (tensTXT<10) {

tensTXT = "0"+tensTXT;

}

_root.bestLapTXT = minutesTXT+"."+secondsTXT+"."+tensTXT;

}

_root.lapTime = getTimer();

}