Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL.h>
- #include <SDL_image.h>
- typedef struct {int x,y;}Point;
- int main()
- {
- SDL_Init(SDL_INIT_VIDEO);
- SDL_Surface *background=IMG_Load("game.png");
- Point cell={160,128};
- Point offset={background->w-cell.x,background->h-cell.y};
- SDL_Surface* display=SDL_SetVideoMode(cell.x,cell.y,0,0);
- int x=0;
- int y=0;
- while(1)
- {
- SDL_Event e;
- while(SDL_PollEvent(&e))
- {
- switch(e.type)
- {
- case SDL_QUIT:
- return 0;
- case SDL_KEYDOWN:
- switch(e.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- return 0;
- case SDLK_LEFT:
- x-=cell.x;
- break;
- case SDLK_RIGHT:
- x+=cell.x;
- break;
- case SDLK_UP:
- y-=cell.y;
- break;
- case SDLK_DOWN:
- y+=cell.y;
- break;
- default:
- break;
- }
- if(x<0)
- x=0;
- if(y<0)
- y=0;
- if(x>offset.x)
- x=offset.x;
- if(y>offset.y)
- y=offset.y;
- break;
- }
- }
- SDL_BlitSurface(background,&(SDL_Rect){x,y,display->w,display->h},display,NULL);
- SDL_Flip(display);
- }
- }
Add Comment
Please, Sign In to add comment