• Jueves 28 de Marzo de 2024, 15:15

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Mensajes - turko666

Páginas: [1]
1
Allegro / Re: Necesito Una Ayudita Sobre Colisiones
« en: Miércoles 22 de Marzo de 2006, 22:04 »
afff otro error, anda todo perfecto exepto cuando te moves en diagonal hacia los extremos del "cubo"  :angry:

2
Allegro / Re: Necesito Una Ayudita Sobre Colisiones
« en: Miércoles 22 de Marzo de 2006, 21:56 »
mmm la verdad no lo entendi muy bien... igualmente gracias por la intencion  :D

de todas formas me ilumine y se me ocurrio como hacerlo... ahora anda de 10  :comp: lo que hice fue remplazar los px_rel y py_rel por px_array que seria la posicion del personaje en el arreglo... si el personaje se mueve 8 px px_array no se mueve... solo se mueve si px%32==0 osea si es divisible por 32... lo mismo py_array.

aca les copio el codigo por si no me entendieron asi lo prueban y ven a que me refiero :P ... el 3 es el personaje "graficamente" el 1 rojo es la posicion en la matriz del personaje...


Citar
#include <allegro.h>
#include <stdlib.h>

#define TILESIZE      32
#define TILES_ANCHO  32
#define TILES_ALTO    24

BITMAP *buffer;
BITMAP *grid;
BITMAP *player;
BITMAP *tiles;

#define UP      0
#define DOWN    1
#define LEFT    2
#define RIGHT    3

//variables del personaje
int px, py, dir, frame,px_array,py_array,px_array_ant,py_array_ant;

char posx[5],posy[5];

short mapa[24][32] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }};
//prototipo funciones
void inicia_todo();
void borra_todo();
void dibuja_mapa();
void mover(int d);
void dibuja_player();
void dibuja_todo();
void blitbuffer( BITMAP *bmp );

// ------------------------- estructura de funciones -------------------------------
void inicia_todo()
{
    allegro_init();
    install_keyboard();
    install_timer();
    install_mouse();
    set_color_depth( 16 );
    set_gfx_mode( GFX_AUTODETECT, 1024, 768, 0, 0);
   
    buffer=create_bitmap(SCREEN_W,SCREEN_H);
    clear(buffer);
   
    grid=create_bitmap(TILES_ANCHO * TILESIZE, TILES_ALTO * TILESIZE);
   
    player=load_bitmap("player.pcx",NULL);
    tiles=load_bitmap("tilemaps.pcx",NULL);
   
    px=32;
    py=32;
    dir=DOWN;
    frame=0;
    px_array=1;
    py_array=1;
}

// ---------------------------------------------------------------------
void borra_todo()
{
    if ( buffer )
        destroy_bitmap( buffer );

    if ( grid )
        destroy_bitmap( grid );
}

// -----------------------------------------------------------------------
void dibuja_player()
{
    textout(buffer,font,"1",px_array*TILESIZE,py_array*TILESIZE,-5789);
    textout(buffer,font,"3",px,py,-500);
}
// -----------------------------------------------------------------------
void dibuja_mapa()
{
  int i , j , x=0 , y=0;
      for(i=0;i<24;i++)
            {
                for(j=0;j<32;j++)
                      {
                      switch(mapa[j])
                            {
                            case 0: textout(grid,font,"0",j*TILESIZE,i*TILESIZE,255);break;
                            case 1: textout(grid,font,"1",j*TILESIZE,i*TILESIZE,5000);break;
                            case 2: blit(tiles,grid,x,0 * TILESIZE ,i * TILESIZE, j * TILESIZE, TILESIZE, TILESIZE);break;
                            }
                      }
            }
  blit( grid, buffer, 0, 0, 0, 0, TILES_ANCHO * TILESIZE, TILES_ALTO * TILESIZE );             
}
// -----------------------------------------------------------------------
void dibuja_todo()
{
    dibuja_mapa();
    dibuja_player();
    blitbuffer(buffer);
    show_mouse(screen);   
}
// ------------------------------------------------------------------------
void blitbuffer( BITMAP *bmp )
{
    acquire_screen();
    blit( bmp, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H );
    release_screen();
}     

// ------------------------------------------------------------------------
void inc_frame(int d)
{
if (dir==UP)
{
  frame++;
  if (frame>1) frame=0;
}
if (dir==DOWN)
{
  frame++;
  if (frame<4 || frame>5) frame=4;
}
if (dir==LEFT)
{
  frame++;
  if (frame<6 || frame>7) frame=6;
}
if (dir==RIGHT)
{
  frame++;
  if (frame<2 || frame>3) frame=2;
}
}
// --------------------------------------------------------------
void mover(int d)
{
    dir=d;
   inc_frame(dir);
   switch(dir)
    {
    case LEFT:  if(colision[py_array][px_array-1]!=0||px%TILESIZE!=0){px-=8;if(px%TILESIZE==0)px_array=px/32;}break;
    case RIGHT: if(colision[py_array][px_array+1]!=0||px%TILESIZE!=0){px+=8;if(px%TILESIZE==0)px_array=px/32;}break;
   case UP:    if(colision[py_array-1][px_array]!=0||py%TILESIZE!=0){py-=8;if(py%TILESIZE==0)py_array=py/32;}break;
   case DOWN:  if(colision[py_array+1][px_array]!=0||py%TILESIZE!=0){py+=8;if(py%TILESIZE==0)py_array=py/32;}break;
    }
}

