aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRubén Beltrán del Río <ben@nsovocal.com>2018-04-23 20:34:45 -0500
committerGitHub <noreply@github.com>2018-04-23 20:34:45 -0500
commit764ac76aa90b75cd5d79c217220654a6975069af (patch)
tree91b41637435724522020bd665a1e2ea04ecaa1c2 /lib
parent6768cd461ec1a8ea87c0f64e1b3c29e36b0b02ed (diff)
Fix positioning and lessen friction (#8)
Diffstat (limited to 'lib')
-rw-r--r--lib/factories/sumo.js50
-rw-r--r--lib/sumo.js18
2 files changed, 66 insertions, 2 deletions
diff --git a/lib/factories/sumo.js b/lib/factories/sumo.js
index dad9987..e8417f9 100644
--- a/lib/factories/sumo.js
+++ b/lib/factories/sumo.js
@@ -80,8 +80,8 @@ export default {
// PHYSICS
const frictionAir = 0.02;
- const friction = 1;
- const frictionStatic = 1;
+ const friction = 0.01;
+ const frictionStatic = 0.01;
const restitution = 1;
const density = 1.5;
@@ -335,5 +335,51 @@ export default {
}
return entity;
+ },
+
+ /**
+ * Creates an invisible block
+ *
+ * @function createInvisibleBlock
+ * @memberof SumoFactory
+ * @param {external:Serpentity} [engine] the serpentity engine to attach
+ * to. If not sent, it will not be attached.
+ * @param {object} [config] the config to override the entity, accepts
+ * the key `position` as an object with an x and y property.
+ * @return {external:Serpentity.Entity} the created entity
+ */
+ createInvisibleBlock(engine, config = {}) {
+
+ const entity = new Entity();
+
+ // POSITION
+
+ entity.addComponent(new PositionComponent(config.position));
+ const position = entity.getComponent(PositionComponent);
+
+ // PHYSICS
+
+ const friction = 0;
+ const frictionStatic = 0;
+ const restitution = 1;
+
+ const body = Bodies.rectangle(position.x / Config.meterSize,
+ position.y / Config.meterSize,
+ config.width / Config.meterSize,
+ config.height / Config.meterSize,
+ {
+ isStatic: true,
+ label: 'Invisible Block',
+ friction,
+ restitution,
+ frictionStatic
+ });
+ entity.addComponent(new BodyComponent({ body }));
+
+ if (engine) {
+ engine.addEntity(entity);
+ }
+
+ return entity;
}
};
diff --git a/lib/sumo.js b/lib/sumo.js
index eef80d7..4785087 100644
--- a/lib/sumo.js
+++ b/lib/sumo.js
@@ -260,6 +260,24 @@ internals.Sumo = class Sumo {
entityB: harness
});
+ SumoFactory.createInvisibleBlock(this._engine, {
+ width: this.horizontalResolution * 2,
+ height: this.verticalResolution * 0.1,
+ position: {
+ x: this.horizontalResolution / 2,
+ y: -this.verticalResolution * 0.1
+ }
+ });
+
+ SumoFactory.createInvisibleBlock(this._engine, {
+ width: this.horizontalResolution * 2,
+ height: this.verticalResolution * 0.1,
+ position: {
+ x: this.horizontalResolution / 2,
+ y: this.verticalResolution + this.verticalResolution * 0.1
+ }
+ });
+
// To keep the coupling behind, we'll manually add the sumos later
this._engine.addEntity(sumoA);