给我一些帮助,我在执行任务时遇到了问题。我正在使用一种称为代码块的软件。
使用SDL 2.0库文件,为Vulture Trouble Game设计一个示例用户界面。游戏的分辨率为640 x480。在设计游戏界面时,必须使用给定的图像(在媒体文件文件夹下)。 它将显示游戏说明并暂停15秒钟。之后,它将切换到主界面。
#ifndef _LIBRARY_
#define _LIBRARY_
#include<SDL.h>
#include<SDL_image.h>
const int WIDTH = 640;
const int HEIGHT = 480;
//prototype
SDL_Window * window = NULL;
SDL_Surface * backBuffer = NULL;
bool initGame(const char*title, int x, int y, int w, int h);
void fillRectangle(SDL_Surface *buffer, int x, int y, int w, int h, Uint8 r, Uint8 g, Uint8 b);
SDL_Surface *loadBMPImage(const char *filename);
SDL_Surface *loadImageFile(const char *filename, int colorMode);
void drawImage(SDL_Surface *dest, SDL_Surface * Source, int x ,int y);
//body
bool initGame(const char *title,int x,int y,int w,int h){
int result = SDL_Init(SDL_INIT_EVERYTHING);
if(result<0){
return false;
}
window = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_SHOWN);
if(window==NULL){
return false;
}
backBuffer = SDL_GetWindowSurface(window);
return true;
}
void fillRectangle(SDL_Surface*buffer , int x, int y, int w, int h, Uint8 r,Uint8 g, Uint8 b){
Uint32 color = SDL_MapRGB(buffer->format,r,g,b);
SDL_Rect rect;
rect.x=x;
rect.y=y;
rect.w=w;
rect.h=h;
SDL_FillRect(backBuffer,&rect,color);
}
SDL_Surface *loadBMPImage(const char *filename){
SDL_Surface *image = SDL_LoadBMP(filename);
if(image==NULL){
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION,"Error! Fail to load image files.",NULL);
SDL_Quit();
return NULL;
}
return image;
}
SDL_Surface *loadImageFile(const char *filename,int colorMode){
SDL_Surface *image = NULL;
SDL_Surface *processedImage = NULL;
image = IMG_Load(filename);
if(image == NULL){
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION,"Error! Fail to load graphic file",NULL);
}
else{
processedImage = SDL_ConvertSurface(image,backBuffer->format,0);
SDL_FreeSurface(image);
if(processedImage != NULL){
Uint32 colorKey;
if (colorMode==1)
colorKey = SDL_MapRGB(processedImage->format,255,0,0);
else if(colorMode==2)
colorKey = SDL_MapRGB(processedImage->format,0,255,0);
else if(colorMode==2)
colorKey = SDL_MapRGB(processedImage->format,0,0,255);
else
colorKey = SDL_MapRGB(processedImage->format,255,0,255);
SDL_SetColorKey(processedImage,SDL_TRUE,colorKey);
}
}
return processedImage;
}
void drawImage(SDL_Surface *dest, SDL_Surface *Source, int x, int y){
SDL_Rect location;
location.x=x;
location.y=y;
SDL_BlitSurface(source,NULL,dest,&location);
}
#endif // _LIBRARY_`enter code here`
我希望代码可以运行,但是有错误。