Home Article Practice SDL.c

SDL.c

2023-03-08 14:03  views:1502  source:小键人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;
}



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

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