Page 39 of 92

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 12:05 pm
by erkosone
No es moco de pavo no la locura esta de los path() jeje..

Source Code (Javascript) [ Download ] [ Hide ]
  • //---------------------------------------------------------------------------------
  • //---------------------------------------------------------------------------------
  • //---------------------------------------------------------------------------------
  • // rutina para seguir caminos prefabricados, gracias hokuto por la idea!
  • //---------------------------------------------------------------------------------
  • //---------------------------------------------------------------------------------
  •  
  • class path{
  •     //----------------------------------------------
  •     constructor(){
  •         this.points = [];               // vector list of path..
  •         this.lastDist = 999999999999;   // last distance to next vector..
  •         this.vel = 3;                   // velocity of movement..
  •         this.pos = 0;                   // actual point of path..
  •         this.x = 0;
  •         this.y = 0;
  •         this.pause = false;
  •         this.last = -666;
  •     }
  •     //----------------------------------------------
  •     add(x, y){
  •         var vec = createVector(x, y);
  •         this.points.push(vec);
  •     }
  •     //----------------------------------------------
  •     length(){
  •         return this.points.length-1;
  •     }
  •     //----------------------------------------------
  •     reset(){
  •         this.pos = 0;
  •         this.lastDist = 999999999999;
  •     }
  •     //----------------------------------------------
  •     setPoint(num){
  •         this.pos = num;
  •     }
  •     //----------------------------------------------
  •     setVelocity(vel){
  •         this.vel = vel;
  •     }
  •     //----------------------------------------------
  •     //----------------------------------------------
  •     move(type_){
  •         this.x = _id_actual_sprite_runing_.x;
  •         this.y = _id_actual_sprite_runing_.y;
  •         if(this.last == -666){
  •             this.last = type_;
  •         }
  •         switch(type_){
  •             //--------------------------------------------------------------------------------------------------------------------------------------
  •             case FORWARD:
  •                 if(this.pause){
  •                     return this.pos;
  •                 }
  •                
  •                 if(type_ != this.last){
  •                     switch(this.last){
  •                         case FORWARD:
  •                             break;
  •                         case FORWARD_LOOP:
  •                             break;
  •                         case REVERSE:
  •                             if(this.pos<this.points.length-1){
  •                                 this.pos++;
  •                             } else{
  •                                 this.pos = 0;
  •                             }
  •                             break;
  •                         case REVERSE_LOOP:
  •                             if(this.pos<this.points.length-1){
  •                                 this.pos++;
  •                             } else{
  •                                 this.pos = 0;
  •                             }
  •                             break;
  •                     }
  •                     this.last = type_;
  •                 }
  •                
  •                 if(this.x == this.points[this.points.length-1].x){
  •                     if(this.y == this.points[this.points.length-1].y){  
  •                         return this.pos;
  •                     }
  •                 }
  •                 var a = this.getAngle(_id_actual_sprite_runing_.x, _id_actual_sprite_runing_.y, this.points[this.pos].x, this.points[this.pos].y);
  •                 if(this.pos < this.points.length){
  •                     this.advance(this.vel, a);
  •                 }
  •                 var d = dist(this.x, this.y, this.points[this.pos].x, this.points[this.pos].y);
  •                 if( d < this.vel ){
  •                     if(this.pos < this.length()){
  •                         this.pos++;
  •                     } else{
  •                         this.x = this.points[this.points.length-1].x;
  •                         this.y = this.points[this.points.length-1].y;
  •                     }
  •                 }
  •                 if(_id_actual_sprite_runing_.body_created){
  •                     _id_actual_sprite_runing_.translate(this.x, this.y);
  •                 } else{
  •                     _id_actual_sprite_runing_.x = this.x;
  •                     _id_actual_sprite_runing_.y = this.y;
  •                 }
  •                 return this.pos;
  •                 break;
  •             //--------------------------------------------------------------------------------------------------------------------------------------
  •             case FORWARD_LOOP:
  •                 if(this.pause){
  •                     return this.pos;
  •                 }
  •                
  •                 if(type_ != this.last){
  •                     switch(this.last){
  •                         case FORWARD:
  •                             break;
  •                         case FORWARD_LOOP:
  •                             break;
  •                         case REVERSE:
  •                             if(this.pos<this.points.length-1){
  •                                 this.pos++;
  •                             } else{
  •                                 this.pos = 0;
  •                             }
  •                             break;
  •                         case REVERSE_LOOP:
  •                             if(this.pos<this.points.length-1){
  •                                 this.pos++;
  •                             } else{
  •                                 this.pos = 0;
  •                             }
  •                             break;
  •                     }
  •                     this.last = type_;
  •                 }
  •                
  •                 var a = this.getAngle(_id_actual_sprite_runing_.x, _id_actual_sprite_runing_.y, this.points[this.pos].x, this.points[this.pos].y);
  •                 if(this.pos < this.points.length){
  •                     this.advance(this.vel, a);
  •                 }
  •                 var d = dist(this.x, this.y, this.points[this.pos].x, this.points[this.pos].y);
  •                 if( d < this.vel ){
  •                     if(this.pos < this.length()){
  •                         this.pos++;
  •                     } else{
  •                         this.pos = 0;
  •                     }
  •                 }
  •                 if(_id_actual_sprite_runing_.body_created){
  •                     _id_actual_sprite_runing_.translate(this.x, this.y);
  •                 } else{
  •                     _id_actual_sprite_runing_.x = this.x;
  •                     _id_actual_sprite_runing_.y = this.y;
  •                 }
  •                 return this.pos;
  •                 break;
  •             //--------------------------------------------------------------------------------------------------------------------------------------
  •             case REVERSE:
  •                 if(this.pause){
  •                     return this.pos;
  •                 }
  •                
  •                 if(type_ != this.last){
  •                     switch(this.last){
  •                         case FORWARD:
  •                             if(this.pos>=0){
  •                                 this.pos--;
  •                             } else{
  •                                 this.pos = this.points.length-1;
  •                             }
  •                             break;
  •                         case FORWARD_LOOP:
  •                             if(this.pos>=0){
  •                                 this.pos--;
  •                             } else{
  •                                 this.pos = this.points.length-1;
  •                             }
  •                             break;
  •                         case REVERSE:
  •                             break;
  •                         case REVERSE_LOOP:
  •                             break;
  •                     }
  •                     this.last = type_;
  •                 }
  •                
  •                 if(this.x == this.points[0].x){
  •                     if(this.y = this.points[0].y){
  •                         this.last = type_;
  •                         return this.pos;
  •                     }
  •                 }
  •                
  •                 var a = this.getAngle(_id_actual_sprite_runing_.x, _id_actual_sprite_runing_.y, this.points[this.pos].x, this.points[this.pos].y);
  •                 if(this.pos >= 0){
  •                     this.advance(this.vel, a);
  •                 }
  •                 var d = dist(this.x, this.y, this.points[this.pos].x, this.points[this.pos].y);
  •                 if( d < this.vel ){
  •                     if(this.pos > 0){
  •                         this.pos--;
  •                     } else{
  •                         this.x = this.points[0].x;
  •                         this.y = this.points[0].y;
  •                     }
  •                 }
  •                 if(_id_actual_sprite_runing_.body_created){
  •                     _id_actual_sprite_runing_.translate(this.x, this.y);
  •                 } else{
  •                     _id_actual_sprite_runing_.x = this.x;
  •                     _id_actual_sprite_runing_.y = this.y;
  •                 }
  •                 return this.pos;
  •                 break;
  •             //--------------------------------------------------------------------------------------------------------------------------------------
  •             case REVERSE_LOOP:
  •                 if(this.pause){
  •                     return this.pos;
  •                 }
  •                
  •                 if(type_ != this.last){
  •                     switch(this.last){
  •                         case FORWARD:
  •                             if(this.pos>0){
  •                                 this.pos--;
  •                             } else{
  •                                 this.pos = this.points.length-1;
  •                             }
  •                             break;
  •                         case FORWARD_LOOP:
  •                             if(this.pos>0){
  •                                 this.pos--;
  •                             } else{
  •                                 this.pos = this.points.length-1;
  •                             }
  •                             break;
  •                         case REVERSE:
  •                             break;
  •                         case REVERSE_LOOP:
  •                             break;
  •                     }
  •                     this.last = type_;
  •                 }
  •                
  •                 if(this.x == this.points[0].x){
  •                     if(this.y = this.points[0].y){
  •                         return this.pos;
  •                     }
  •                 }
  •                
  •                 var a = this.getAngle(_id_actual_sprite_runing_.x, _id_actual_sprite_runing_.y, this.points[this.pos].x, this.points[this.pos].y);
  •                 if(this.pos >= 0){
  •                     this.advance(this.vel, a);
  •                 }
  •                 var d = dist(this.x, this.y, this.points[this.pos].x, this.points[this.pos].y);
  •                 if( d < this.vel ){
  •                     if(this.pos > 0){
  •                         this.pos--;
  •                     } else{
  •                         this.pos = this.points.length-1;
  •                     }
  •                 }
  •                 if(_id_actual_sprite_runing_.body_created){
  •                     _id_actual_sprite_runing_.translate(this.x, this.y);
  •                 } else{
  •                     _id_actual_sprite_runing_.x = this.x;
  •                     _id_actual_sprite_runing_.y = this.y;
  •                 }
  •                 return this.pos;
  •                 break;
  •             //--------------------------------------------------------------------------------------------------------------------------------------
  •         }
  •     }
  •     //----------------------------------------------
  •     getAngle (x1, y1, x2, y2){
  •         var a = degrees(atan2(y2-y1, x2-x1 ));
  •         if(a<0){a=360.0+a;}
  •         if(a>=360.0){a=0;}  
  •         return (360-a);
  •     }
  •     //----------------------------------------------
  •     advance(dist, angle){
  •         this.x = this.x + dist * cos(radians(-angle));
  •         this.y = this.y - dist * sin(radians(angle));
  •     }
  •     //----------------------------------------------
  • }


