Game Development Reference
In-Depth Information
no knowledge of the def. You
ll notice throughout the code
below that class names in Box2D consistently end with
when they refer to this construct.
s now look at how these principles work in the context of
our engine.
public class AirHockeyEngine
public static const DISTANCE_RATIO:Number = 30;
private var mPhysicsEngine:b2World;
private var mConfig:AirHockeyEngineConfig;
private var mPlayer1:b2Body, mPlayer2:b2Body;
private var mPuck:b2Body, mGoal1:b2Body, mGoal2:b2Body;
private var mCollisionBodies:Vector.
private var mPlayer1Joint:b2MouseJoint, mPlayer2Joint:
// Origin positions
private var mPlayer1Origin:b2Vec2, mPlayer2Origin:
b2Vec2, mPuckOrigin:b2Vec2;
ratio I mentioned a moment ago. We then define member variables
for the different Box2D components we
ll want to keep track of: the
world and bodies for the paddles, puck, goals, and walls. There
member variable to keep track of the engine config object we cre-
ated earlier in the Game class. We also define a new kind of object
called a b2MouseJoint. Joints are used in Box2D to connect two
objects to each other with some kind of physical constraints. In the
case of a b2MouseJoint, we
to the world object so that we can use the mouse (or in our situa-
tion, touch input) to apply forces to it. We
ll see how this works
shortly. The last thing we define are origin positions for the two
paddles and the puck. These b2Vec2 objects, which you can sort of
think of like a cross between the Point and Vector3D objects in
ActionScript, will keep the original positions of the objects so that
we can restore the state of the game board at a moment
s notice.
public function AirHockeyEngine( _config:AirHockeyEngineConfig )
if ( !_config )
throw new ArgumentError( " The AirHockeyEngine
requires a AirHockeyEngineConfig struct to
instantiate. " );
mConfig = _config;
Search Nedrilad ::

Custom Search