Original Post
Hi there again! I'm having a problem with events. I have a code like this to handle inputs and to show blocks: And the HandleInput() definition is: Show() definition is something like this: And finally, my CheckCollision() function is something like this: Ok. The problem comes when block falls on the ground and a new block appears. Because block's constructor sets xVel and yVel to 0.. the new block has xVel = 0 and yVel = 0, if you're pressing a key or not! Then.. suppose you're pressing the left key and a new block appears. If you release the left key, the xVel of that block will be set to 23. So the block will move itself to the right without worrying if you're pressing a key or not. How can I solve it? I tried to set a temporary xVel and another with yVel to copy them to the new block before it appears. It works with the first three blocks but the next block has the same problem again! help me please. I'm getting frustrated :( Thank u in advance for your help! [Edited by - GutyGu on July 10, 2006 7:49:55 PM]
while ( SDL_PollEvents( &event ) )
{
if ( event.type == SDL_QUIT )
{
quit = true;
}
block.HandleInput();
}
block.Show();
Blocks::HandleInput()
{
if ( active == true )
{
if ( event.type == SDL_KEYDOWN )
{
switch ( event.key.keysym.sym )
{
case SDLK_LEFT:
xVel = xVel - BLOCK_SIZE;
break;
case SDLK_RIGHT:
xVel = xVel + BLOCK_SIZE;
break;
}
}
if ( event.type == SDL_KEYUP )
{
switch ( event.key.keysym.sym )
{
case SDLK_LEFT:
xVel = xVel + BLOCK_SIZE;
break;
case SDLK_RIGHT:
xVel = xVel - BLOCK_SIZE;
break;
}
}
}
}
Blocks::Show()
{
x = xVel;
y = yVel;
ApplySurface( x, y, block, screen );
}
Blocks::CheckCollision()
{
if ( activa == true )
{
if ( y + temp2->h == GROUND )
{
yVel -= yVel;
xVel -= xVel;
activa = false;
return true;
}
}
return false;
}