首页 文章 SDL.c

SDL.c

2023-03-08 14:03  浏览数:1508  来源:小键人12970039    

#include <SDL.h>
int main(int argc, char** argv){
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = SDL_CreateWindow("title",SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,800,600,SDL_WINDOW_SHOWN);
SDL_Renderer* render = SDL_CreateRenderer(window,-1,0);
SDL_Rect rect = {100,100,50,50};
SDL_Event event;
SDL_bool running = SDL_TRUE;
const Uint8* keyState;
int speed = 6;
while(running){
SDL_PollEvent(&event);
if(event.type == SDL_QUIT) running = SDL_FALSE;
keyState = SDL_GetKeyboardState(NULL);
if(keyState[SDL_SCANCODE_UP]) rect.y -= speed;
if(keyState[SDL_SCANCODE_DOWN]) rect.y += speed;
if(keyState[SDL_SCANCODE_RIGHT]) rect.x += speed;
if(keyState[SDL_SCANCODE_LEFT]) rect.x -= speed;
SDL_SetRenderDrawColor(render,0,0,0,255);
SDL_RenderClear(render);
SDL_SetRenderDrawColor(render,0,255,0,255);
SDL_RenderFillRect(render,&rect);
SDL_RenderPresent(render);
SDL_Delay(1000/120);
}
SDL_DestroyRenderer(render);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)