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
// 木偶人对战画面, 效率太低, 废弃;
let Matter = require('matter-js');
var Engine = Matter.Engine,
Render = Matter.Render,
Runner = Matter.Runner,
Body = Matter.Body,
Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies,
Composites = Matter.Composites,
Composite = Matter.Composite,
Events = Matter.Events;
Composites.Person = function(x, y, ){
let group = Body.nextGroup(true),
Person = Composite.create({ label: 'Person'}),
radius = 2;
const Physics = (state, { touches, time }) => {
let engineId = Object.keys(state).find(key => state[key].engine);
let engine = state[engineId].engine;
console.log(time)
Matter.Engine.update(engine, time.delta);
return state;
};
setupWorld = () => {
let engine = Matter.Engine.create({ enableSleeping: false });
let world = engine.world;
world.gravity.y = 0.0;
let bird = Matter.Bodies.rectangle( Constants.MAX_WIDTH / 2, Constants.MAX_HEIGHT / 2, Constants.BIRD_WIDTH, Constants.BIRD_HEIGHT);
let floor1 = Matter.Bodies.rectangle(
Constants.MAX_WIDTH / 2,
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,
const Physics = (state, { touches, time }) => {
let engine = state["physics"].engine;
Matter.Engine.update(engine, time.delta);
return state;
};
this.tickStart = function () {
var event = {
timestamp: engine.timing.timestamp
};
Matter.Events.on(engine, "beforeRender", event);
Matter.Events.on(engine, "beforeTick", event);
Matter.Events.on(engine, "tick", event);
Matter.Engine.update(engine, 1000/60);
Matter.Events.on(engine, "afterTick", event);
Matter.Events.on(engine, "afterRender", event);
};
"use strict";
/**
* 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) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _matterJs = require('matter-js');
var engine = _matterJs.Engine.create();
exports.default = engine;
//# sourceMappingURL=engine.js.map
ServerWorld.prototype.physicsTick = function(){
this.physicsTickCounter++;
var self = this;
_.forEach(this.worldState._state.players, function(player){
player.server_applyStateForPhysicsTick(self.physicsTickCounter);
});
this.worldState.recordPlayerStatesForThisTick(self.physicsTickCounter);
Matter.Engine.update(this.physicsEngine, global.config.physicsClock_ms);
}
world.gravity.y = 1.2;
addPipesAtLocation((Constants.MAX_WIDTH * 2) - (Constants.PIPE_WIDTH / 2), world, entities);
addPipesAtLocation((Constants.MAX_WIDTH * 3) - (Constants.PIPE_WIDTH / 2), world, entities);
}
hadTouches = true;
Matter.Body.setVelocity( bird, {
x: bird.velocity.x,
y: -10
});
}
});
Matter.Engine.update(engine, time.delta);
Object.keys(entities).forEach(key => {
if (key.indexOf("pipe") === 0 && entities.hasOwnProperty(key)){
Matter.Body.translate(entities[key].body, {x: -2, y: 0});
if (key.indexOf("Top") !== -1 && parseInt(key.replace("pipe", "")) % 2 === 0){
if (entities[key].body.position.x <= bird.position.x && !entities[key].scored){
entities[key].scored = true;
dispatch({ type: "score" });
}
if (entities[key].body.position.x <= -1 * (Constants.PIPE_WIDTH / 2)){
let pipeIndex = parseInt(key.replace("pipe", ""));
delete(entities["pipe" + (pipeIndex - 1) + "Top"]);
delete(entities["pipe" + (pipeIndex - 1)]);
delete(entities["pipe" + pipeIndex + "Top"]);