Desktop / script.js
darkc0de's picture
Rename ai_studio_code.js to script.js
38ace53 verified
Raw
History Blame
6.16 kB
/* =========================================
1. Boot Sequence Logic
========================================= */
const bootLines =[
"XORTRON CRIMINAL COMPUTING BIOS v2.4.1",
"Copyright (C) 2084 XORTRON Syndicate",
"Initializing hardware interface... OK",
"Checking memory... 64000K OK",
"Loading Neural Net Drivers... SUCCESS",
"Connecting to Dark Web Node 77-Alpha...",
"Bypassing security protocols...",
"Decryption key accepted.",
"Mounting virtual drives...",
"System Ready. Welcome, Operative."
];
let bootScreen = document.getElementById('boot-screen');
let bootText = document.getElementById('boot-text');
let lineIndex = 0;
function runBootSequence() {
if (lineIndex < bootLines.length) {
bootText.innerHTML += bootLines[lineIndex] + "<br>";
lineIndex++;
// Speed of boot lines appearing
setTimeout(runBootSequence, Math.random() * 300 + 100);
} else {
// Wait 1 second after boot text finishes, then fade out
setTimeout(() => {
bootScreen.style.opacity = '0';
setTimeout(() => { bootScreen.style.display = 'none'; }, 1000);
}, 1000);
}
}
window.onload = runBootSequence;
/* =========================================
2. System Clock & Window Management
========================================= */
function updateClock() {
const now = new Date();
document.getElementById('clock').innerText = now.toLocaleTimeString();
}
setInterval(updateClock, 1000);
updateClock();
let highestZIndex = 10;
function openWindow(id) {
let win = document.getElementById(id);
win.style.display = 'flex';
bringToFront(win);
}
function closeWindow(id) {
document.getElementById(id).style.display = 'none';
}
function bringToFront(elmnt) {
highestZIndex++;
elmnt.style.zIndex = highestZIndex;
}
// Apply drag functionality to all windows
document.querySelectorAll('.window').forEach(win => {
dragElement(win);
// Bring window to front when clicked anywhere on it
win.addEventListener('mousedown', () => bringToFront(win));
});
function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
var header = document.getElementById(elmnt.id + "-header");
if (header) { header.onmousedown = dragMouseDown; }
else { elmnt.onmousedown = dragMouseDown; }
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
bringToFront(elmnt);
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
}
/* =========================================
3. XOR-Snake Game Logic
========================================= */
const canvas = document.getElementById('snake-canvas');
const ctx = canvas.getContext('2d');
const gridSize = 20;
let snake =[{x: 200, y: 200}];
let apple = {x: 100, y: 100};
let dx = 0;
let dy = 0;
let gameInterval;
let gameRunning = false;
function initSnake() {
if(gameRunning) return;
snake =[{x: 200, y: 200}];
dx = gridSize; dy = 0; // Start moving right
placeApple();
gameRunning = true;
gameInterval = setInterval(gameLoop, 100);
// Auto-focus window to accept keystrokes immediately
bringToFront(document.getElementById('snake-window'));
}
function placeApple() {
apple.x = Math.floor(Math.random() * (canvas.width / gridSize)) * gridSize;
apple.y = Math.floor(Math.random() * (canvas.height / gridSize)) * gridSize;
}
function gameLoop() {
// Move Snake
const head = {x: snake[0].x + dx, y: snake[0].y + dy};
snake.unshift(head);
// Check collision with apple
if (head.x === apple.x && head.y === apple.y) {
placeApple();
} else {
snake.pop(); // Remove tail if no apple eaten
}
// Check collision with walls or self
if (head.x < 0 || head.x >= canvas.width || head.y < 0 || head.y >= canvas.height || collision(head)) {
clearInterval(gameInterval);
gameRunning = false;
ctx.fillStyle = '#ff003c';
ctx.font = '30px "Share Tech Mono"';
ctx.fillText('SYSTEM FAILURE', 80, 200);
return;
}
// Draw Background
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw Grid Lines (Hacker aesthetic)
ctx.strokeStyle = '#003333';
for(let i=0; i<canvas.width; i+=gridSize) {
ctx.beginPath(); ctx.moveTo(i, 0); ctx.lineTo(i, canvas.height); ctx.stroke();
ctx.beginPath(); ctx.moveTo(0, i); ctx.lineTo(canvas.width, i); ctx.stroke();
}
// Draw Apple
ctx.fillStyle = '#ff003c';
ctx.fillRect(apple.x, apple.y, gridSize - 2, gridSize - 2);
// Draw Snake
ctx.fillStyle = '#00e5ff';
snake.forEach(part => {
ctx.fillRect(part.x, part.y, gridSize - 2, gridSize - 2);
});
}
function collision(head) {
for (let i = 1; i < snake.length; i++) {
if (head.x === snake[i].x && head.y === snake[i].y) return true;
}
return false;
}
// Arrow Key Controls for Snake (Only active if window is displayed)
document.addEventListener('keydown', (e) => {
if(document.getElementById('snake-window').style.display !== 'flex') return;
// Prevent default scrolling when using arrows
if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].indexOf(e.code) > -1) {
e.preventDefault();
}
if (e.code === 'ArrowUp' && dy === 0) { dx = 0; dy = -gridSize; }
else if (e.code === 'ArrowDown' && dy === 0) { dx = 0; dy = gridSize; }
else if (e.code === 'ArrowLeft' && dx === 0) { dx = -gridSize; dy = 0; }
else if (e.code === 'ArrowRight' && dx === 0) { dx = gridSize; dy = 0; }
});