X-Git-Url: https://git.r.bdr.sh/rbdr/sumo/blobdiff_plain/7ade6f8d96825386bf2e89dea51f9297cbac8e9c..6768cd461ec1a8ea87c0f64e1b3c29e36b0b02ed:/lib/factories/sumo.js diff --git a/lib/factories/sumo.js b/lib/factories/sumo.js index ea5a71c..dad9987 100644 --- a/lib/factories/sumo.js +++ b/lib/factories/sumo.js @@ -82,8 +82,8 @@ export default { const frictionAir = 0.02; const friction = 1; const frictionStatic = 1; - const restitution = 0.9; - const density = 1; + const restitution = 1; + const density = 1.5; const body = Bodies.circle(position.x / Config.meterSize, position.y / Config.meterSize, radius / Config.meterSize, { label: 'Sumo body', @@ -296,6 +296,44 @@ export default { engine.addEntity(entity); } + return entity; + }, + + /** + * Creates a static arena entity + * + * @function createArena + * @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 + */ + createArena(engine, config = {}) { + + const entity = new Entity(); + + // POSITION + + entity.addComponent(new PositionComponent(config.position)); + const position = entity.getComponent(PositionComponent); + + // RENDERING + + const radius = 300; + + const container = config.container || { + container: PixiFactory.createArena({ radius }) + }; + container.container.position.x = position.x; + container.container.position.y = position.y; + entity.addComponent(new PixiContainerComponent(container)); + + if (engine) { + engine.addEntity(entity); + } + return entity; } };