Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as Matter from 'matter-js'
// Matter.js module aliases
const consts = {
Engine: Matter.Engine,
World: Matter.World,
Body: Matter.Body,
Bodies: Matter.Bodies,
Events: Matter.Events,
Vector: Matter.Vector,
Composite: Matter.Composite
}
export default consts
Constants.MAX_HEIGHT - 25,
Constants.MAX_WIDTH + 4,
50,
{ isStatic: true }
);
let floor2 = Matter.Bodies.rectangle(
Constants.MAX_WIDTH + (Constants.MAX_WIDTH / 2),
Constants.MAX_HEIGHT - 25,
Constants.MAX_WIDTH + 4,
50,
{ isStatic: true }
);
Matter.World.add(world, [bird, floor1, floor2]);
Matter.Events.on(engine, 'collisionStart', (event) => {
var pairs = event.pairs;
this.gameEngine.dispatch({ type: "game-over"});
});
return {
physics: { engine: engine, world: world },
floor1: { body: floor1, renderer: Floor },
floor2: { body: floor2, renderer: Floor },
bird: { body: bird, pose: 1, renderer: Bird},
}
}
constructor(props) {
super(props);
this.loopID = null;
this.lastTime = null;
const world = Matter.World.create({ gravity: props.gravity });
this.engine = Engine.create({
world,
});
this.loop = this.loop.bind(this);
}
x,
Constants.MAX_HEIGHT - 50 - pipe2Height - (pipeTopHeight / 2),
pipeTopWidth,
pipeTopHeight,
{ isStatic: true}
);
let pipe2 = Matter.Bodies.rectangle(
x,
Constants.MAX_HEIGHT - 50 - (pipe2Height / 2),
Constants.PIPE_WIDTH,
pipe2Height,
{ isStatic: true}
);
Matter.World.add(world, [pipe1, pipe1Top, pipe2, pipe2Top]);
entities["pipe" + (pipes + 1)] = {
body: pipe1, renderer: Pipe, scored: false
}
entities["pipe" + (pipes + 2)] = {
body: pipe2, renderer: Pipe, scored: false
}
entities["pipe" + (pipes + 1) + "Top"] = {
body: pipe1Top, renderer: PipeTop, scored: false
}
entities["pipe" + (pipes + 2) + "Top"] = {
body: pipe2Top, renderer: PipeTop, scored: false
}
const engine = Matter.Engine.create({ enableSleeping: false });
const world = engine.world;
const body = Matter.Bodies.rectangle(width / 2, -1000, boxSize, boxSize, { frictionAir: 0.021 });
const floor = Matter.Bodies.rectangle(width / 2, height - boxSize / 2, width, boxSize, { isStatic: true });
const constraint = Matter.Constraint.create({
label: "Drag Constraint",
pointA: { x: 0, y: 0 },
pointB: { x: 0, y: 0 },
length: 0.01,
stiffness: 0.1,
angularStiffness: 1
});
Matter.World.add(world, [body, floor]);
Matter.World.addConstraint(world, constraint);
return (
);
}
touches.filter(t => t.type === "press").forEach(t => {
const body = Matter.Bodies.rectangle(t.event.pageX, t.event.pageY, 50, 50, { frictionAir: 0.021 });
Matter.World.add(world, [body]);
state[++boxIds] = {
body: body,
size: [50, 50],
renderable: Box
};
});
body: function (entity) {
Matter.World.remove(engine.world, bodies[entity.uid]);
delete bodies[entity.uid];
}
};
body.force = entity.c.body.force;
proxy(entity.c.body, 'force', body, 'force');
proxy(entity.c.body, 'density', body, 'density');
body.position.x = entity.c.body.x;
proxy(entity.c.body, 'x', body.position, 'x');
body.position.y = entity.c.body.y;
proxy(entity.c.body, 'y', body.position, 'y');
//proxy(entity.c, 'velocity', body, 'velocity');
Matter.World.add(engine.world, body);
bodies[entity.uid] = body;
}
};
/**
* A tool for modifying the properties of an engine and renderer.
* @module Gui
*/
var Gui = module.exports = {};
const dat = require('../../node_modules/dat.gui/build/dat.gui.min');
const ToolsCommon = require('./Common');
const Serializer = require('matter-tools').Serializer;
const Matter = require('matter-js');
const Engine = Matter.Engine;
const Detector = Matter.Detector;
const Grid = Matter.Grid;
const World = Matter.World;
const Bodies = Matter.Bodies;
const Events = Matter.Events;
const Composite = Matter.Composite;
/**
* Creates a Gui
* @function Gui.create
* @param {engine} [engine]
* @param {runner} [runner]
* @param {render} [render]
* @return {gui} The created gui instance
*/
Gui.create = function(engine, runner, render) {
dat.GUI.TEXT_CLOSED = '▲';
dat.GUI.TEXT_OPEN = '▼';
constructor(props) {
super(props);
this.loopID = null;
this.lastTime = null;
const world = Matter.World.create({ gravity: props.gravity });
this.engine = Engine.create({
world,
});
this.loop = this.loop.bind(this);
}