// ---------------------- MAIN ------------------------------------
int main()
{
    bool done = false;
    bool mousemove = false;
    inicia_todo();

    while ( !done )
    {
        dibuja_todo();
        rest(30);

// ESC para salir

        if (key[ KEY_ESC ] ) done = true;
       
       
        if (key[ KEY_DOWN ] )mover(DOWN);
        if (key[ KEY_UP ] ) mover(UP);
        if (key[ KEY_LEFT ] ) mover(LEFT);
        if (key[ KEY_RIGHT ] ) mover(RIGHT);
       
    }
    borra_todo();
    return 0;
}
END_OF_MAIN();

3
Allegro / Re: Necesito Una Ayudita Sobre Colisiones
« en: Miércoles 22 de Marzo de 2006, 09:35 »
afff se me acabaron las ideas... solo se me ocurren 2 cosas:

1ero(y absurda idea) : hacer una matriz aumentada 4 veces entonces al moverse 8 px todos los tiles ocuparan 16 posiciones de un arreglo

0 0 0 0  << asi seria un solo tile de 32px... usa 16 posiciones de memoria en vez de 1
0 0 0 0
0 0 0 0
0 0 0 0

Esa tecnica no puede fallar pero me parece demasiado antipráctico, ademas el uso de memoria se iria x las nubes en mapas grandes.


2do: hacer que cada tile (posicion de la matriz) utilize campos, o sea... si quiero subir (y-=8 px) que vea si la proxima posicion del arreglo es == 0 (como ya esta hecho) o si esa posicion +8px de x ==0 o si esa posicion -8px de x ==0... pero tampoco le encuentro la vuelta...

adjunto una imagen para explicar el problema... a partir del 0 y 16px de X positivo y 16px de y positivo hay colision... pero 16 px X negativo y 16 px Y negativo no hay colision alguna, se puede transpasar sin ningun problema ya uqe solo se fija si los proximos 32 px tienen un valor igual a 0... pero no se fija sus alrededores.

4
Allegro / Re: Necesito Una Ayudita Sobre Colisiones
« en: Lunes 20 de Marzo de 2006, 19:04 »
Mira a lo que me refiero...

P/D: no se puede adjuntar 2 imagenes en un mismo post?  :o

5
Allegro / Re: Necesito Una Ayudita Sobre Colisiones
« en: Lunes 20 de Marzo de 2006, 18:53 »
Mmm hay algo que le falla todavia a las colisiones, voy a poner un screenshot para que te des una idea mas clara (no se como se adjuntan pero voy a intentar)

Bueno en el dibujo las lineas fuccias serian los limites de cada celda de la matriz no caminable... el personaje (3) nunca podria estar 8 px mas arriba ni mas atras que un 0... deberia estar 32 px como minimo porque al utilizar tiles de 32px al ver el resultado ya usando tiles graficos el personaje se mete en el agua por ejemplo  :rain:

6
Allegro / Re: Necesito Una Ayudita Sobre Colisiones
« en: Lunes 20 de Marzo de 2006, 07:54 »
:D (no estaba tan equivocado) es lo mismo que me plantie yo, habia intentado hacer una condicion sacando el resto... pero yo habia intentado if(px%TILESIZE==0) y ahi fue donde meti la pata. tiene que ser distinto de 0, no igual  :unsure:

Muchas gracias por darme una mano... prometo mas adelante cuando lleve un poquito mejor el juego lo posteo. En este momento me estoy metiendo a la parte mas dificil que es controlar el personaje mediante el mouse calculando phatfinding y todo eso que me resulta bastante engorroso  :comp: y luego tengo que pasar al scrolling de pantalla.

En fin gracias de nuevo!!

7
Allegro / Necesito Una Ayudita Sobre Colisiones
« en: Domingo 19 de Marzo de 2006, 01:36 »
Antes que nada buenasss a todos  :rolleyes:
tengo un problemaa con el tema de colisiones, paso a poner el codigo y despues explico  en que cosas tengo dudas:

Citar
#include <allegro.h>
#include <stdlib.h>

#define TILESIZE      32
#define TILES_ANCHO   32
#define TILES_ALTO    24

BITMAP *buffer;
BITMAP *grid;
BITMAP *player;
BITMAP *tiles;

#define UP       0
#define DOWN     1
#define LEFT     2
#define RIGHT    3

//variables del personaje
int px, py, dir, frame,aguaframe;

char posx[5],posy[5];

short mapa[24][32] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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//prototipo funciones
void inicia_todo();
void borra_todo();
void dibuja_mapa();
void mover(int d);
void dibuja_player();
void dibuja_todo();
void blitbuffer( BITMAP *bmp );