En el post anterior te he dejado la libreria para probar ;)

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 1:14 pm
by erkosone
Joer XD.. bugs y mas bugs, esta es la buena ;)

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 2:27 pm
by Hokuto7
jejeje,ya me la he descargado y la pruebo. ;)

Lo del angulo me referia a que no funciona el crear una variable y utilizarla para cambiar los valores en esta variable,hay que utilizar angle directamente.ejemplo

variable angulo = 0;
angle = angulo.
angulo = 90;//no me deja hacerlo

Con advance2 si me deja utilizar una variable,pero con advance no.

Con repecto a lo de probar cosillas,pues ya sabes que le tengo alergia a la estructura de niveles,cuando tengas creado la estructura me pondre mas enserio con la libreria,y asi podre crear niveles facilmente y podre probar muchas cosillas.
------------------------------------------------------------------------------------------------
Te comento una cosa,ahora si que es seguro,hay problemas con brackets.Sabes que al abrir brackets,te carga los ejemplo con los que estas trabajando,sin embargo despues de un tiempo no funcionan los ejemplo y se queda el navegador cargando.

Entonces lo que yo hago es cerrar el ejemplo y volver a cargar la carpeta donde esta,pero antes tengo que salirme de la carpeta y volver a entrar,si no ,no funciona.

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 3:04 pm
by Hokuto7
Ya lo he probado y te comento,funciona todo muy bien menos el movimiento 2("reverse"),este movimiento no funciona,tambien he probado el pause y funciona muy bien.

