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

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  problemas con sdl al ejecutar mi muñeco
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: problemas con sdl al ejecutar mi muñeco  (Leído 2,070 veces)
peterfly

Desconectado Desconectado

Mensajes: 94


Ver Perfil
problemas con sdl al ejecutar mi muñeco
« en: 23 Septiembre 2011, 14:02 pm »

Hola

Oy me e bajado de internet un codigo para ver si me funciona el sdl con c++

Pero cuando ejecute dicho codigo se me cierra recien lo ejecuto...

El codigo es
Código:
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
void limpiar (SDL_Surface *screen);
void imprimir(SDL_Surface *screen, SDL_Surface *ima, int x, int y);
void mover_objeto(int *x, int *y, int ancho, int alto);
int main(int argc, char *argv[])
{
SDL_Surface *screen;
SDL_Surface *ima;
Mix_Music *cancion;
SDL_Event event;
int salir = 0;
int x = 100;
int y = 100;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1)
{
printf("Error: %s\n", SDL_GetError());
return 1;
}
screen = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE);
if (screen == NULL)
{
printf("Error: %s\n", SDL_GetError());
return 1;
}
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1)
{
printf("Error en Mix_OpenAudio: %s\n", Mix_GetError());
return 1;
}
SDL_WM_SetCaption("Ejemplo 2", NULL);
ima = IMG_Load("c:/ima.png");
if (ima == NULL)
{
printf("Error en IMG_Load= %s\n", SDL_GetError());
return 1;
}
cancion = Mix_LoadMUS("c:/cancion.xm");
if (!cancion)
printf("Error en Mix_LoadMUS: %s\n", Mix_GetError());
if (cancion)
{
if (Mix_PlayMusic(cancion, -1) == -1)
printf("Error en Mix_PlayMusic: %s\n", Mix_GetError());
}
while (! salir)
{
SDL_PollEvent(&event);
if (event.type == SDL_QUIT)
salir = 1;
mover_objeto(&x, &y, ima->w, ima->h);
limpiar(screen);
imprimir(screen, ima, x, y);
SDL_Flip(screen);
SDL_Delay(10);
}
if (cancion)
{
Mix_HaltMusic();
Mix_FreeMusic(cancion);
}
Mix_CloseAudio();
SDL_Quit();
return 0;
}
void limpiar (SDL_Surface *screen)
{
Uint32 a = SDL_MapRGB(screen->format, 200, 200, 200);
SDL_FillRect(screen, NULL, a);
}
void imprimir(SDL_Surface *screen, SDL_Surface *ima, int x, int y)
{
SDL_Rect rect = {x, y, 0, 0};
SDL_BlitSurface(ima, NULL, screen, &rect);
}
void mover_objeto(int *x, int *y, int ancho, int alto)
{
Uint8 *key = SDL_GetKeyState(NULL);
if (key[SDLK_LEFT] && * x > 0)
(*x) -= 5;
if (key[SDLK_RIGHT] && (*x + ancho) < 320)
(*x) += 5;
if (key[SDLK_UP] && *y > 0)
(*y) -= 5;
if (key[SDLK_DOWN] && (*y + alto) < 240)
(*y) += 5;
}

Como puedo acer para que no se cierre en cuanto lo ejecuto???


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
No se me regenera el muñeco en Battlefield 2142
Juegos y Consolas
Cergath 1 1,536 Último mensaje 19 Octubre 2008, 05:32 am
por valx00
Problemas al ejecutar aplicacion .net en XP
.NET (C#, VB.NET, ASP)
Skeletron 9 6,630 Último mensaje 18 Mayo 2009, 13:13 pm
por Meta
¿Cuál es el nombre de este muñeco?
Foro Libre
Psyke1 3 6,204 Último mensaje 10 Enero 2011, 23:00 pm
por ignorantev1.1
PROBLEMAS AL EJECUTAR SQLMAP
Scripting
camilo07 2 2,272 Último mensaje 2 Octubre 2015, 19:09 pm
por camilo07
Problemas al ejecutar BO2 Redacted
Juegos y Consolas
L3I_W0N6 1 9,587 Último mensaje 10 Febrero 2016, 20:22 pm
por Machacador
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines