Ver Mensaje Individual
  #16 (permalink)  
Antiguo 19/09/2012, 15:32
harryarcoiris
 
Fecha de Ingreso: agosto-2012
Mensajes: 94
Antigüedad: 11 años, 8 meses
Puntos: 7
Respuesta: SDL C No compila

Hola!!

Gracias Lemon!!! Esa es la funcion y anda de lujo. Ahora ese cuadrado blanco se ve del color de fondo (por ahora negro). Pero tengo un problema con el sonido. Necesito que reproduzca un simple Wav. Pero no lo hace, trabaja con SDL_Mixer, y juro por mi que esta bien linkeado, ahora aprendi a hacerlo bien. Ya que intente hacer que reproduzca, solo usando el codigo de el audio, y anduvo de lujo.

Dejo Code: //Flier Land Rover por Alejandro*/
/*El programa genera un auto, y permite moverlo por la pantalla. Ademas, prende y apaga la luz de retroceso si retrocede,
y el audio aun no funciona, pero estoy haciendo un code para un juego.*/

#include <stdio.h>
#include "SDL.h"
#include <SDL_mixer.h>
const int WINDOW_WIDTH = 1020;//altura de ventana
const int WINDOW_HEIGHT = 709;//ancho de ventana
const char* WINDOW_TITLE = "Flier Land Rover";//titulo de ventana

int main(int argc, char **argv)
{
int x, y;//posicion inicial de el vehiculo
x = 100;
y = 100;


//Idea: Hacer el vehiculo fuera de la pantalla y que entre con el sonido actual
SDL_Init( SDL_INIT_VIDEO |SDL_INIT_AUDIO);
//Inicia el Sonido y el Video
SDL_Surface *image;
//Buffer de Imagen
SDL_Rect dest;
//Posicion de superficie cuadrada que contiene el BMP
SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);//Inicia la ventana
SDL_WM_SetCaption( WINDOW_TITLE, 0 );
//Titulo de ventana
SDL_Event event;
//Deteccion de eventos
Mix_Chunk *sonido;
//apuntador a variable que contiene el sonido.
bool luz_blanca = false;
//Variable Booleana que maneja la luz trasera
bool gameRunning = true;
//Variable Booleana que maneja el cierre del bucle loop.
int canal;
//Variable de Canal de Sonido

if(Mix_OpenAudio(22050, AUDIO_S16, 2, 4096)) {
printf("No se puede inicializar SDL_mixer %s\n",Mix_GetError());
exit(1);
}
//Inicia los parametros de el sonido
sonido = Mix_LoadWAV("car-ignition-2.wav");
//La variable sonido ahora contiene el archivo car-ignition-2.wav
while (gameRunning)//Inicio del Loop
{

if(luz_blanca == false)
{
image = SDL_LoadBMP("LandRover.bmp");

canal = Mix_PlayChannel(-1, sonido, 0);
}
else
{
image = SDL_LoadBMP("LandRover1.bmp");
luz_blanca = false;
canal = Mix_PlayChannel(-1, sonido, 0);
if(Mix_Playing(canal) == 1)
{
printf("Se esta reproduciendo");
getchar();
}
}

SDL_SetColorKey(image,SDL_SRCCOLORKEY|SDL_RLEACCEL ,SDL_MapRGB(image->format,255,255,255));
dest.x = x;
dest.y = y;
dest.w = image->w;
dest.h = image->h;


SDL_BlitSurface(image, NULL, screen, &dest);


SDL_Flip(screen);

SDL_FreeSurface(screen);

dest.x = x;
dest.y = y;
dest.w = image->w;
dest.h = image->h;
SDL_FillRect(screen,&dest,SDL_MapRGB(screen->format,0,0,0));


Uint8 *keys;
keys=SDL_GetKeyState(NULL);
if (keys[SDLK_UP] == 1)
{
y = y - 1;
}
if (keys[SDLK_DOWN] == 1)
{
y = y + 1;
}
if (keys[SDLK_LEFT] == 1)
{
x = x - 1;
luz_blanca = true;
}
if (keys[SDLK_RIGHT] == 1)
{x = x + 1;}


if (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
gameRunning = false;
}

}


keys=SDL_GetKeyState(NULL);
if (keys[SDLK_ESCAPE] == 1) {gameRunning = false;}

}


SDL_Quit();
return 0;
}