I second SC's comments:
1. Dehydration is the most likely culprit. Hydration tends to be a slow process, so drinking more on the day of a game may not be enough (and drinking right after the game may be too late to avoid painful side effects like you're seeing). You need to keep yourself well hydrated at all times, especially starting a couple days before strenuous activity, and then make sure to replenish fluids during the game as well. For games under an hour, drinking some water during breaks is typically enough. For longer games, consider drinking something like gatorade.
2. A poor diet could be at fault too. If you don't eat enough food to fuel your body, you can easily end up feeling like crap. Basketball burns a whole lot of calories per hour, so make sure you eat a solid meal a few hours before the game.
3. Finally, it is possible that your body is just not used to the strain of extended exercise. Consider playing at half pace, or shorter games, or taking more breaks for a little while. Let your body adapt and gradually ramp your way up.