0.1.3 • Published 2 years ago

matter-map-creator v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

npm install matter-maps-creator

yarn add matter-maps-creator

ClassesUtility
MapThis is one of the main classes of the project, it serves to rederize the map, create and add objects to the world.
AnimationsAdds animations to bodies.
ParticlesCreate particles in the world. WARN: IT'S STILL IN TESTS.
MethodsUtility
addCustomAdd a custom body. parameters: bodies, callback?
addRectangleAdd a rectangle body. parameters: x, y, w, h, color, callback?
addCircleAdd a circle body. parameters: x, y, r, color, callback?
addPolygonAdd a polygon body. parameters: x, y, s, r, color, callback?
addTrapezoidAdd a trapezoid body. parameters: x, y, w, h, sl, color, callback?
platformAdd a platform to map. parameters: x, y, size, color, callback?
wreckingballAdd a wreckingball to map. parameters: x, y, size, color, length, chainWidth, chainColor, callback?.
ragdollAdd a ragdoll to map. parameters: x, y, scale, color, callback?.
carAdd a car to map. parameters: x, y, size, color, wheelAColor, wheelBColor, callback?.
chainAdd a chain to map. parameters: x, y, size, length, color, callback?.
bridgeAdd a bridge to map. parameters: x, y, size, length, color, callback?.
buildThis method being the last to be invoked, to render the map. parameters: callback?.
// setup.js
import { Composite, Engine, Mouse, MouseConstraint, Render, Runner } from 'matter-js';

function setup() {
  const engine: Engine = Engine.create();
  const render: Render = Render.create({
    element: document.body,
    engine: engine,
    options: {
      width: window.innerWidth,
      height: window.innerHeight
    }
  });
  Render.run(render);

  const runner: Runner = Runner.create();
  Runner.run(runner, engine);
  
  return {
    engine: engine,
    render: render,
    runner: runner
  };
}
export default setup;
// mapUseExample.js
import { Map } from 'matter-maps-creator';
import setup from 'setup.js';

const { engine } = setup();

const worldXSize = 30000;
const worldYSize = 15000;
const walls = true;
const map = new Map(engine, worldXSize, worldYSize, walls);

map.addRectangle(3000, 3000, 200, 200, '#005');
map.ragdoll(4000, 4000, 5, '#005');
const platform = map.platform(6000, 5000, 1200, '#606090');

console.log(`Platform: ${platform.id} has rendered.`);

map.build(() => console.log('The map was built and rendered.'));
MethodsUtility
rotateRotates a body constantly. parameters: body, rotation
moveLeftConstantly moves one body to the left. parameters: body, distance, speed
moveRightConstantly moves one body to the right. parameters: body, distance, speed
moveUpConstantly moves one body to the up. parameters: body, distance, speed
moveDownConstantly moves one body to the down. parameters: body, distance, speed
trailCreate a trail through which the body passes. parameters: body, disappearAfter, appearWhenSpeed, color
cameraFocusThe camera will then follow the body or bodies. parameters: bodies, zoom, center
// setup.js
import { Composite, Engine, Mouse, MouseConstraint, Render, Runner } from 'matter-js';

function setup() {
  const engine: Engine = Engine.create();
  const render: Render = Render.create({
    element: document.body,
    engine: engine,
    options: {
      width: window.innerWidth,
      height: window.innerHeight
    }
  });
  Render.run(render);

  const runner: Runner = Runner.create();
  Runner.run(runner, engine);
  
  return {
    engine: engine,
    render: render,
    runner: runner
  };
}
export default setup;
// mapUseExample.js
import { Map, Animations } from 'matter-maps-creator';
import setup from 'setup.js';

const { engine, render } = setup();

const worldXSize = 30000;
const worldYSize = 15000;
const walls = true;
const map = new Map(engine, worldXSize, worldYSize, walls);
const animations = new Animations(engine, render);

const player = map.addRectangle(2500, 500, 200, 200, '#005');
animations.cameraFocus(player, 20, true);

const platform = map.platform(2500, 3000, 1200, '#606090');
animations.moveRight(platform, 700, 0.014);
animations.moveDown(platform, 900, 0.018);

map.build(() => console.log('The map was built and rendered.'));
MethodsUtility
directionalIt generates directional particles. parameters: options
explosionIt generates explosion of particles. parameters: options
trailCreate a trail through which the body passes. parameters: options
stopStop the execution of the particle creation. parameters: executeDelay
// setup.js
import { Composite, Engine, Mouse, MouseConstraint, Render, Runner } from 'matter-js';

function setup() {
  const engine: Engine = Engine.create();
  const render: Render = Render.create({
    element: document.body,
    engine: engine,
    options: {
      width: window.innerWidth,
      height: window.innerHeight
    }
  });
  Render.run(render);

  const runner: Runner = Runner.create();
  Runner.run(runner, engine);
  
  return {
    engine: engine,
    render: render,
    runner: runner
  };
}
export default setup;
// mapUseExample.js
import { Map, Animations, Particles } from 'matter-maps-creator';
import setup from 'setup.js';

const { engine, render } = setup();

const worldXSize = 30000;
const worldYSize = 15000;
const walls = true;
const map = new Map(engine, worldXSize, worldYSize, walls);
const animations = new Animations(engine, render);

const playerParticle = new Particles(engine, 50, 300);

const player = map.addRectangle(2500, 500, 200, 200, '#005');
animations.cameraFocus(player, 20, true);
  
setInterval(() => {
  playerParticle.explosion({
    x: player.position.x,
    y: player.position.y,
    size: 15,
    initialForce: 0.1,
    color: '#005',
    collision: false
  });
}, 500);
  
const platformParticle = new Particles(engine, 50, 800);
  
const platform = map.platform(2500, 3000, 1700, '#606090');
  
platformParticle.directional({
  x: platform.position.x,
  y: platform.position.y,
  maxX: 1200,
  maxY: 500,
  force: { x: 0, y: -0.1 },
  size: 15,
  color: '#005',
  collision: false
});

map.build(() => console.log('The map was built and rendered.'));
0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago