Skip to content

Instantly share code, notes, and snippets.

@Alos
Created April 27, 2011 05:49
Show Gist options
  • Save Alos/943779 to your computer and use it in GitHub Desktop.
Save Alos/943779 to your computer and use it in GitHub Desktop.
/**
Creates the objects that represent the model
*/
- (void) createObjects:(CPNumber)numberOfObjects{
var fixDef = new b2FixtureDef;
fixDef.density = 1.0;
fixDef.friction = 0.5;
fixDef.restitution = 0.2;
fixDef.shape = new b2CircleShape(
Math.random() + 0.1 //radius
);
for(var i=0; i<numberOfObjects; i++){
var bodyDef = new b2BodyDef;
bodyDef.type = b2Body.b2_dynamicBody;
var initialPosition = [self getNewInitialPosition];
CPLog.info("Position #%@: %@, %@",i ,initialPosition.x, initialPosition.y);
bodyDef.position.Set(initialPosition);
var body = world.CreateBody(bodyDef);
body.CreateFixture(fixDef);
body.SetBullet(false);
var initialForce = [self getNewInitialForce];
CPLog.info("Force #%@: %@, %@",i ,initialForce.x, initialForce.y);
body.ApplyForce(initialForce, ZERO_VECTOR);
[arrayOfObjects addObject: body];
}
debugger;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment