Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://www.youtube.com/user/thecplusplusguy
- //multiple rect
- #include <SDL/SDL.h>
- int main()
- {
- SDL_Init(SDL_INIT_EVERYTHING);
- SDL_Surface* screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
- Uint32 start;
- SDL_Event event;
- bool running=true;
- SDL_Rect rec1;
- SDL_Rect rec2;
- rec1.x=60;
- rec1.y=90;
- rec1.w=30;
- rec1.h=30;
- rec2.x=140;
- rec2.y=120;
- rec2.w=30;
- rec2.h=30;
- while(running)
- {
- start=SDL_GetTicks();
- while(SDL_PollEvent(&event))
- {
- switch(event.type)
- {
- case SDL_QUIT:
- running=false;
- break;
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- running=false;
- break;
- }
- }
- }
- SDL_FillRect(screen,&rec1,SDL_MapRGB(screen->format,255,0,0));
- SDL_FillRect(screen,&rec2,SDL_MapRGB(screen->format,0,0,255));
- SDL_Flip(screen);
- if(1000.0/30>SDL_GetTicks()-start)
- SDL_Delay(1000.0/30-(SDL_GetTicks()-start));
- }
- SDL_Quit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement