Commits

Anonymous committed d178b8c

reduce PTM and add configrable radius parameter for balls

Comments (0)

Files changed (4)

         return ground;
     }
 
-    var createBall = function(world, x, y, userData) {
+    var createBall = function(world, x, y, radius, userData) {
         var shape = new Box2D.b2CircleShape();
-        shape.set_m_radius(0.25); //a 0.5x0.5 rectangle
+        shape.set_m_radius(radius); //a 0.5x0.5 rectangle
         var bd = new Box2D.b2BodyDef();
         bd.set_bullet(true);
         bd.set_type(Box2D.b2_dynamicBody);
         bd.set_position(new Box2D.b2Vec2(x, y));
         var body = world.CreateBody(bd);
         body.userData = userData;
-        var fixture = body.CreateFixture(shape, 1.0);
+        var fixtureDef = new Box2D.b2FixtureDef();
+        fixtureDef.set_shape( shape );
+        fixtureDef.set_restitution( 0.5 );
+        fixtureDef.set_density( 1.0 );
+        var fixture = body.CreateFixture( fixtureDef );
+        //var fixture = body.CreateFixture(shape, 1.0);
         body.SetFixedRotation(false);
         return {body:body, fixture:fixture};
     }
 "use strict";
 define(['createjs','debugDraw'],function(createjs, debugDraw) {
-    var PTM = 26;
+    var PTM = 26/2;
     var canvas = document.getElementById("2space");
     var context = canvas.getContext('2d');
     var world = undefined;
         warpHoleColumns: 11,
         warpHoleRows: 11,
         frameSize: 9.09,
-        FLARThreshold: 64
+        FLARThreshold: 90,
     }
 });
         });
     }
 
-    var createBallSprite = function(red,green,blue) {
+    var createBallSprite = function(radius, red,green,blue) {
         var g = new createjs.Graphics();
         g.setStrokeStyle(1);
         g.beginStroke(createjs.Graphics.getRGB(0,0,0));
         g.beginFill(createjs.Graphics.getRGB(red,green,blue));
-        g.drawCircle(0,0,10);
+        g.drawCircle(0,0,radius*display2d.PTM);
         var shape = new createjs.Shape(g);
         shape.regX = 0;
         shape.regY = 0;
 
     var createBall = function(ballType,x,y) {
         var colors = ballColors[ballType];
-        var ball = bodies.createBall(world, x, y, {
+        var radius = 0.50;
+        var ball = bodies.createBall(world, x, y, radius, {
             attributes: {
                 isBall:true,
                 ballType:ballType,
             },
-            sprite:createBallSprite(colors.r,colors.g,colors.b)
+            sprite:createBallSprite(radius, colors.r,colors.g,colors.b)
         });
         display2d.stage.addChild( ball.body.userData.sprite );
         actors.push( ball );
     var createWarpHoleSprite = function(filename) {
         var data = {
             images: [filename],
-            frames: {width:80, height:80, regX:40, regY:40},
+            frames: {width:60, height:60, regX:30, regY:30},
             animations: {
                 closed: {
                     frames: [0],
 
     var clearWorld = function() {
         world = newWorld();
-        createWall(0,-6.7,18,0);
-        createWall(0,6.7,18,0);
-        createWall(9,0,0,13.4);
-        createWall(-9,0,0,-13.4);
+        createWall(0,-6.7*2,18*2,0);
+        createWall(0,6.7*2,18*2,0);
+        createWall(9*2,0,0,13.4*2);
+        createWall(-9*2,0,0,-13.4*2);
     }
 
     var fixtureToUserData = function(f) {