pbInfo.ro
Probleme
Probleme - clasa a IX-a
Probleme - clasa a X-a
Probleme - clasa a XI-a
Probleme din concursuri
Căutare problemă
Exerciții
Programează cu Blockly
Desenează cu Processing
Exersează SQL
Soluţii
Resurse
Resurse pentru clasa a IX-a
Resurse pentru clasa a X-a
Resurse pentru clasa a XI-a
Articole recomandate
Subiecte bacalaureat
Ajutor
Autentificare
Înregistrare
Autentificare
Utilizator sau email
Parola
Acest site foloseşte cookies. Navigând în continuare, vă exprimaţi acordul asupra folosirii cookie-urilor.
Îti place pbInfo? Atunci acceptă-l cu totul! Dezactivează modulul de blocare a reclamelor!
v0.1 - NECSUCRAFT - Processing
Lista scripturi
Script Nou
Ajutor
ID
Autor
Duplicat din
Ultima modificare
#7243
7B-Necsulescu Stefan Matei (Stefan_Matei_Necsulescu)
-
Luni, 18 mai 2026, 10:53
// ===================================================== // ULTRA BLOCK ENGINE (JUICED & SATISFYING EDITION) // ===================================================== let world = new Map(); // ===================================================== // SETTINGS // ===================================================== const chunkSize = 16; const renderDistance = 0.5; const worldHeight = 64; const blockSize = 32; const eyeHeight = 50; const AIR = 0; const GRASS = 1; const STONE = 2; const WOOD = 3; const LEAVES = 4; const BRICK = 5; const CHEST = 6; const GLASS = 7; const GOLD = 8; const breakTimes = { [GRASS]: 15, [STONE]: 45, [WOOD]: 30, [LEAVES]: 6, [BRICK]: 50, [CHEST]: 25, [GLASS]: 8, [GOLD]: 70 }; // ===================================================== // PLAYER // ===================================================== let pX = 0; let pY = -300; let pZ = 0; let rotX = 0; let rotY = 0; let velocityY = 0; let isGrounded = false; const playerHeight = 55; const playerRadius = 10; let health = 100; let maxHealth = 100; let xp = 0; let level = 1; let fallStartY = 0; let selectedBlock = STONE; // Juice Variables let walkTimer = 0; let bobY = 0; let screenShake = 0; let damageFlash = 0; let hpVisual = 100; // Smoothly interpolated health bar // ===================================================== // INVENTORY // ===================================================== let inventory = { [GRASS]: 10, // Started with some blocks for instant fun [STONE]: 10, [WOOD]: 10, [LEAVES]: 10, [BRICK]: 10, [GLASS]: 10, [GOLD]: 10 }; // ===================================================== // VISUAL EFFECTS SYSTEMS // ===================================================== let structures = new Set(); let breakingBlock = null; let breakProgress = 0; let xpDrops = []; let particles = []; // Debris popping out of blocks let lootMessage = ""; let lootTimer = 0; let lootColor = [255, 255, 255]; // ===================================================== // PRELOAD & SETUP // ===================================================== function preload() { myFont = loadFont('https://cdnjs.cloudflare.com/ajax/libs/topcoat/0.8.0/font/SourceCodePro-Bold.otf'); } function setup() { pixelDensity(1); setAttributes('antialias', false); createCanvas(windowWidth, windowHeight, WEBGL); noiseSeed(5); textFont(myFont); noStroke(); document.body.style.overflow = "hidden"; document.oncontextmenu = () => false; } // ===================================================== // MAIN LOOP // ===================================================== function draw() { background(120, 190, 255); // Update Game Logic handleMovement(); handleCamera(); handlePhysics(); handleBlockBreaking(); updateParticles(); collectXP(); // Decays & Interpolations screenShake *= 0.85; if (damageFlash > 0) damageFlash -= 5; hpVisual = lerp(hpVisual, health, 0.15); // Math for look vectors let eyeY = pY - eyeHeight + bobY; let lookX = sin(rotY) * cos(rotX); let lookY = sin(rotX); let lookZ = -cos(rotY) * cos(rotX); // Apply Screen Shake right into the camera matrix let shakeX = random(-screenShake, screenShake); let shakeY = random(-screenShake, screenShake); let shakeZ = random(-screenShake, screenShake); camera( pX + shakeX, eyeY + shakeY, pZ + shakeZ, pX + lookX + shakeX, eyeY + lookY + shakeY, pZ + lookZ + shakeZ, 0, 1, 0 ); // Lights directionalLight(255, 255, 255, -1, -1, -1); ambientLight(damageFlash > 0 ? color(255, 120 - damageFlash, 120 - damageFlash) : 130); // 3D Rendering Passes renderWorld(); renderParticles(); renderXP(); drawCursor(); // 2D UI Overlay drawUI(); } // ===================================================== // WORLD OPERATIONS // ===================================================== function keyXYZ(x, y, z) { return `${x},${y},${z}`; } function getBlock(x, y, z) { return world.get(keyXYZ(x, y, z)) || 0; } function setBlock(x, y, z, type) { if (type === 0) world.delete(keyXYZ(x, y, z)); else world.set(keyXYZ(x, y, z), type); } // ===================================================== // WORLD GENERATION (Terrain & Structure Pops) // ===================================================== function generateChunk(cx, cz) { const chunkID = `${cx},${cz}`; if (structures.has(chunkID)) return; structures.add(chunkID); for (let x = 0; x < chunkSize; x++) { for (let z = 0; z < chunkSize; z++) { let wx = cx * chunkSize + x; let wz = cz * chunkSize + z; let h = floor(noise(wx * 0.05, wz * 0.05) * 8) + 4; for (let y = 0; y < h; y++) { let caveNoise = noise(wx * 0.09, y * 0.09, wz * 0.09); if (caveNoise > 0.63 && y > 2) continue; if (y === h - 1) setBlock(wx, y, wz, GRASS); else setBlock(wx, y, wz, STONE); } if (getBlock(wx, h - 1, wz) === GRASS && getBlock(wx, h, wz) === AIR) { let roll = random(); if (roll < 0.006) spawnTree(wx, h, wz); else if (roll < 0.007) spawnHouse(wx, h, wz); else if (roll < 0.009) setBlock(wx, h, wz, GOLD); } } } } function spawnTree(x, y, z) { let h = floor(random(3, 6)); for (let i = 0; i < h; i++) setBlock(x, y + i, z, WOOD); for (let lx = -2; lx <= 2; lx++) { for (let ly = -2; ly <= 2; ly++) { for (let lz = -2; lz <= 2; lz++) { if (abs(lx) + abs(ly) + abs(lz) < 4) { if (getBlock(x + lx, y + h - 1 + ly, z + lz) === AIR) { setBlock(x + lx, y + h - 1 + ly, z + lz, LEAVES); } } } } } } function spawnHouse(x, y, z) { for (let xx = 0; xx < 5; xx++) { for (let zz = 0; zz < 5; zz++) setBlock(x + xx, y, z + zz, BRICK); } for (let yy = 1; yy < 4; yy++) { for (let xx = 0; xx < 5; xx++) { for (let zz = 0; zz < 5; zz++) { if (xx === 0 || xx === 4 || zz === 0 || zz === 4) { setBlock(x + xx, y + yy, z + zz, WOOD); } } } } for (let xx = -1; xx < 6; xx++) { for (let zz = -1; zz < 6; zz++) setBlock(x + xx, y + 4, z + zz, BRICK); } setBlock(x + 2, y + 1, z, AIR); setBlock(x + 2, y + 2, z, AIR); setBlock(x + 3, y + 1, z + 3, CHEST); } // ===================================================== // RENDER WORLD (With dynamic impact squish) // ===================================================== function renderWorld() { let pcx = floor(pX / blockSize / chunkSize); let pcz = floor(pZ / blockSize / chunkSize); for (let cx = pcx - renderDistance; cx <= pcx + renderDistance; cx++) { for (let cz = pcz - renderDistance; cz <= pcz + renderDistance; cz++) { generateChunk(cx, cz); } } for (let [k, type] of world) { if (type === AIR) continue; let parts = k.split(","); let x = int(parts[0]); let y = int(parts[1]); let z = int(parts[2]); let wx = x * blockSize; let wy = -y * blockSize; let wz = z * blockSize; let dx = wx - pX; let dz = wz - pZ; let maxDist = renderDistance * chunkSize * blockSize; if (dx * dx + dz * dz > maxDist * maxDist) continue; let visible = getBlock(x + 1, y, z) === AIR || getBlock(x - 1, y, z) === AIR || getBlock(x, y + 1, z) === AIR || getBlock(x, y - 1, z) === AIR || getBlock(x, y, z + 1) === AIR || getBlock(x, y, z - 1) === AIR; if (!visible) continue; push(); translate(wx, wy, wz); blockColor(type); // Crunching crunch animation when hitting a block if (breakingBlock && breakingBlock.x === x && breakingBlock.y === y && breakingBlock.z === z) { let maxTime = breakTimes[type] || 30; let ratio = breakProgress / maxTime; // Jiggle scaling simulation let pulse = 1 - (ratio * 0.15) + sin(frameCount * 0.5) * 0.03; scale(pulse); // Hit flash overlay simulation if (frameCount % 4 < 2) fill(255, 255, 255, 150); } box(blockSize); pop(); } } function blockColor(t) { if (t === GRASS) fill(60, 210, 60); else if (t === STONE) fill(140, 142, 145); else if (t === WOOD) fill(135, 90, 50); else if (t === LEAVES) fill(45, 160, 45); else if (t === BRICK) fill(190, 80, 80); else if (t === CHEST) fill(235, 160, 40); else if (t === GLASS) fill(200, 235, 255, 180); else if (t === GOLD) fill(255, 215, 0); } // ===================================================== // PARTICLES ENGINE (Debris Burst) // ===================================================== function spawnDebris(bx, by, bz, type) { let count = type === LEAVES ? 8 : 15; for (let i = 0; i < count; i++) { particles.push({ x: bx + random(-10, 10), y: by + random(-10, 10), z: bz + random(-10, 10), vx: random(-3, 3), vy: random(-4, -1), vz: random(-3, 3), grav: 0.2, life: 1.0, decay: random(0.03, 0.06), type: type }); } } function updateParticles() { for (let i = particles.length - 1; i >= 0; i--) { let p = particles[i]; p.x += p.vx; p.vy += p.grav; p.y += p.vy; p.z += p.vz; p.life -= p.decay; if (p.life <= 0) particles.splice(i, 1); } } function renderParticles() { for (let p of particles) { push(); translate(p.x, p.y, p.z); blockColor(p.type); let sz = blockSize * 0.2 * p.life; box(sz); pop(); } } // ===================================================== // MOVEMENT & CAMERA WITH SMOOTH BOBBING // ===================================================== function handleMovement() { let speed = keyIsDown(SHIFT) ? 9 : 5.5; let dx = 0, dz = 0; if (keyIsDown(87)) { dx += sin(rotY); dz -= cos(rotY); } // W if (keyIsDown(83)) { dx -= sin(rotY); dz += cos(rotY); } // S if (keyIsDown(65)) { dx -= cos(rotY); dz -= sin(rotY); } // A if (keyIsDown(68)) { dx += cos(rotY); dz += sin(rotY); } // D let len = Math.hypot(dx, dz); if (len > 0) { dx = (dx / len) * speed; dz = (dz / len) * speed; if (isGrounded) { walkTimer += keyIsDown(SHIFT) ? 0.35 : 0.22; bobY = sin(walkTimer) * 3.5; // Natural headbobbing rhythm } } else { bobY = lerp(bobY, 0, 0.1); } if (!checkCollision(pX + dx, pY, pZ)) pX += dx; if (!checkCollision(pX, pY, pZ + dz)) pZ += dz; } function handleCamera() { let rs = 0.045; if (keyIsDown(74)) rotY -= rs; // J if (keyIsDown(76)) rotY += rs; // L if (keyIsDown(73)) rotX -= rs; // I if (keyIsDown(75)) rotX += rs; // K rotX = constrain(rotX, -1.45, 1.45); } // ===================================================== // PHYSICS & IMPACT CONCUSSION // ===================================================== function handlePhysics() { velocityY += 0.38; velocityY = constrain(velocityY, -50, 14); let ny = pY + velocityY; if (checkCollision(pX, ny, pZ)) { if (velocityY > 0) { if (!isGrounded) { // Just landed! Let's shake the screen based on structural velocity screenShake = map(velocityY, 0, 14, 1, 10); } isGrounded = true; let fallDist = abs(pY - fallStartY) / blockSize; if (fallDist > 3.5) { takeDamage(floor((fallDist - 3.5) * 6.5)); } } velocityY = 0; } else { pY = ny; if (isGrounded) fallStartY = pY; isGrounded = false; } } function checkCollision(x, y, z) { let pMinX = x - playerRadius, pMaxX = x + playerRadius; let pMinY = y - playerHeight, pMaxY = y; let pMinZ = z - playerRadius, pMaxZ = z + playerRadius; let startX = floor((pMinX + blockSize / 2) / blockSize); let endX = floor((pMaxX + blockSize / 2) / blockSize); let startZ = floor((pMinZ + blockSize / 2) / blockSize); let endZ = floor((pMaxZ + blockSize / 2) / blockSize); let startY = floor((-pMaxY + blockSize / 2) / blockSize); let endY = floor((-pMinY + blockSize / 2) / blockSize); for (let bx = startX; bx <= endX; bx++) { for (let by = startY; by <= endY; by++) { for (let bz = startZ; bz <= endZ; bz++) { if (getBlock(bx, by, bz) !== AIR) return true; } } } return false; } function takeDamage(amount) { health = max(0, health - amount); damageFlash = 80; screenShake = 12; // High impacts kick the camera out if (health <= 0) { health = maxHealth; hpVisual = 0; pX = 0; pY = -300; pZ = 0; velocityY = 0; lootMessage = "💥 WASTED 💥"; lootColor = [255, 50, 50]; lootTimer = 150; } } // ===================================================== // SATISFYING INTERACTIVE SYSTEMS (Mining / Placing) // ===================================================== function raycast() { let maxDist = 220; let eyeY = pY - eyeHeight + bobY; let dirX = sin(rotY) * cos(rotX), dirY = sin(rotX), dirZ = -cos(rotY) * cos(rotX); let lastX = floor(pX / blockSize), lastY = floor(-eyeY / blockSize), lastZ = floor(pZ / blockSize); for (let d = 0; d < maxDist; d += 1.5) { let rx = pX + dirX * d, ry = eyeY + dirY * d, rz = pZ + dirZ * d; let bx = floor(rx / blockSize), by = floor(-ry / blockSize), bz = floor(rz / blockSize); if (getBlock(bx, by, bz) !== AIR) { return { hit: { x: bx, y: by, z: bz }, prev: { x: lastX, y: lastY, z: lastZ } }; } lastX = bx; lastY = by; lastZ = bz; } return null; } function handleBlockBreaking() { if (mouseIsPressed && mouseButton === LEFT) { let result = raycast(); if (!result) { breakingBlock = null; breakProgress = 0; return; } let hit = result.hit; if (!breakingBlock || hit.x !== breakingBlock.x || hit.y !== breakingBlock.y || hit.z !== breakingBlock.z) { breakingBlock = hit; breakProgress = 0; } let type = getBlock(hit.x, hit.y, hit.z); breakProgress++; // Add subtle visual sparks/micro shakes while actively grinding blocks if (breakProgress % 3 === 0) { screenShake = max(screenShake, 1.2); } if (breakProgress >= (breakTimes[type] || 30)) { let targetX = hit.x * blockSize; let targetY = -hit.y * blockSize; let targetZ = hit.z * blockSize; // Burst particle debris spawnDebris(targetX, targetY, targetZ, type); screenShake = 6; // Destruction pop kick // Drop dynamic floating XP Orbs let dropAmt = floor(random(1, 4)); for (let j = 0; j < dropAmt; j++) { xpDrops.push({ x: targetX + random(-5, 5), y: targetY - 5, z: targetZ + random(-5, 5), pulseOffset: random(100) }); } // Special items checks if (type === CHEST) { let options = [ { name: "GOLD BLOCK", col: [255, 220, 0] }, { name: "DIAMOND MATRIX", col: [0, 240, 255] }, { name: "GOLDEN APPLE", col: [255, 100, 255] } ]; let choice = random(options); lootMessage = "💎 FOUND: " + choice.name; lootColor = choice.col; lootTimer = 140; inventory[GOLD] += 3; } if (inventory[type] !== undefined) inventory[type]++; setBlock(hit.x, hit.y, hit.z, AIR); breakingBlock = null; breakProgress = 0; } } else { breakingBlock = null; breakProgress = 0; } } // ===================================================== // MAGNETIC XP DROPS (Smooth Pull Trail) // ===================================================== function renderXP() { for (let x of xpDrops) { push(); translate(x.x, x.y + sin(frameCount * 0.15 + x.pulseOffset) * 4, x.z); emissiveMaterial(0, 255, 150); // Pulsing size glow simulation let sRadius = 4 + sin(frameCount * 0.2) * 1.5; sphere(sRadius); pop(); } } function collectXP() { for (let i = xpDrops.length - 1; i >= 0; i--) { let x = xpDrops[i]; // Calculate 3D distances let dx = pX - x.x, dy = (pY - eyeHeight) - x.y, dz = pZ - x.z; let distSQ = dx * dx + dy * dy + dz * dz; let dist = sqrt(distSQ); // Magnets engage up close if (dist < 120) { let pullSpeed = map(dist, 0, 120, 0.45, 0.08); x.x = lerp(x.x, pX, pullSpeed); x.y = lerp(x.y, pY - eyeHeight/2, pullSpeed); x.z = lerp(x.z, pZ, pullSpeed); } if (dist < 16) { xp += 15; xpDrops.splice(i, 1); screenShake = max(screenShake, 2); // Level up flash if (xp >= level * 80) { level++; health = maxHealth; lootMessage = "⭐ LEVEL UP: " + level + " ⭐"; lootColor = [100, 255, 100]; lootTimer = 160; } } } } // ===================================================== // TARGET SELECTION OUTLINE // ===================================================== function drawCursor() { let result = raycast(); if (!result) return; let h = result.hit; push(); translate(h.x * blockSize, -h.y * blockSize, h.z * blockSize); noFill(); // Neon breathing pulse overlay selector box let selectGlow = 160 + sin(frameCount * 0.2) * 95; stroke(255, selectGlow, selectGlow); strokeWeight(1.5); box(blockSize * 1.04); pop(); } function mousePressed() { let result = raycast(); if (!result) return; if (mouseButton === RIGHT) { let p = result.prev; if (inventory[selectedBlock] <= 0) return; if (getBlock(p.x, p.y, p.z) === AIR) { setBlock(p.x, p.y, p.z, selectedBlock); if (checkCollision(pX, pY, pZ)) { setBlock(p.x, p.y, p.z, AIR); return; } // Placed block micro impact response inventory[selectedBlock]--; screenShake = 3; } } } // ===================================================== // JUICY UI DISPLAY OVERLAYS // ===================================================== function drawUI() { push(); resetMatrix(); ortho(); noLights(); // Dynamic crosshair scale dependent on actions let crossSz = (breakingBlock) ? 14 + sin(frameCount * 0.5) * 3 : 8; stroke(255); strokeWeight(2); line(-crossSz, 0, crossSz, 0); line(0, -crossSz, 0, crossSz); noStroke(); // Draw Block Inventory Matrix let startY = -height / 2 + 50; let activeOffset = sin(frameCount * 0.1) * 3; const blockNames = ["AIR", "GRASS", "STONE", "WOOD", "LEAVES", "BRICK", "CHEST", "GLASS", "GOLD"]; fill(0, 0, 0, 70); rect(-width / 2 + 10, startY - 20, 180, 210, 8); for (let key in inventory) { let isSelected = (int(key) === selectedBlock); if (isSelected) { fill(255, 230, 100); textSize(17); text(`👉 ${blockNames[key]}: ${inventory[key]}`, -width / 2 + 25 + activeOffset, startY); } else { fill(210); textSize(14); text(` ${blockNames[key]}: ${inventory[key]}`, -width / 2 + 25, startY); } startY += 24; } // DAMAGE SCREEN FLASH FILTER if (damageFlash > 0) { fill(255, 0, 0, map(damageFlash, 0, 80, 0, 75)); rect(-width / 2, -height / 2, width, height); } // HEALTH BAR (Interpolated sliding value) let barW = 240, barH = 24; let hpX = -width / 2 + 30, hpY = height / 2 - 50; fill(30, 30, 30, 150); rect(hpX, hpY, barW, barH, 4); let visualWidth = map(hpVisual, 0, maxHealth, 0, barW); fill(255, 60, 80); rect(hpX, hpY, visualWidth, barH, 4); fill(255); textSize(14); textAlign(LEFT, CENTER); text(`HP ${health} / ${maxHealth}`, hpX + 15, hpY + barH / 2); // LEVEL & XP BAR STATS DISPLAY textSize(15); fill(100, 255, 180); text(`LEVEL ${level}`, hpX, hpY - 45); fill(230); text(`XP ${xp}`, hpX + 110, hpY - 45); // NOTIFICATION BANNER STRIP if (lootTimer > 0) { fill(lootColor[0], lootColor[1], lootColor[2], map(lootTimer, 0, 140, 0, 255)); textSize(26); textAlign(CENTER, CENTER); // Scaling impact splash when banner presents let scaleIn = 1.0; if (lootTimer > 120) scaleIn = map(lootTimer, 140, 120, 1.5, 1.0); push(); scale(scaleIn); text(lootMessage, 0, -height / 3); pop(); lootTimer--; } pop(); } // ===================================================== // CONTROLLER HOOKS // ===================================================== function keyPressed() { if (key === " " && isGrounded) { velocityY = -5.8; // Snappy upwards propulsion velocity screenShake = 3; } if (key === "1") selectedBlock = GRASS; if (key === "2") selectedBlock = STONE; if (key === "3") selectedBlock = WOOD; if (key === "4") selectedBlock = LEAVES; if (key === "5") selectedBlock = BRICK; if (key === "6") selectedBlock = GLASS; if (key === "7") selectedBlock = GOLD; } function windowResized() { resizeCanvas(windowWidth, windowHeight); }
Duplicare
Executare
Cod
Cod HTML
<iframe sandbox="allow-scripts" src="/p5js/index.php?id=7243" style="width:408px; height:408px;border:solid 1px gray; overflow: scroll;"></iframe>
Duplicare script
Denumirea noului script
Du-te sus!