SDL and Rectangle movement not moving ?

Started by
0 comments, last by Tom Sloper 12 years, 3 months ago
Hello I'm building a game and I want the background to keep moving too the left here is a video showcasing the problem

http://www.youtube.c...z0KsSWtcA#t=56s

but the backgrond will not continue left but bounce off and keep repeating as you can clearly see in the video

here is the code causing the problem I spent all day tweaking this code with no luck what so ever



int LevelOneFunction(void *unused)
{
SDL_Rect MainRect;
SDL_Rect LevelOneRect;
SDL_Rect GroundOneRect;
SDL_Rect MarioRect;
MainRect.x = 10;
MainRect.y = 0;
MarioRect.x = 0;
MarioRect.y = 280;

LevelOneRect.x = -10;
LevelOneRect.y = 0;
GroundOneRect.x = 0;
GroundOneRect.y = 0;

SDL_FillRect(Screen,NULL,(0,0,0));

SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);

SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
SDL_Flip(Screen);

//On and Off Level One Switch
bool done = false;

//Event Creation
SDL_Event event;
//While Done is equal false
while(!done)
{
//While continous events are running in event
while(SDL_PollEvent(&event))
{
//allow to be able to switch events
switch(event.type)
{
//if user presses on close
case SDL_QUIT:
//Close Application
return 0;

//break case
break;

//While Any Key is Down
case SDL_KEYDOWN:
//Allow Keyboard Events
switch(event.key.keysym.sym)
{
//Up is Pressed
case SDLK_RIGHT:

LevelOneRect.x +=6;
GroundOneRect.x +=2;
MarioRect.x+=8;
//First Frame
SDL_FillRect(Screen,NULL,(0,0,0));
MainRect = LevelOneRect ;
SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);
MainRect = GroundOneRect ;
SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
MainRect = MarioRect ;
SDL_BlitSurface(SuperMarioWalk1Surf,NULL,Screen,&MarioRect);
SDL_Flip(Screen);

/////////////////////////////////////////
//Second Frame
SDL_FillRect(Screen,NULL,(0,0,0));
MainRect = LevelOneRect;
SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);
MainRect = GroundOneRect;
SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
MainRect = MarioRect;
SDL_BlitSurface(SuperMarioWalk2Surf,NULL,Screen,&MarioRect);
SDL_Flip(Screen);

/////////////////////////////////////////

//Third Frame
SDL_FillRect(Screen,NULL,(0,0,0));
MainRect = LevelOneRect;
SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);
MainRect = GroundOneRect;
SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
MainRect = MarioRect;
SDL_BlitSurface(SuperMarioWalk3Surf,NULL,Screen,&MarioRect);
SDL_Flip(Screen);

/////////////////////////////////////////

break;

}
break;
}

}

}

}
Advertisement
This isn't a Game Design question. Moving it elsewhere.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement