This is my first attempt at collision detection and I'm going to use bounding box / rectangle collision detection, do I need to check with all the objects on the map? If I have 100 different platforms, boxes and other stuff do I need to check with all of them if they collide with the player? This seems really tedious and inefficient..
I also have a problem with the keyboard input / events in my game, when I press left / right arrow key then press the up arrow key to jump while holding left / right it stops moving to the left / right.
What I thought would happen, if this is the event queue: right, right, right, up, right, right, right, etc etc.
What actually happens: Right, right, right, up then it stops.
Sorry if my explaining is a bit confusing. Here's some code.
Player.cpp Move function.
Player::vel_X += 1;
Player::vel_X -= 1;
The jumping function only sets the vel_Y to -20 and sets jumping = true
My game loop.
1 void Game::update(Player *p)
3 p->setX(p->getfX() + p->getfVel_X());
4 p->setY(p->getfY() + p->getfVel_Y());
5 if(p->getfVel_X() > 0.1 && !p->jumping) p->setVel_X(p->getfVel_X() - 0.5);
6 if(p->getfVel_X() < -0.1 && !p->jumping) p->setVel_X(p->getfVel_X() + 0.5);
7 if(p->getfY() < 400) p->setVel_Y(p->getfVel_Y() + 5);
8 if(p->getfY() == 400.0)
11 p->jumping = false;
13 if(p->getfY() > 400)
16 p->jumping = false;
Right now it's only a "P" being drawn on a black background, I'm trying to perfect character movement before I add platforms, images, sound etc
oh and, whats the difference between Player::vel_X and just typing vel_X in player.cpp?
Edit: nevermind, there is no difference between Player::vel_X and typing vel_X, it's a matter of style for anyone else who might be wondering the same thing