c语言sdl小游戏,求求求!用C和sdl写的打飞机小游戏

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include #include #include

int main() {

SDL_Surface *screen = NULL; SDL_Surface *tank = NULL; SDL_Rect tankPosition; SDL_Event event; int wantsToQuit = 0;

SDL_Init(SDL_INIT_VIDEO);

screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE ); SDL_WM_SetCaption("SDL events handling", NULL);

tank = SDL_LoadBMP("tank.bmp"); SDL_SetColorKey( tank, SDL_SRCCOLORKEY, SDL_MapRGB(tank->format, 255, 19, 255) ); tankPosition.x = 0; tankPosition.y = 0;

while (!wantsToQuit) { SDL_WaitEvent(&event); switch(event.type) { case SDL_QUIT: wantsToQuit = 0; break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_UP: tankPosition.y--; break; case SDLK_DOWN: tankPosition.y++; break; case SDLK_RIGHT: tankPosition.x++; break; case SDLK_LEFT: tankPosition.x--; break; } break; }

// we clean the screen SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 255)); // we draw GMH at the new position SDL_BlitSurface(tank, NULL, screen, &tankPosition); // we update what the user see SDL_Flip(screen); }

SDL_FreeSurface(tank); SDL_Quit();

return EXIT_SUCCESS;}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值