console.log("loading player system"); const playerSystem = (engine) => { const entity = document.getElementById("player"); const movementRate = 0.5; engine("registerEntity", entity); const playerTransform = engine ("getComponentConstructor", "transform")(entity); const playerCollision = engine ("getComponentConstructor", "collision")(entity, { layers: new Set(["player"]), mask: new Set(["environment"]), collisionShape: { } }); // const interactionCollision = // engine ("getComponentConstructor", "collision") (entity, { // layers: ["player"], // mask: ["interactable"], // collisionShape: { // } // }); const move = (direction) => (delta, eventData) => { let translation = [0,0]; switch (direction) { case "left": translation [0] = -( movementRate * delta ); break; case "right": translation[0] = movementRate * delta; break; case "up": translation[1] = - ( movementRate * delta ); break; case "down": translation[1] = movementRate * delta; break; } playerTransform("translate", translation); playerCollision("checkCollision"); // interactionCollision("checkCollision"); }; engine("registerEntity", entity); engine("addComponent", entity, "transform", playerTransform); engine("addComponent", entity, "collision", playerCollision); // engine("addComponent", entity, "collision", interactionCollision); // engine("") engine("subscribeToEvent", "moveLeft", "movePlayerLeft", move("left")); engine("subscribeToEvent", "moveRight", "movePlayerRight", move("right")); engine("subscribeToEvent", "moveUp", "movePlayerUp", move("up")); engine("subscribeToEvent", "moveDown", "movePlayerDown", move("down")); };