Ciao a tutti! Volevo chiedervi, ho trovato questo codice su risorseflash, per creare una macchina che si muove...
Adesso però vorrei fare un tracciato fatto di tante linee. Come faccio a dire che quando va su una linea di fare una certa azione???
Ecco il codice:
onClipEvent (load) {
maxspeed = 20; //velocita massima
maxnegspeed = -20; //velocita massima retromarcia
speed = 0; //velocita corrente
//funzione che muove la macchina
function move(angolo) {
quanto = (_rotation/180)*Math.PI;
_x += angolo*Math.sin(quanto);
_y += -angolo*Math.cos(quanto);
return angolo;
}
}
onClipEvent (enterFrame) {
//accelera
if (Key.isDown(Key.UP)) {
if (speed<maxspeed) {
speed += 5; //l'accelerazione è di 0.1
}
} else {
//rallenta
if (Key.isDown(Key.DOWN) == false) {
speed *= 0.98;
if (speed<0.1 and speed>-0.1) {
speed = 0;
}
}
}
//frena, retromarcia
if (Key.isDown(Key.DOWN)) {
if (speed>maxnegspeed) {
speed -= 5;
}
}
//sterza a sinistra
if (Key.isDown(Key.LEFT)) {
_rotation -= speed/1; //era /2
}
//sterza a destra
if (Key.isDown(Key.RIGHT)) {
_rotation += speed/1; //era /2
}
//muove la macchina
move(speed);
//velocita corrente
_root.speed = Math.round(speed);
}

Rispondi quotando

