The problem is, my player just won't move.
Here is the code:
This is a part of my Player.cpp, where I handle input and move the player.
void Player::Handle_Input(SDL_Event* event)
{
if(event->type == SDL_KEYDOWN)
{
switch(event->key.keysym.sym)
{
case SDLK_RIGHT: xVel += 1; break;
case SDLK_LEFT: xVel -= 1; break;
}
}
else if(event->type == SDL_KEYUP)
{
switch(event->key.keysym.sym)
{
case SDLK_RIGHT: xVel -= 1; break;
case SDLK_LEFT: xVel += 1; break;
}
}
}
void Player::Move()
{
x += xVel;
}
This is my main.cpp. It handles events here.
int main(int argc, char* args[])
{
Game g;
Player Player;
SDL_Event event;
g.OnInit();
while(g.running)
{
while(SDL_PollEvent(&event))
{
g.OnEvent(&event);
Player.Handle_Input(&event);
}
g.OnLoop();
g.OnRender();
}
g.OnCleanup();
return 0;
}
Now, can somebody help me? I just can't make the player move. I'm out of ideas.
Thanks.