Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Generated by CoffeeScript 1.6.3
- (function() {
- var createBody, createSprite;
- goog.provide('boxtest');
- goog.require('lime.Director');
- goog.require('lime.Scene');
- goog.require('box2d.World');
- boxtest.WIDTH = 1024;
- boxtest.HEIGHT = 768;
- createBody = function(world, x, y, width, height, isStatic) {
- var bodyDef, shapeDef;
- bodyDef = new box2d.BodyDef;
- bodyDef.position.Set(x, y);
- shapeDef = new box2d.BoxDef;
- shapeDef.width = width;
- shapeDef.height = height;
- shapeDef.density = isStatic ? 0 : 1;
- shapeDef.restitution = .9;
- shapeDef.friction = 1;
- bodyDef.AddShape(shapeDef);
- return world.CreateBody(bodyDef);
- };
- createSprite = function(scene, width, height, fill) {
- var sprite;
- sprite = new lime.Sprite().setSize(width, height);
- sprite.setFill(fill);
- scene.appendChild(sprite);
- return sprite;
- };
- boxtest.start = function() {
- var bounds, director, dynamicBody, dynamicBodySprite, gravity, scene, staticBody, staticBodySprite, step, updateSpritePosition, world;
- director = new lime.Director(document.body, boxtest.WIDTH, boxtest.HEIGHT);
- scene = new lime.Scene();
- gravity = new box2d.Vec2(0, 100);
- bounds = new box2d.AABB();
- bounds.minVertex.Set(-boxtest.WIDTH, -boxtest.HEIGHT);
- bounds.maxVertex.Set(2 * boxtest.WIDTH, 2 * boxtest.HEIGHT);
- world = new box2d.World(bounds, gravity, false);
- staticBody = createBody(world, 200, 300, 200, 200, true);
- staticBodySprite = createSprite(scene, 200, 200, "#000000");
- dynamicBody = createBody(world, 220, 0, 50, 50, false);
- dynamicBodySprite = createSprite(scene, 50, 50, "#FF0000");
- director.makeMobileWebAppCapable();
- director.replaceScene(scene);
- updateSpritePosition = function(body, sprite) {
- var pos, rot;
- pos = body.GetCenterPosition().clone();
- rot = body.GetRotation();
- sprite.setRotation(-rot / Math.PI * 180);
- return sprite.setPosition(pos);
- };
- step = function(msecPassed) {
- world.Step(msecPassed / 1000, 3);
- updateSpritePosition(staticBody, staticBodySprite);
- return updateSpritePosition(dynamicBody, dynamicBodySprite);
- };
- return lime.scheduleManager.schedule(step);
- };
- goog.exportSymbol('boxtest.start', boxtest.start);
- }).call(this);
- /*
- //@ sourceMappingURL=boxtest.map
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement