// Cloned by Jack Egan on 12 Nov 2024 from World "Websockets boxes (clone by Jack Egan)" by Jack Egan
// Please leave this clone trail here.
// Cloned by Jack Egan on 12 Nov 2024 from World "Websockets boxes" by Starter user
// Please leave this clone trail here.
// ==== Starter World =================================================================================================
// This code is designed for use on the Ancient Brain site.
// This code may be freely copied and edited by anyone on the Ancient Brain site.
// To include a working run of this program on another site, see the "Embed code" links provided on Ancient Brain.
// ====================================================================================================================
// Demo of Websockets functionality added to a 3D World
// Run with two or more users
// Click button to change a random box's texture on all clients running this World
// Pick a side and compete against an opponent!
// You can annoy the other player by reloading the page!
AB.clockTick = 100;
AB.maxSteps = 100000;
AB.screenshotStep = 100;
const SKYCOLOR = 0xccffcc;
const MAXPOS = 4000;
const startRadiusConst = MAXPOS * 1.5;
const maxRadiusConst = MAXPOS * 5;
ABWorld.drawCameraControls = false;
AB.drawRunControls = false;
// No army or texture array needed anymore
var textureArray = [];
// Add the text box to the HTML body
function addTextBox() {
const textboxHTML = `
<div style="position: absolute; top: 20px; left: 20px; z-index: 1000;">
<input type="text" id="userInput" placeholder="Type something..." />
<button onclick="showInput()">Submit</button>
<p id="outputText"></p>
</div>
`;
document.body.insertAdjacentHTML('beforeend', textboxHTML);
}
// Function to show the text entered in the textbox
function showInput() {
const userInput = document.getElementById("userInput").value;
document.getElementById("outputText").innerText = `You typed: ${userInput}`;
}
function loadResources() {
// All resources are ready instantly since we don't have any objects to load
initScene();
}
function initScene() {
// Just create an empty world, no objects to add
ABWorld.init3d(startRadiusConst, maxRadiusConst, SKYCOLOR);
// Render the world
ABWorld.render();
AB.removeLoading();
AB.runReady = true;
// Add the text box to the screen
addTextBox();
}
AB.world.newRun = function() {
AB.loadingScreen();
AB.runReady = false;
loadResources();
};
AB.world.nextStep = function() {
// No movement or interaction needed in this simple version
};