Game Development Reference
In-Depth Information
// [self applyForceTowardsFinger];
Now you can add the Plunger class, which I've already done in the Physic-
sBox2DPinball01 project. Listing 13-14 shows the Plunger class's interface,
which is also derived from BodySprite .
Listing 13-14 . The Plunger's Header File
#import "BodySprite.h"
@interface Plunger : BodySprite
b2PrismaticJoint* joint;
+(id) plungerWithWorld:(b2World*)world;
The Plunger class has a member variable for b2PrismaticJoint , which it's go-
ing to use to propel itself upward. A prismatic joint allows only one axis of move-
ment—a telescope bar would be a good example of a prismatic joint in the real world.
You can only move the smaller pipe inside the larger pipe, which allows the telescope
bar to be extended and retracted, but only in one direction.
Initializing the plunger is also straightforward, as Listing 13-15 shows. I edited the
plunger's physics settings in PhysicsEditor. In particular, I set the friction to a very
high value and set restitution to 0. This ensures that the ball is launched smoothly by
remaining in close contact with the plunger during the time the plunger is propelled up-
Listing 13-15 . Initializing the Plunger
#import "Plunger.h"
@implementation Plunger
-(id) initWithWorld:(b2World*)world
Search Nedrilad ::

Custom Search