#include int main() { int i,j,quit=0; SDL_Surface *screen; SDL_Surface *box; SDL_Surface *box2; SDL_Surface *background; SDL_Event event; SDL_Rect offset; SDL_Rect offset2; SDL_Init(SDL_INIT_EVERYTHING); // creates a surface for the image screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE); background=IMG_Load("background.bmp"); //renders the image box=IMG_Load("box.bmp");//loads the image saved in this file and attaches it to box box2=IMG_Load("box2.bmp"); offset2.x=0; // sets offset2 starting position to (0,0) offset2.y=0; while(quit==0) { SDL_BlitSurface(background, NULL, screen, NULL); if(SDL_PollEvent(&event)) { if(event.type==SDL_KEYDOWN) // . is a structure?? { switch(event.key.keysym.sym) { case SDLK_ESCAPE: // escape key is being set to quit the program quit=1; break; case SDLK_RETURN: offset.x=320; offset.y=240; offset.w=box->w; offset.h=box->h; break; case SDLK_UP:// up key can be replaced by lower case w capital W means you have to hold shift down every time you hit w. offset.y=offset.y-10; break; // with programming screens 0,0 is the top right corner of the screen not center like math class. case SDLK_DOWN: offset.y=offset.y+10; break; case SDLK_RIGHT: offset.x=offset.x+10; break; case SDLK_LEFT: offset.x=offset.x-10; break; } } else if(event.type == SDL_QUIT) quit = 1; } if(offset2.x <= 0) i=10; else if(offset2.x >=640) i=-10; if(offset2.y <= 0) j=10; else if(offset2.y >=480) j=-10; offset2.x +=i; //offset2 is a box that moves on its own bouncing around on the walls. offset2.y +=j; SDL_BlitSurface(box2,NULL,screen,&offset2); SDL_BlitSurface(box,NULL,screen,&offset); SDL_Flip(screen); SDL_Delay(10); } return(0); }