// ------------------------- estructura de funciones -------------------------------
void inicia_todo()
{
     allegro_init();
     install_keyboard();
     install_timer();
     install_mouse();
     set_color_depth( 16 );
     set_gfx_mode( GFX_AUTODETECT, 1024, 768, 0, 0);
     
     buffer=create_bitmap(SCREEN_W,SCREEN_H);
     clear(buffer);
     
     grid=create_bitmap(TILES_ANCHO * TILESIZE, TILES_ALTO * TILESIZE);
     
     player=load_bitmap("player.pcx",NULL);
     tiles=load_bitmap("tilemaps.pcx",NULL);
     
     px=32;
     py=32;
     dir=DOWN;
     frame=0;
}

// ---------------------------------------------------------------------
void borra_todo()
{
    if ( buffer )
        destroy_bitmap( buffer );

    if ( grid )
        destroy_bitmap( grid );
}

// -----------------------------------------------------------------------
void dibuja_player()
{
    textout(buffer,font,"3",px,py,-500);
}
// -----------------------------------------------------------------------
void dibuja_mapa()
{
  int i , j , x=0 , y=0;
       for(i=0;i<24;i++)
             {
                for(j=0;j<32;j++)
                      {
                      switch(mapa[j])
                            {
                            case 0: textout(grid,font,"0",j*TILESIZE,i*TILESIZE,255);break;
                            case 1: textout(grid,font,"1",j*TILESIZE,i*TILESIZE,5000);break;
                            case 2: blit(tiles,grid,x,0 * TILESIZE ,i * TILESIZE, j * TILESIZE, TILESIZE, TILESIZE);break;
                            }
                      }
             }
  blit( grid, buffer, 0, 0, 0, 0, TILES_ANCHO * TILESIZE, TILES_ALTO * TILESIZE );               
}
// -----------------------------------------------------------------------
void dibuja_todo()
{
     dibuja_mapa();
     dibuja_player();
     blitbuffer(buffer);
}
// ------------------------------------------------------------------------
void blitbuffer( BITMAP *bmp )
{
    acquire_screen();
    blit( bmp, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H );
    release_screen();
}       

// ------------------------------------------------------------------------
void inc_frame(int d)
{
   if (dir==UP)
   {   
  frame++;
  if (frame>1) frame=0;
   }
   if (dir==DOWN)
   {
  frame++;
  if (frame<4 || frame>5) frame=4;
   }
   if (dir==LEFT)
   {
  frame++;
  if (frame<6 || frame>7) frame=6;
   }
   if (dir==RIGHT)
   {
  frame++;
  if (frame<2 || frame>3) frame=2;
   }
}
// --------------------------------------------------------------
void mover(int d)
{
    int px_rel=px/TILESIZE;
    int py_rel=py/TILESIZE;
    dir=d;
   inc_frame(dir);
   switch(dir)
    {
    case LEFT:  if(mapa[py_rel][px_rel-1]!=0)px-=TILESIZE;break;
    case RIGHT: if(mapa[py_rel][px_rel+1]!=0)px+=TILESIZE;break;
   case UP:    if(mapa[py_rel-1][px_rel]!=0)py-=TILESIZE;break;
   case DOWN:  if(mapa[py_rel+1][px_rel]!=0)py+=TILESIZE;break;
    }
}

// ---------------------- MAIN ------------------------------------
int main()
{
    bool done = false;
    inicia_todo();

    while ( !done )
    {
        dibuja_todo();
        rest(50);

// ESC para salir

        if (key[ KEY_ESC ] ) done = true;
       
        if (key[ KEY_DOWN ] ) mover(DOWN);
        if (key[ KEY_UP ] ) mover(UP);
        if (key[ KEY_LEFT ] ) mover(LEFT);
        if (key[ KEY_RIGHT ] ) mover(RIGHT);
    }
    borra_todo();
    return 0;
}
END_OF_MAIN();

Bueno el programa en si anda, remplace los graficos por ceros y unos y un 3 para el personaje... esta basado basicamente en una matriz de ceros y unos  (0 para los tiles no caminables, 1 para los caminables)

El problema viene en la funcion mover(int d) porque el personaje se mueve de 32px a 32px y eso le quita mucha "delicadesa" al juego, es como si fuese a los saltos, lo que quiero hacer es que las cordenadas del personaje X e Y disminuyan o aumenten (depende la orden) en 8px en vez de 32 (TILESIZE), pero cuando cambio estos valores fallan las colisiones... si prueban el programa van a ver que de izq. a derecha y de arriba hacia abajo las colisiones andan perfecto pero cuando uno camina de derecha a izq. colisiona mucho antes de que choque con un 0... lo mismo de abajo hacia arriba.

Citar
    case LEFT:     if(mapa[py_rel][px_rel-1]!=0)px-=8;break;
    case RIGHT:  if(mapa[py_rel][px_rel+1]!=0)px+=8;break;
    case UP:       if(mapa[py_rel-1][px_rel]!=0)py-=8;break;
    case DOWN:  if(mapa[py_rel+1][px_rel]!=0)py+=8;break;


es solo eso, si algun entendido me puede dar una mano se agradece  :D

Páginas: [1]