elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Audio en allegro en: 2 Junio 2019, 20:23 pm
Hola, estoy diseñando un videojuego en allegro y hasta ahora todo corre perfectamente pero tengo un problema con la musica de fondo.

Al estar tecleando para controlar el personaje la musica de repente se deja de reproducir, solo al estar controlando el personaje, si no muevo el personaje entonces todo esta bien.

Como puedo solucionar este problema??

dejo el código que estoy diseñando gracias.

#include <allegro.h>
#define ancho 1280
#define alto 720

using namespace std;

int main()
{
    int x=-593, y=0, z=80, up=0, pos=0, fx=0, sx=0, s=0;
    allegro_init();
   install_keyboard();
   set_volume(230, 200);

    if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL)!=0)
        {
            allegro_message("Error: inicializando sistema de sonido\n%s\n", allegro_error);
            return 1;
        }

   set_color_depth(32);
   set_gfx_mode(GFX_AUTODETECT_WINDOWED, ancho, alto, 0, 0);

    BITMAP *cargando = load_bitmap("cargando.bmp", NULL);
    draw_sprite(screen,cargando,0,0);
    SAMPLE *soundstart = load_wav("soundstart.wav");
    play_sample(soundstart,200,150,1000,0);
    SAMPLE *soundjump = load_wav("soundjump.wav");
   BITMAP *buffer = create_bitmap(ancho,alto);
    BITMAP *fondo1 = load_bitmap("fondo1.bmp", NULL);
    BITMAP *choque = load_bmp("fondolim.bmp",NULL);
    BITMAP *skin1 = load_bitmap("skin1.bmp", NULL);
    BITMAP *skin2 = load_bitmap("skin2.bmp", NULL);
    SAMPLE *soundtrack=load_wav("soundtrack.wav");
    stop_sample(soundstart);
    play_sample(soundtrack,200,150,1000,0);
    clear_to_color(buffer, 0xaaaaaa);
    blit(fondo1, buffer, fx, 0, 0, 0, 1280, 720);
    masked_blit(skin1, buffer, 89, 0, 0, 570-y, 89, 140);
    blit(buffer, screen, 0, 0, 0, 0, 1280, 720);


    while (!key[KEY_ESC])
    {
        //control de animación
        if (x%15==0){s=s+89;}
        if (s==356) {s=0;}
        if (x>0) {fx=x; sx=0;}
        else {fx=0; sx=x;}

        //control en y
        if ((key[KEY_W]||key[KEY_SPACE]||key[KEY_UP])&&up==0&&y==z-80){play_sample(soundjump,100,100,500,0); up=1;}
        if (y==z){up=0;}
        if (up==1){y++;}
        else {if (y>z-80){y--;}}
        if (getpixel( choque, 650+x, 710-y) == 0x0000ff) {z=y+80;}
        else {if (z>80){z--;}}

        //control en x
        if (key[KEY_D]||key[KEY_RIGHT])
            {
                pos=0;
                if (getpixel( choque, 662+x, 710-y) != 0xff0000){x++;}
            }
        if (key[KEY_A]||key[KEY_LEFT])
            {
                pos=1;
                if (getpixel( choque, 658+x, 710-y) != 0xff0000){x--;}
            }

        //control de movimiento
        if (pos==0)
            {
                if (up==0)
                    {
                        if (y>z-80)
                            {
                                blit(fondo1, buffer, fx, 0, 0, 0, 1280, 720);
                                masked_blit(skin1, buffer, 363, 0, 598+sx, 570-y, 93, 140);
                            }
                        else
                            {
                                if (key[KEY_D]||key[KEY_RIGHT])
                                    {
                                        blit(fondo1, buffer, fx, 0, 0, 0, 1280, 720);
                                        masked_blit(skin1, buffer, s, 0, 598+sx, 570-y, 89, 140);
                                    }
                                else
                                {
                                    blit(fondo1, buffer, fx, 0, 0, 0, 1280, 720);
                                    masked_blit(skin1, buffer, 89, 0, 598+sx, 570-y, 89, 140);
                                }
                            }
                    }
                if (up==1)
                    {
                        blit(fondo1, buffer, fx, 0, 0, 0, 1280, 720);
                        masked_blit(skin1, buffer, 466, 0, 598+sx, 570-y, 93, 140);
                    }
            }
        if (pos==1)
            {
                if (up==0)
                    {
                        if (y>z-80)
                            {
                                blit(fondo1, buffer, fx, 0, 0, 0, 1280, 720);
                                masked_blit(skin2, buffer, 365, 0, 598+sx, 570-y, 93, 140);
                            }
                        else
                            {
                                if (key[KEY_A]||key[KEY_LEFT])
                                    {
                                        blit(fondo1, buffer, fx, 0, 0, 0, 1280, 720);
                                        masked_blit(skin2, buffer, s, 0, 598+sx, 570-y, 89, 140);
                                    }
                                else
                                {
                                    blit(fondo1, buffer, fx, 0, 0, 0, 1280, 720);
                                    masked_blit(skin2, buffer, 89, 0, 598+sx, 570-y, 89, 140);
                                }
                            }
                    }
                if (up==1)
                    {
                        blit(fondo1, buffer, fx, 0, 0, 0, 1280, 720);
                        masked_blit(skin2, buffer, 469, 0, 598+sx, 570-y, 93, 140);
                    }
            }
        //control de imagen
        blit(buffer, screen, 0, 0, 0, 0, 1280, 720);
    }

    destroy_bitmap(buffer);
    destroy_sample(soundstart);
    destroy_sample(soundtrack);
    destroy_sample(soundjump);

    return 0;
}
END_OF_MAIN();
2  Programación / Programación C/C++ / Re: Allegro en: 29 Mayo 2019, 01:50 am
Es fácil, solo tienes que mover el contenido de la carpeta debug a la carpeta principal, ya que si lo ejecutas desde la carpeta debug el ejecutable no encuentra ninguna información para correr, es por eso que tienes que tienes que mover el ejecutable junto al archivo creado por allegro a la carpeta principal donde se encuentra el main.cpp y los otros archivos bmp, mid, wav y demás que utilizaste. Suerte!!!
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines