Const names

This commit is contained in:
StevenJoeZhang 2019-02-03 14:49:23 +08:00
parent bb6cb3171e
commit a7d298f625
16 changed files with 71 additions and 57 deletions

View File

@ -1,4 +1,4 @@
# Blockly.IO
# Paper.IO
This is a clone of the original Paper-IO released by Voodoo, except for one aspect. This will attempt to implement a multi-player aspect of the game (like a real IO game). Currently this has a playground at this [link](https://thekidofarcrania.github.io/BlocklyIO). It's a demo version of what to come. Hopefully by that time, the necessary server infrastructure could be obtained.
@ -33,6 +33,12 @@ sudo npm install -g browserify uglify-es
browserify client.js | uglifyjs > public/bundle.js
```
## TODO
加快渲染速度
优化胜负判定
## License
This is licensed under MIT. As such, please provide due credit and link back to this repository if possible.

View File

@ -4,9 +4,6 @@ var io = require("socket.io-client");
var client = require("./src/game-client");
client.allowAnimation = true;
client.renderer = require("./src/user-mode");
var core = require("./src/core");
var GRID_SIZE = core.GRID_SIZE;
var CELL_WIDTH = core.CELL_WIDTH;
var mimiRequestAnimationFrame = window.requestAnimationFrame
|| window.webkitRequestAnimationFrame
@ -16,11 +13,7 @@ var mimiRequestAnimationFrame = window.requestAnimationFrame
|| function(callback) { window.setTimeout(callback, 1000 / 30) };
function run() {
var names = "Alice Bob Carol Dave Eve Francis Grace Hans Isabella Jason Kate Louis Margaret Nathan Olivia Paul Queen Richard Susan Thomas Uma Vivian Winnie Xander Yasmine Zach".split(" ");
var prefix = "Angry Baby Crazy Diligent Excited Fat Greedy Hungry Interesting Japanese Kind Little Magic Naïve Old Powerful Quiet Rich Superman THU Undefined Valuable Wifeless Xiangbuchulai Young Zombie".split(" ");
var name = $("#name").val() || [prefix[Math.floor(Math.random() * prefix.length)], names[Math.floor(Math.random() * names.length)]].join(" ");
$("#name").val(name);
client.connectGame("//" + window.location.hostname + ":8081", name, function(success, msg) {
client.connectGame("//" + window.location.hostname + ":8081", $("#name").val(), function(success, msg) {
if (success) {
$("#begin").fadeOut(1000);
$("#main-ui").fadeIn(1000);

5
config.json Normal file
View File

@ -0,0 +1,5 @@
{
"hostname": "0.0.0.0",
"port": 8080,
"bots": []
}

File diff suppressed because one or more lines are too long

View File

@ -16,9 +16,9 @@
<canvas id="main-ui"></canvas>
<div id="begin">
<a id="github" href="https://github.com/stevenjoezhang/paper.io" title="Visit the open-source code on GitHub!">
<svg width="80" height="80" viewBox="0 0 250 250" style="fill: #222; color: #fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true">
<svg viewBox="0 0 250 250" aria-hidden="true">
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" class="octo-arm"></path>
<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
</svg>
</a>

View File

@ -51,10 +51,18 @@ canvas {
}
#github svg {
transition: all 1s;
transform-origin: right top;
fill: #222;
color: #fff;
position: absolute;
top: 0;
right: 0;
border: 0;
width: 80px;
height: 80px;
}
#github:hover svg {
transform: scale(2);
width: 160px;
height: 160px;
}
.center {
vertical-align: middle;

View File

@ -1,5 +1,5 @@
var hostname = process.argv[2] || "0.0.0.0";
var port = parseInt(process.argv[3]) || 8080;
var hostname = process.argv[2] || "0.0.0.0";
var finalhandler = require("finalhandler");
var http = require("http");
var serveStatic = require("serve-static");

View File

@ -101,7 +101,7 @@ function foundProto(func) {
}
function connect() {
client.connectGame(process.argv[2], process.argv[3] || "[BOT]", function(success, msg) {
client.connectGame(process.argv[2], process.argv[3], function(success, msg) { //|| "[BOT]"
if (!success) setTimeout(connect, 1000);
});
}
@ -254,8 +254,8 @@ client.renderer = {
disconnect: function() {
var dt = (endFrame - startFrame);
startFrame = -1;
log("I died... (survived for " + dt + " frames.)");
log("I killed " + client.kills + " player(s).");
log(`I died... (survived for ${dt} frames.)`);
log(`I killed ${client.kills} player(s).`);
log("Coefficients: " + coeffs);
var mutation = Math.min(10, Math.pow(2, calcFavorability(params)));

View File

@ -8,7 +8,7 @@ var client = require("../game-client");
var GRID_SIZE = core.GRID_SIZE;
var CELL_WIDTH = core.CELL_WIDTH;
var MOVES = [[-1, 0], [0, 1], [1, 0], [0, -1]]
var MOVES = [[-1, 0], [0, 1], [1, 0], [0, -1]];
var startFrame = -1;
var endFrame = -1;
@ -25,7 +25,7 @@ function mod(x) {
}
function connect() {
client.connectGame(process.argv[2], process.argv[3] || "[PAPER-IO-BOT]", function(success, msg) {
client.connectGame(process.argv[2], process.argv[3], function(success, msg) { //|| "[PAPER-IO-BOT]"
if (!success) setTimeout(connect, 1000);
});
}
@ -188,8 +188,8 @@ client.renderer = {
var dt = (endFrame - startFrame);
startFrame = -1;
log("I died... (survived for " + dt + " frames.)");
log("I killed " + client.kills + " player(s).");
log(`I died... (survived for ${dt} frames.)`);
log(`I killed ${client.kills} player(s).`);
connect();
},
removePlayer: function(player) {

18
src/core/consts.js Normal file
View File

@ -0,0 +1,18 @@
function constant(val) {
return {
value: val,
enumerable: true
};
}
var consts = {
GRID_SIZE: constant(80),
CELL_WIDTH: constant(40),
SPEED: constant(5),
BORDER_WIDTH: constant(20),
MAX_PLAYERS: constant(81),
PREFIXES: constant("Angry Baby Crazy Diligent Excited Fat Greedy Hungry Interesting Japanese Kind Little Magic Naïve Old Powerful Quiet Rich Superman THU Undefined Valuable Wifeless Xiangbuchulai Young Zombie".split(" ")),
NAMES: constant("Alice Bob Carol Dave Eve Francis Grace Hans Isabella Jason Kate Louis Margaret Nathan Olivia Paul Queen Richard Susan Thomas Uma Vivian Winnie Xander Yasmine Zach".split(" "))
};
Object.defineProperties(module.exports, consts);

View File

@ -1,5 +1,5 @@
var ANIMATE_FRAMES = 24;
var CELL_WIDTH = 40;
var consts = require("./consts");
var CELL_WIDTH = consts.CELL_WIDTH;
//TODO: remove constants
exports.initPlayer = function(grid, player) {

View File

@ -1,16 +0,0 @@
function constant(val) {
return {
value: val,
enumerable: true
};
}
var consts = {
GRID_SIZE: constant(80),
CELL_WIDTH: constant(40),
SPEED: constant(5),
BORDER_WIDTH: constant(20),
MAX_PLAYERS: constant(81)
};
Object.defineProperties(module.exports, consts);

View File

@ -1,5 +1,5 @@
var core = require("./core");
var consts = require("./game-consts");
var consts = require("./consts");
exports.Color = require("./color");
exports.Grid = require("./grid");

View File

@ -1,7 +1,7 @@
var Stack = require("./stack");
var Color = require("./color");
var Grid = require("./grid.js");
var consts = require("./game-consts.js");
var Grid = require("./grid");
var consts = require("./consts");
var GRID_SIZE = consts.GRID_SIZE;
var CELL_WIDTH = consts.CELL_WIDTH;

View File

@ -1,8 +1,6 @@
var io = require("socket.io-client");
var core = require("./core");
var Player = core.Player;
var GRID_SIZE = core.GRID_SIZE;
var CELL_WIDTH = core.CELL_WIDTH;
var running = false;
var user, socket, frame;
var players, allPlayers;
@ -18,7 +16,6 @@ var grid = new core.Grid(core.GRID_SIZE, function(row, col, before, after) {
});
var mimiRequestAnimationFrame;
try {
if (window && window.document) {
mimiRequestAnimationFrame = window.requestAnimationFrame
@ -39,6 +36,9 @@ function connectGame(url, name, callback) {
running = true;
user = null;
deadFrames = 0;
var prefixes = core.PREFIXES;
var names = core.NAMES;
name = name || [prefixes[Math.floor(Math.random() * prefixes.length)], names[Math.floor(Math.random() * names.length)]].join(" ");
//Socket connection
io.j = [];
io.sockets = [];

View File

@ -2,10 +2,10 @@ var core = require("./core");
var GRID_SIZE = core.GRID_SIZE;
var CELL_WIDTH = core.CELL_WIDTH;
var MAX_PLAYERS = core.MAX_PLAYERS;
var HUES = [0, 10, 20, 25, 30, 35, 40, 45, 50, 60, 70, 100, 110, 120, 125, 130, 135, 140, 145, 150, 160, 170, 180, 190, 200, 210, 220].map(function(val) {
var SATS = [192, 150, 100].map(function(val) {
return val / 240;
});
var SATS = [192, 150, 100].map(function(val) {
var HUES = [0, 10, 20, 25, 30, 35, 40, 45, 50, 60, 70, 100, 110, 120, 125, 130, 135, 140, 145, 150, 160, 170, 180, 190, 200, 210, 220].map(function(val) {
return val / 240;
});
@ -182,8 +182,8 @@ function Game(id) {
data.newPlayers = snews;
newPlayers = [];
}
for (var pl of players) {
pl.client.emit("notifyFrame", data);
for (var p of players) {
p.client.emit("notifyFrame", data);
}
frame++;
pushPlayerLocations();
@ -193,14 +193,14 @@ function Game(id) {
function update() {
var dead = [];
core.updateFrame(grid, players, dead);
for (var pl of dead) {
if (!pl.handledDead) {
possColors.push(pl.baseColor);
pl.handledDead = true;
for (var p of dead) {
if (!p.handledDead) {
possColors.push(p.baseColor);
p.handledDead = true;
}
if (pl.name.indexOf("BOT") == -1) log((pl.name || "Unnamed") + " (" + pl.num + ") died.");
pl.client.emit("dead");
pl.client.disconnect(true);
if (p.name.indexOf("BOT") == -1) log((p.name || "Unnamed") + " (" + p.num + ") died.");
p.client.emit("dead");
p.client.disconnect(true);
}
}
}