Permalink
Browse files

+ Absolute Positoning for Paddles

  • Loading branch information...
1 parent c6ddfef commit 5782cdd7703eaace7e4dc95ca50005c33dd446a1 @moritzh moritzh committed Jan 10, 2012
Showing with 3 additions and 29 deletions.
  1. +3 −29 PeerPong/PeerPongPaddle.mm
View
@@ -95,7 +95,7 @@ -(void)updateLivesLeftLabel {
-(void)addPhysics {
// Create paddle body
b2BodyDef bodyDef;
- bodyDef.type = b2_dynamicBody;
+ bodyDef.type = b2_staticBody;
b2Vec2 pos = [self getLocation];
bodyDef.position.Set(pos.x, pos.y);
@@ -116,20 +116,10 @@ -(void)addPhysics {
shapeDef.restitution = 0.1f;
fixture = body->CreateFixture(&shapeDef);
- // Restrict paddle along the x axis
- b2PrismaticJointDef jointDef;
- jointDef.collideConnected = true;
- jointDef.Initialize(body, gameplay.groundBody,
- body->GetWorldCenter(), [self getAxis]);
- joint = gameplay.world->CreateJoint(&jointDef);
}
-(void)removePhysics {
- // If user didn't move his paddle mouseJoint is NULL
- if (mouseJoint != NULL) {
- gameplay.world->DestroyJoint(mouseJoint);
- }
- gameplay.world->DestroyJoint(joint);
+
body->DestroyFixture(fixture);
gameplay.world->DestroyBody(body);
}
@@ -163,24 +153,8 @@ -(b2Vec2)getAxis {
}
-(void)update {
- if (mouseJoint == NULL) {
b2Vec2 locationWorld = [self getLocation];
-
- if (fixture->TestPoint(locationWorld)) {
- b2MouseJointDef md;
- md.bodyA = gameplay.groundBody;
- md.bodyB = body;
- md.target = locationWorld;
- md.collideConnected = true;
- md.maxForce = 1000.0f * body->GetMass();
-
- mouseJoint = (b2MouseJoint *)gameplay.world->CreateJoint(&md);
- body->SetAwake(true);
- }
- } else {
- b2Vec2 locationWorld = [self getLocation];
- mouseJoint->SetTarget(locationWorld);
- }
+ body->SetTransform(locationWorld, 0);
}

0 comments on commit 5782cdd

Please sign in to comment.