Aqui esta el personaje principal:
Código ActionScript :
this.onEnterFrame = function() {
stop();
switch (Key.getCode()) {
case Key.UP:
if (!this.fondo.hitTest(this.bola._x,this.bola._y-27,true)){
this.bola._y = this.bola._y - 1
}
break;
case Key.DOWN:
if (!this.fondo.hitTest(this.bola._x,this.bola._y+27,true)){
this.bola._y = this.bola._y + 1
}
break;
case Key.RIGHT:
if (!this.fondo.hitTest(this.bola._x+19,this.bola._y,true)){
this.bola._x = this.bola._x + 1
}
break;
case Key.LEFT:
if (!this.fondo.hitTest(this.bola._x-19,this.bola._y,true)){
this.bola._x = this.bola._x - 1
}
break;
}
}
Aqui el personaje se mueve ,todo bienEn esta es la comida:
Código ActionScript :
xdirec=1;
ydirec=0;
margen=20;
this.onEnterFrame=function(){
this._x=this._x + xdirec;
this._y=this._y + ydirec;
if((this._parent.fondo.hitTest(this._x-margen,this._y,true) || this._parent.fondo.hitTest(this._x+margen,this._y,true)) && xdirec!=0){
if(this._parent.fondo.hitTest(this._x,this._y-margen,true)){
ydirec=1;
xdirec=0;
}else if(this._parent.fondo.hitTest(this._x,this._y+margen,true)){
ydirec=-1;
xdirec=0;
}else{
valor=Math.floor(Math.random()*2+1);
if(valor==1){
ydirec=1;
xdirec=0;
}else{
ydirec=-1;
xdirec=0;
}
}
}
this._x=this._x + xdirec;
this._y=this._y + ydirec;
if((this._parent.fondo.hitTest(this._x,this._y-margen,true) || this._parent.fondo.hitTest(this._x,this._y+margen,true)) && ydirec!=0){
if(this._parent.fondo.hitTest(this._x-margen,true)){
xdirec=1;
ydirec=0;
}else if(this._parent.fondo.hitTest(this._x+margen,true)){
xdirec=-1;
ydirec=0;
}else{
valor=Math.floor(Math.random()*2+1);
if(valor==1){
xdirec=1;
ydirec=0;
}else{
xdirec=-1;
ydirec=0;
}
}
}
if(this.hitTest(this._parent.bola)){
this._parent.puntos ++;
this._x=417
this._y=104
}
}
La comida,cada vez que choca con el personaje, me sube un punto.Y los malos:
Código ActionScript :
xdirec=1;
ydirec=0;
margen=20;
stop();
this.onEnterFrame=function(){
this._x=this._x + xdirec;
this._y=this._y + ydirec;
if((this._parent.fondo.hitTest(this._x-margen,this._y,true) || this._parent.fondo.hitTest(this._x+margen,this._y,true)) && xdirec!=0){
if(this._parent.fondo.hitTest(this._x,this._y-margen,true)){
ydirec=1;
xdirec=0;
}else if(this._parent.fondo.hitTest(this._x,this._y+margen,true)){
ydirec=-1;
xdirec=0;
}else{
valor=Math.floor(Math.random()*2+1);
if(valor==1){
ydirec=1;
xdirec=0;
}else{
ydirec=-1;
xdirec=0;
}
}
}
this._x=this._x + xdirec;
this._y=this._y + ydirec;
if((this._parent.fondo.hitTest(this._x,this._y-margen,true) || this._parent.fondo.hitTest(this._x,this._y+margen,true)) && ydirec!=0){
if(this._parent.fondo.hitTest(this._x-margen,true)){
xdirec=1;
ydirec=0;
}else if(this._parent.fondo.hitTest(this._x+margen,true)){
xdirec=-1;
ydirec=0;
}else{
valor=Math.floor(Math.random()*2+1);
if(valor==1){
xdirec=1;
ydirec=0;
}else{
xdirec=-1;
ydirec=0;
}
}
}
if(this.hitTest(this._parent.bola)){
this._parent.vidas --
this._parent.bola._x=58.6
this._parent.bola._y=100.4
}
}
Que cada vez que me tocan me resta una vida.Asi que si alguien puede decirme como puedo hacerlo para que al llegar p.e. a 100 puntos me salte a otro fotograma, le estaria agradecido.
