Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Generated by CoffeeScript 1.6.3
  2. (function() {
  3.   var createBody, createSprite;
  4.  
  5.   goog.provide('boxtest');
  6.  
  7.   goog.require('lime.Director');
  8.  
  9.   goog.require('lime.Scene');
  10.  
  11.   goog.require('box2d.World');
  12.  
  13.   boxtest.WIDTH = 1024;
  14.  
  15.   boxtest.HEIGHT = 768;
  16.  
  17.   createBody = function(world, x, y, width, height, isStatic) {
  18.     var bodyDef, shapeDef;
  19.     bodyDef = new box2d.BodyDef;
  20.     bodyDef.position.Set(x, y);
  21.     shapeDef = new box2d.BoxDef;
  22.     shapeDef.width = width;
  23.     shapeDef.height = height;
  24.     shapeDef.density = isStatic ? 0 : 1;
  25.     shapeDef.restitution = .9;
  26.     shapeDef.friction = 1;
  27.     bodyDef.AddShape(shapeDef);
  28.     return world.CreateBody(bodyDef);
  29.   };
  30.  
  31.   createSprite = function(scene, width, height, fill) {
  32.     var sprite;
  33.     sprite = new lime.Sprite().setSize(width, height);
  34.     sprite.setFill(fill);
  35.     scene.appendChild(sprite);
  36.     return sprite;
  37.   };
  38.  
  39.   boxtest.start = function() {
  40.     var bounds, director, dynamicBody, dynamicBodySprite, gravity, scene, staticBody, staticBodySprite, step, updateSpritePosition, world;
  41.     director = new lime.Director(document.body, boxtest.WIDTH, boxtest.HEIGHT);
  42.     scene = new lime.Scene();
  43.     gravity = new box2d.Vec2(0, 100);
  44.     bounds = new box2d.AABB();
  45.     bounds.minVertex.Set(-boxtest.WIDTH, -boxtest.HEIGHT);
  46.     bounds.maxVertex.Set(2 * boxtest.WIDTH, 2 * boxtest.HEIGHT);
  47.     world = new box2d.World(bounds, gravity, false);
  48.     staticBody = createBody(world, 200, 300, 200, 200, true);
  49.     staticBodySprite = createSprite(scene, 200, 200, "#000000");
  50.     dynamicBody = createBody(world, 220, 0, 50, 50, false);
  51.     dynamicBodySprite = createSprite(scene, 50, 50, "#FF0000");
  52.     director.makeMobileWebAppCapable();
  53.     director.replaceScene(scene);
  54.     updateSpritePosition = function(body, sprite) {
  55.       var pos, rot;
  56.       pos = body.GetCenterPosition().clone();
  57.       rot = body.GetRotation();
  58.       sprite.setRotation(-rot / Math.PI * 180);
  59.       return sprite.setPosition(pos);
  60.     };
  61.     step = function(msecPassed) {
  62.       world.Step(msecPassed / 1000, 3);
  63.       updateSpritePosition(staticBody, staticBodySprite);
  64.       return updateSpritePosition(dynamicBody, dynamicBodySprite);
  65.     };
  66.     return lime.scheduleManager.schedule(step);
  67.   };
  68.  
  69.   goog.exportSymbol('boxtest.start', boxtest.start);
  70.  
  71. }).call(this);
  72.  
  73. /*
  74. //@ sourceMappingURL=boxtest.map
  75. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement