2017-04-21 36 views
-1
#include <stdlib.h> 
#include <stdio.h> 
#include <SDL/SDL.h> 

void pause() 
{ 
    int continuer = 1; 
    SDL_Event event; 

    while (continuer) 
    { 
     SDL_WaitEvent(&event); 
     switch(event.type) 
     { 
      case SDL_QUIT: 
       continuer = 0; 
     } 
    } 
} 

int main(int argc, char *argv[]) 
{ 
    SDL_Init(SDL_INIT_VIDEO); 
    SDL_Rect posBack, posbtn_jouer, posbtn_regles; 
    SDL_Surface *screen = NULL, *background = NULL, *btn_jouer = NULL, *btn_regles = NULL; 

    posBack.x = 0; 
    posBack.y = 0; 
    posbtn_jouer.x = 400; 
    posbtn_jouer.y = 460; 
    posbtn_regles.x = 400; 
    posbtn_regles.y = 570; 

    screen = SDL_SetVideoMode(1080, 720, 32, SDL_HWSURFACE); 
    background = SDL_LoadBMP("game_home.bmp"); 
    SDL_BlitSurface(background,NULL,screen,&posBack); 

    btn_jouer = SDL_LoadBMP("btn_jouer.bmp"); 
    SDL_SetColorKey(btn_jouer,SDL_SRCCOLORKEY,SDL_MapRGB(btn_jouer->format,255,255,255)); 
    SDL_BlitSurface(btn_jouer,NULL,screen,&posbtn_jouer); 

    btn_regles = SDL_LoadBMP("btn_regles.bmp"); // Ouverture du bouton regles 
    SDL_SetColorKey(btn_regles,SDL_SRCCOLORKEY,SDL_MapRGB(btn_regles->format,255,255,255)); 
    SDL_BlitSurface(btn_regles,NULL,screen,&posbtn_regles); 
    SDL_Flip(screen); 

    pause(); 

    SDL_FreeSurface(background); 
    SDL_FreeSurface(btn_jouer); 
    SDL_FreeSurface(btn_regles); 

    SDL_Quit(); 

    return EXIT_SUCCESS; 
} 

我使用SDL和C的游戏程序中,当我编译该代码时,消息“进程终止状态3(0分钟0秒(S ))“在我看来,我不明白是什么问题。我谷歌它,但没有发现任何可以帮助我...如果有人可以帮助我,我很困惑。过程终止状态3 - 码块

+0

什么是头文件(在编译时)和库(在链接时)没有包含在内,所以编译失败是由于没有包含'SDL'头文件。 – user3629249

+0

发布的代码ALSO并不干净地编译,因为'main()'的签名是'int main(int argc,char * argv [])',但参数未被使用。建议使用其他有效签名:'int main(void)' – user3629249

+1

为了便于阅读和理解:1)始终缩进代码。在每个大括号'{'后缩进。在每个大括号'}'之前unindent。为每个缩进级别建议4个空格 – user3629249

回答

0

首先,确保包含正确的头文件。你确定你没有使用吗?如果是,请使用<SDL2/SDL.h>作为标题。

其次,在

switch(event.type) 
    { 
     case SDL_QUIT: 
      continuer = 0; 
    } 

event.type不是类型char。使用语句。

第三,请检查您的文件的路径是否正确。他们必须从项目目录的根目录开始,或者指针backgroundbtn_jouer将为NULL