Pero me ha pasado una cosa,al principio lo use asi p.pause(true),asi se me quedo congelado el juego y luego lo use asi,p.pause = true y funciono bien.

Luego he visto que has creado unas constantes de colores para las funciones de engui,pues estaria bien que crearas unas constantes de colores para poder utilizarlas en todo el codigo.

Por ultimo comentarte algo que se me a ocurrido,como el advance rota automaticamente,pues podrias dejar este path como esta y crear un path2 que en vez de ir aun punto x e y fuera aun angulo,seria asi.

Source Code (Javascript) [ Download ] [ Hide ]
  •    var punto = new path2();
  •    punto.add(angulo=0);
  •    punto.add(angulo=90);
  •    punto.setPoint(0)
  •    punto.setVelocity(5);
  •  


A lo mejor con esto se resuelve el problema que tienes con la autorotacion,pero solo es por si no lo consigues. ;)

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 4:26 pm
by erkosone
Hola Hokuto, el reverse a mi me funciona bien, pero tienes que setear de inicio, el punto de partida, fijate que en la linea 63 hay esto: p.setPoint(0);

si tu path es de n' puntos, tienes que setear el punto de inicio como el ultimo para que de inicio reverse funcione, por que en el ejemplo se setea como inicio el cero, y como ya esta en el cero no retrocede mas jeje..
pero si lo dejas avanzar hasta el punto que sea y luego pulsas D veras como hace el reverse bien.

Estoy ahora con la rotación, haber que saco ;)

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 4:41 pm
by erkosone
Con rotacion!

Ale ahora ya si!, joer ha costado pero lo tengo listo 8-) 8-)

Ahora a probarlo a fondo y miramos el siguiente paso, los niveles. que en verdad esta facil de hacer, estoy pensando en algo bastante sencillo :P

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 4:50 pm
by Hokuto7
Vale ya entiendo,voy aprobar el reserve y la rotacion a ver como te ha quedado. ;)

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 5:09 pm
by Hokuto7
Vale,ya lo he probado y funciona todo de lujo,te a quedado cojonuuuuudo. :claphands:

Ahora me vas a mandar a freir esparragos,pero habria alguna forma de que cuando rote lo hiciera mas suave y lento,porque ahora lo hace muy brusco.

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 5:11 pm
by erkosone
Hokuto lo de los niveles creo que lo mejor va a ser crear un juego y hacer las pruebas con el XD..

Me voy a montar un minijuego con 10 niveles y empiezo a montar el sistema, haber que me sale de inicio y luego vamos retocandolo :)

Aunque ya te digo que es bastante simple de hacer por tu cuenta, por que solo es hacer una colección de colecciones de sprites, donde puedes invocarlos de una.. matarlos de una.. o cosas así, invocar al grupo o level 1.. matar al grupo o level 2.. etc etc..

voy a montar algo y te lo muestro.


P.D: jaja vale dejame que mire como hacer lo del giro suave.. yo también me habia dado cuenta XD..

Re: Test de mi gameEngine en processing.

PostPosted: Sun Aug 12, 2018 5:12 pm
by Hokuto7
Ok,cuando lo tengas avisa. :y: