Comunidad de diseño web y desarrollo en internet online

obstaculizar avance de personaje en juego

Citar            
MensajeEscrito el 12 Oct 2009 01:16 am
Buenas, estoy intentando realizar a través de una serie de comandos, el desplazamiento de un personaje por la pantalla controlado a través del seguimiento del puntero del mouse. El meollo es que necesito que en determinado punto de la pantalla, el personaje sea obstaculizado por ciertos objetos que no le permiten dar el paso, es decir avanzar por donde están ellos. Por tanto, si el puntero del mouse se direcciona sobre esta zona esa suerte de objetos paredes deberían frenarle el paso.
Tengo el siguiente código de comandos para el movimiento del personaje pero no conozco cómo poder realizar lo antedicho.
Gracias de antemano.

Código :

var Speed:Number = 1 // Velocidad del personaje
var TmpXY:Number = 0;

onEnterFrame = function() {
   gotoSpotX = this._parent._xmouse;
   gotoSpotY = this._parent._ymouse;


   
   
   
   // calculate angle of current position to target position 
   delta_x = this._x-gotoSpotX;
   delta_y = this._y-gotoSpotY;
   targetRotation = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
   if (targetRotation<0){
      targetRotation += 360//Acomoda el angulo para que sea de 360 grados
   }   
   
   // move beetle toward the target and stop when it gets there
   if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>Speed) {
      _y -= Speed*Math.cos(targetRotation*(Math.PI/180));
      _x += Speed*Math.sin(targetRotation*(Math.PI/180));
      this.Fachadas.Parado = false; //Controla fachada de estar parado
   }else{
      this.Fachadas.Parado = true;
   }
   
   // 
   // loop to opposite side of the masked area when the beetle travels off-screen
   if (_y<10) {
      _root.gotoAndStop(2)
   }
   if (_y>370) {
      _root.gotoAndStop(2)
   }
   if (_x<10) {
      _root.gotoAndStop(1)
   }
   if (_x>370) {
      _root.gotoAndStop(1)
   }
   

   
   
   
   // Asigna el cambio de fachadas
   if (targetRotation<20){
      this.Fachadas.Angulo = 0;
   }else if (targetRotation<70){
      this.Fachadas.Angulo = 45;
   }else if (targetRotation<100){
      this.Fachadas.Angulo = 90;
   }else if (targetRotation<150){
      this.Fachadas.Angulo = 135;
   }else if (targetRotation<183){
      this.Fachadas.Angulo = 180;
   }else if (targetRotation<240){
      this.Fachadas.Angulo = 225;
   }else if (targetRotation<290){
      this.Fachadas.Angulo = 270;
   }else if (targetRotation<335){
      this.Fachadas.Angulo = 315;
   }else if (targetRotation<360){
      this.Fachadas.Angulo = 0;
   
   }
   

   
   this.Direccion._rotation = targetRotation; // Borrar esto
   XY =  int(_x) + " ; " + int(_y); // Borrar esto
   Ang =  this.Fachadas.Angulo; // Borrar esto
}

Por incubo

53 de clabLevel



 

firefox
Citar            
MensajeEscrito el 13 Oct 2009 02:39 pm
Para evitar la avalancha de ifs.. se usa una técnica denominada Tiles, a través de la cual se contruyen los "mundos" de los personajes. Te recomiendo que busques dentro de http://gotoAndPlay.it algún tutorial sobre el tema

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 13 Oct 2009 04:04 pm

Por comicSans

Claber

151 de clabLevel



 

firefox
Citar            
MensajeEscrito el 13 Oct 2009 04:09 pm
Ray casting es para ver si se ven dos objetos, no para detectar colisiones

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.