pues nada que viendo el jueguecito de coches que teneis de tutorial, me puse con el y vi que estaba preparado para AS1!!!
he cambiado los nombres de las variables y la forma de interactuar las colisiones, en mi caso, dibujo un circuito trasparente que si se sale de el, frena el coche (todo con otra funcion de cristalab)
Espero que os guste! a ver si la proxima va en as3!
saludos!
archivo FLA[megaupload]
Código ActionScript :
stop();
//Variables de velocidad, angulo del coche y velocidad de giro
//Velocidad maxima que pueden alcanzar los coches
rootVelocidad=15;
coche_mc.velocidad=0;
coche_mc.maxVelocidad=rootVelocidad;
coche_mc.angulo=270;
coche_mc.laps=0;
coche_mc.cP1=false;
coche_mc.cP2=false;
coche_mc.cP3=false;
coche2_mc.velocidad=0;
coche2_mc.maxVelocidad=rootVelocidad;
coche2_mc.angulo=270;
coche2_mc.laps=0;
coche2_mc.cP1=false;
coche2_mc.cP2=false;
coche2_mc.cP3=false;
velocidadRotacion=6;
//funcion que detecta las colisiones
function checkHit(a:MovieClip, b:MovieClip) {
with (a) {
if (b.hitTest(getBounds(_root).xMax, _y, true)) {
return "left";
} else if (b.hitTest(getBounds(_root).xMin, _y, true)) {
return "right";
} else if (b.hitTest(_x, getBounds(_root).yMax, true)) {
return "up";
} else if (b.hitTest(_x, getBounds(_root).yMin, true)) {
return "down";
} else {
return false;
}
}
}
coche_mc.onEnterFrame=function(){
//Por cada frame ejecuta las siguientes condiciones
// Un coche solo gira si esta en movimiento
if(this.velocidad!=0){
//por lo tanto solo girara si presiona la tecla correspondiente
if (Key.isDown(Key.RIGHT)){
this.angulo += velocidadRotacion;
}else if (Key.isDown(Key.LEFT)){
this.angulo += velocidadRotacion*(-1);
}
}
//Velocidad y/o movimiento
//hacia adelante
if (Key.isDown(Key.UP)){
if(this.velocidad<rootVelocidad){
this.velocidad+=0.5;
}
}else{
if(this.velocidad>0){
this.velocidad-=0.5;
if(this.velocidad<0.5){
this.velocidad=0;
}
}
}
//hacia atras
if (Key.isDown(Key.DOWN)){
if(this.velocidad>-3){
this.velocidad--;
}
}else{
if (this.velocidad<0){
this.velocidad+=0.1;
if(this.velocidad>0.5){
this.velocidad=0;
}
}
}
//colisiones, condiciona al coche a ir por la carretera
if(checkHit(this, circuito_mc)){
this.maxVelocidad=rootVelocidad;
}else{
this.maxVelocidad=1;
if(this.velocidad>1){
this.velocidad-=1.5;
}
}
//si cocha contra el otro coche
if(checkHit(this, _root.coche2_mc)){
this.velocidad=1;
}
//Movemos el coche
//Direccion del coche
radian = Math.PI/180*this.angulo;
//posicion x = cos
this._x += (this.velocidad*Math.cos(radian));
//posicion y = sin
this._y += (this.velocidad*Math.sin(radian));
this._rotation = this.angulo;
//Salidas de texto
speed1_txt.text=Math.round(this.velocidad);
if(checkHit(this, _root.checkpoint1_mc)){
this.cP1=true;
}
if(this.cP1){
if(checkHit(this, _root.checkpoint2_mc)){
this.cP2=true;
}
}
if(this.cP2){
if(checkHit(this, _root.checkpoint3_mc)){
this.cP3=true;
}
}
if(this.cP3){
if(checkHit(this, _root.checkpoint4_mc)){
this.cP4=true;
}
}
if(this.cP4){
this.laps++;
_root.laps1_txt.text=this.laps;
this.cP1=false;
this.cP2=false;
this.cP3=false;
this.cP4=false;
}
}
coche2_mc.onEnterFrame=function(){
//Por cada frame ejecuta las siguientes condiciones
// Un coche solo gira si esta en movimiento
if(this.velocidad!=0){
//por lo tanto solo girara si presiona la tecla correspondiente
if (Key.isDown(68)){
this.angulo += velocidadRotacion;
}else if (Key.isDown(65)){
this.angulo += velocidadRotacion*(-1);
}
}
//Velocidad y/o movimiento
//hacia adelante
if (Key.isDown(87)){
if(this.velocidad<rootVelocidad){
this.velocidad+=0.5;
}
}else{
if(this.velocidad>0){
this.velocidad-=0.5;
if(this.velocidad<0.5){
this.velocidad=0;
}
}
}
//hacia atras
if (Key.isDown(83)){
if(this.velocidad>-3){
this.velocidad--;
}
}else{
if (this.velocidad<0){
this.velocidad+=0.1;
if(this.velocidad>0.5){
this.velocidad=0;
}
}
}
//colisiones, condiciona al coche a ir por la carretera
if(checkHit(this, circuito_mc)){
this.maxVelocidad=rootVelocidad;
}else{
this.maxVelocidad=1;
if(this.velocidad>1){
this.velocidad-=1.5;
}
}
//si cocha contra el otro coche
if(checkHit(this, _root.coche_mc)){
this.velocidad=1;
}
//Movemos el coche
//Direccion del coche
radian = Math.PI/180*this.angulo;
//posicion x = cos
this._x += (this.velocidad*Math.cos(radian));
//posicion y = sin
this._y += (this.velocidad*Math.sin(radian));
this._rotation = this.angulo;
//Salidas de texto
speed2_txt.text=Math.round(this.velocidad);
if(checkHit(this, _root.checkpoint1_mc)){
this.cP1=true;
}
if(this.cP1){
if(checkHit(this, _root.checkpoint2_mc)){
this.cP2=true;
}
}
if(this.cP2){
if(checkHit(this, _root.checkpoint3_mc)){
this.cP3=true;
}
}
if(this.cP3){
if(checkHit(this, _root.checkpoint4_mc)){
this.cP4=true;
}
}
if(this.cP4){
this.laps++;
_root.laps2_txt.text=this.laps;
this.cP1=false;
this.cP2=false;
this.cP3=false;
this.cP4=false;
}
}

Zguillez