Files
2020-05-28 10:46:51 +00:00

123 líneas
2.9 KiB
JavaScript

function percent(m, p){
return (m * 100) / p;
}
function getDirection(mouse, wx, wy){
if(mouse.y < window.innerHeight/2){
if(mouse.x < window.innerWidth/2){
if(percent(mouse.x, wx) >= percent(mouse.y, wy)){
direction = "up";
}else{
direction = "left";
}
}else{
if(percent((mouse.x - wx)*-1, wx) >= percent(mouse.y, wy)){
direction = "up";
}else{
direction = "right";
}
}
}else{
if(mouse.x < wx/2){
if(percent(mouse.x, wx) >= percent((mouse.y - wy) * -1, wy)){
direction = "down";
}else{
direction = "left";
}
}else{
if(percent((mouse.x - wx)*-1, wx) >= percent((mouse.y - wy) * -1, wy)){
direction = "down";
}else{
direction = "right";
}
}
}
return direction;
}
function getLive(life){
var r = ""
for (var i = 0; i < map.player.lives; i++){
r += "💗 ";
}
return r;
}
function getParam(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4(); + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
function comparePlayer(a, b) {
if (a.py > b.py) {
return -1;
}
if (a.py < b.py) {
return 1;
}
return 0;
}
function comparePlayerScore(a, b) {
if (parseInt(a.score) > parseInt(b.score)) {
return -1;
}
if (parseInt(a.score) < parseInt(b.score)) {
return 1;
}
return 0;
}
function is_touch_device() {
try {
document.createEvent("TouchEvent");
return true;
} catch (e) {
return false;
}
}
function refreshScore(){
setInterval(function(){
$("#scoreOutput").html("");
var i = 1;
var showPlayer = false;
if(map.players){
Object.values(map.players).sort(comparePlayerScore).map(function(element){
if (score > element.score && !showPlayer){
$("#scoreOutput").html($("#scoreOutput").html() + i + "º - " + userName + " - " + score + "<br>");
i++;
showPlayer = true;
}
if(!element.deleted){
$("#scoreOutput").html($("#scoreOutput").html() + i + "º - " + element.username + " - " + element.score + "<br>");
i++;
}
});
}
if(!showPlayer){
$("#scoreOutput").html($("#scoreOutput").html() + i + "º - " + userName + " - " + score + "<br>");
}
}, 1000)
}
function getUserRamdom(){
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return "Guest-" + s4();
}