How should I design a "Proper" OO Pong?
The idea of Proper being that any element can be changed: The shape of the ball, the court, and the paddles, adding obstacles, and even "powerups", like "can stick the ball to the paddle".
The two more pressing questions, right now, are:
I imagine you could make a physics engine object that you update continuously at given time intervals. It would check for collisions, move the ball, compute bounce angles, etc.
EDIT #1: To add a little more detail, the "game physics" object would store, among other things, references to other game objects like the ball and paddles. The game physics object would have an "update" method that would be called continuously as the game runs. Some of the steps this method would perform are:
Just a few ideas.
EDIT #2: To elaborate with a bit more of an OO focus...
The various physical objects, like the ball and paddles, would store innate physical states and parameters for themselves (position, speed, mass, etc.) as properties. The game physics object would essentially represent all of the equations of physical motion as methods.
As an example... Let's say you want to model the effects of air friction on the ball. The ball object would store properties such as "velocity" and "drag coefficient". The game physics object would have a method for computing the force of air resistance on an object by fetching the necessary properties of that object and plugging them in to a given equation of fluid drag.
By encapsulating things in this way, updates to the code can be easier. For instance, if you want to use a different equation for fluid drag, the only modification you need to make is to the appropriate method of the game physics object. None of the other objects need to be modified.
Seems to me like the court would be the appropriate object to do the checking, or depending on how complex the logic is, a separate class for dealing with collisions (i.e. some kind of physics engine like gnovice said).
The balls and paddles shouldn't have to know about each other since they're not directly related in an object oriented sense. One doesn't contain the other nor does one derive from the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With