So im making a pong clone and i have a silly problem.
I have a Paddle class with HandleInput(), Update(), and Draw() functions. The HandleIput and Update functions look like this at the moment.
void Paddle::HandleInput( Keyboard& keyboard )
{
if( keyboard.KeyIsHeld( m_upKey ) )
m_position.y -= m_moveSpeed;
if( keyboard.KeyIsHeld( m_downKey ) )
m_position.y += m_moveSpeed;
}
void Paddle::Update( float deltaTime )
{
}
The problem is that i want the position to be changed over time but at the moment the "Update" function is the one who is passed the delta time. It's a stupid problem but i can't figure out a nice way around it.
I want to avoid passing the delta time to the "HandleInput" function because it wouldn't really make sense, and also these function are actually an interface to a game object so it would mean passing it to every "HandleInput" function, whether it needed it or not. I could add a couple booleans to track whether either of the keys were pressed during "HandleInput" but that is essentially testing the same thing twice. I'm leaning towards the idea of adding a "delta position" variable to track the change in position, so the code would look something like this.
void Paddle::HandleInput( Keyboard& keyboard )
{
if( keyboard.KeyIsHeld( m_upKey ) )
m_deltaY -= m_moveSpeed;
if( keyboard.KeyIsHeld( m_downKey ) )
m_deltaY += m_moveSpeed;
}
void Paddle::Update( float deltaTime )
{
m_position.y += (m_deltaY * deltaTime);
m_deltaY = 0;
}
What do you guys think is the best solution?