module.exports = { create: channel => { map = require("../public/maps/" + channel + "/index").map; map.players = {}; return map; }, collision: (a,b) => { return a && b ? parseInt(a.position.x) + parseInt(a.width) > parseInt(b.position.x) && parseInt(a.position.x) < parseInt(b.position.x) + parseInt(b.width) && parseInt(a.position.y) + parseInt(a.height) > parseInt(b.position.y) && parseInt(a.position.y) < parseInt(b.position.y) + parseInt(b.height) : false; }, collisionX: (m, a,b) => { return parseInt(a.position.x + m) + parseInt(a.width) > parseInt(b.position.x) && parseInt(a.position.x + m) < parseInt(b.position.x) + parseInt(b.width) && parseInt(a.position.y) + parseInt(a.height) > parseInt(b.position.y) && parseInt(a.position.y) < parseInt(b.position.y) + parseInt(b.height); }, collisionY: (m, a,b) => { return parseInt(a.position.y + m) + parseInt(a.height) > parseInt(b.position.y) && parseInt(a.position.y + m) < parseInt(b.position.y) + parseInt(b.height) && parseInt(a.position.x) + parseInt(a.width) > parseInt(b.position.x) && parseInt(a.position.x) < parseInt(b.position.x) + parseInt(b.width); }, insideX: (m, item, limits) => { return (item.position.x + m) > limits.x.max && (item.position.x + m) < limits.x.min; }, insideY: (m, item, limits) => { return (item.position.y + m) > limits.y.max && (item.position.y + m) < limits.y.min; }, moveX: (m, player, channel) => { let maper = module.exports; return maper.insideX(m, player, channel.limits) && !Object.values(channel.players).reduce((acc, x) => acc ? acc : player != x ? maper.collisionX(m, player, x) : false, false) && !Object.values(channel.colliders).reduce((acc, x) => acc ? acc : player != x ? maper.collisionX(m, player, x) : false, false); }, moveY: (m, player, channel) => { let maper = module.exports; return maper.insideY(m, player, channel.limits) && !Object.values(channel.players).reduce((acc, x) => acc ? acc : player != x ? maper.collisionY(m, player, x) : false, false) && !Object.values(channel.colliders).reduce((acc, x) => acc ? acc : player != x ? maper.collisionY(m, player, x) : false, false); }, getRandom: (min, max) => { return Math.floor(Math.random() * (max - min) ) + min; }, getRandomPosition:(limits) =>{ let maper = module.exports; return { "x": maper.getRandom(limits.x.min, limits.x.max), "y": maper.getRandom(limits.y.min, limits.y.max) } } }