首頁 文章 SDL.c

SDL.c

2023-03-08 14:03  瀏覽數:1482  來源:小键人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)