client build update
This commit is contained in:
parent
8e007763bf
commit
e194968af5
15 changed files with 2050 additions and 8 deletions
90
client/dest/core.js
Normal file
90
client/dest/core.js
Normal file
|
@ -0,0 +1,90 @@
|
|||
var ticksAlive = 0;
|
||||
var debugMode = false;
|
||||
var camera = {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
size: 1.5
|
||||
};
|
||||
var chatOpened = false;
|
||||
var chatMessages = [];
|
||||
var chatTyping = "";
|
||||
var player = new MainPlayer();
|
||||
player.register();
|
||||
var blocks = [];
|
||||
const allowed_key_to_send = [
|
||||
"KeyR", "KeyW", "KeyE", "KeyQ", "KeyS",
|
||||
"Numpad1", "Numpad2", "Numpad3", "Numpad4", "Numpad5",
|
||||
"Numpad6", "Numpad7", "Numpad8", "Numpad9", "Numpad0",
|
||||
"ShiftLeft", "ControlLeft", "Enter",
|
||||
"F1", "F2", "KeyZ", "KeyX", "KeyC"
|
||||
];
|
||||
function connectServer(address, name) {
|
||||
player.closeConnection();
|
||||
player.onConnect(name);
|
||||
try {
|
||||
let conn = new Connection(address, player.onPacket, (e) => {
|
||||
player.conn = null;
|
||||
setServerError(e == null ? "Connection closed due to error" : e);
|
||||
resetWorld();
|
||||
});
|
||||
conn.send(new JoinPacket(name));
|
||||
}
|
||||
catch (exception) {
|
||||
setServerError(exception);
|
||||
}
|
||||
}
|
||||
function resetWorld() {
|
||||
player.onConnect("unnamed player");
|
||||
blocks = [];
|
||||
blocks.push(new Block(-1, -1, "#555", true, "normal"));
|
||||
blocks.push(new Block(0, -1, "#a67", true, "spawn"));
|
||||
blocks.push(new Block(1, -1, "#555", true, "normal"));
|
||||
}
|
||||
function getBlock(x, y) {
|
||||
let value = blocks.find(o => !(o instanceof Player) && o.x == x && o.y == y);
|
||||
if (typeof value === "undefined") {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
function placeBlock(block) {
|
||||
blocks.push(block);
|
||||
}
|
||||
function removeBlock(x, y) {
|
||||
blocks = blocks.filter(o => o instanceof Player || o.x != x || o.y != y);
|
||||
}
|
||||
function getPlayer(name) {
|
||||
let value = blocks.find(o => o instanceof Player && o.name == name);
|
||||
if (typeof value === "undefined") {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
function removePlayer(name) {
|
||||
blocks = blocks.filter(o => !(o instanceof Player) || o.name != name);
|
||||
}
|
||||
function render() {
|
||||
ctx.fillStyle = "#333";
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
for (const block of blocks)
|
||||
block.render();
|
||||
for (const block of blocks)
|
||||
block.renderText();
|
||||
player.render();
|
||||
player.renderText();
|
||||
}
|
||||
function tick() {
|
||||
for (const block of blocks)
|
||||
block.tick();
|
||||
player.tick();
|
||||
}
|
||||
function renderTick() {
|
||||
for (const block of blocks)
|
||||
block.renderTick();
|
||||
player.renderTick();
|
||||
}
|
||||
resetWorld();
|
Loading…
Add table
Add a link
Reference in a new issue