Comutare navigație
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
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!
×
Lista scripturi
Script Nou
Ajutor
"MINECRAFT FR v1.1.0" - Processing
ID
Autor
Duplicat din
Ultima modificare
#6330
6B-Necsulescu Stefan Matei (Stefan_Matei_Necsulescu)
-
Duminica, 17 nov 2024, 14:24
///NU UITATI SA CITITI INSTRUCTIUNILE!!!! ///POATE CA VI SE PARE CA ESTE UN CER SI DA, UAAAU. DAR DE FAPT POTI SA TE MISTI UTILIZAND W A S D SI POTI SA ROTESTI CAMERA UTILIZAND MOUS-UL. ///VA ROG, DACA AVETI IMBUNATATIRI SCRIETI-LE LA ADRESA DE E-MAIL: "necsulescu.stefan@gmail.com"; ///VA ROG SA ADAUGATI SURVIVE MODE, GRAVITATIE MOBI ETC. // Camera: let rotX = 0; let rotZ = 0; let camX = -10; //absolute let camY = -10; let camZ = -10; let camCenterX = 10; //relative let camCenterY = 0; let camCenterZ = 0; let camUpX = 0; // relative let camUpY = 0; let camUpZ = 1; const camPosChange = 1; const camRotChange = 2; // Minecraft: const worldHeight = 5; const worldLength = 5; const worldWidth = 5; const cubeSize = 10; let world = new Array(worldHeight); let keysPressed; function setup() { createCanvas(windowWidth - 20, windowHeight - 20, WEBGL); for (let hgt = 0; hgt < worldHeight; hgt++) { world[hgt] = new Array(worldLength); for (let len = 0; len < worldLength; len++) { world[hgt][len] = new Array(worldWidth); for (let wdt = 0; wdt < worldWidth; wdt++) { /* let distToCenter = sqrt(sq(hgt - int(worldHeight / 2)) + sq(len - int(worldLength / 2)) + sq(wdt - int(worldWidth / 2))); if (distToCenter <= worldHeight / 2 && distToCenter >= worldHeight / 2 - 2) { world[hgt][len][wdt] = true; } else { world[hgt][len][wdt] = false; } */ if (random() < 0.5) { world[hgt][len][wdt] = true; } else { world[hgt][len][wdt] = false; } } } } } function draw() { resizeCanvas(windowWidth - 20, windowHeight - 20); background(0x55, 0xCC, 0xFF); resetMatrix(); ambientLight(255); pointLight(100, 100, 100, 100, 100, -1000); specularMaterial(200, 200, 200); shininess(1); perspective(1, width / height, 0.01, 10000); if (keyIsPressed) { if (keysPressed.w == true) { camX += camPosChange * cos(rotZ); camY += camPosChange * sin(rotZ); } else if (keysPressed.s == true) { camX -= camPosChange * cos(rotZ); camY -= camPosChange * sin(rotZ); } if (keysPressed.a == true) { camX -= camPosChange * camCenterY; camY += camPosChange * camCenterX; } else if (keysPressed.d == true) { camX += camPosChange * camCenterY; camY -= camPosChange * camCenterX; } if (keysPressed.q == true) { camZ -= camPosChange; } else if (keysPressed.e == true) { camZ += camPosChange; } } rotZ = map(mouseX, 0, width - 1, PI, -PI) * camRotChange; rotX = map(mouseY, 0, height - 1, -HALF_PI, HALF_PI) * camRotChange; if (rotX >= HALF_PI) { rotX = HALF_PI - 0.0001; } if (rotX <= -HALF_PI) { rotX = -HALF_PI + 0.0001; } camCenterX = cos(rotZ) * cos(rotX); camCenterY = sin(rotZ) * cos(rotX); camCenterZ = sin(rotX); camera(camX, camY, camZ, camX + camCenterX, camY + camCenterY, camZ + camCenterZ, camUpX, camUpY, camUpZ); // begin drawing *************************************** strokeWeight(2); stroke(0); fill(0xEE); for (let hgt = 0; hgt < worldHeight; hgt++) { for (let len = 0; len < worldLength; len++) { for (let wdt = 0; wdt < worldWidth; wdt++) { if (world[hgt][len][wdt] == true) { beginShape(QUADS); if (wdt == 0 || world[hgt][len][wdt - 1] == false) { //fill(0xE8); beginShape(); vertex((wdt) * cubeSize, (len) * cubeSize, (hgt) * cubeSize); vertex((wdt) * cubeSize, (len) * cubeSize, (hgt + 1) * cubeSize); vertex((wdt) * cubeSize, (len + 1) * cubeSize, (hgt + 1) * cubeSize); vertex((wdt) * cubeSize, (len + 1) * cubeSize, (hgt) * cubeSize); endShape(CLOSE); } if (len == 0 || world[hgt][len - 1][wdt] == false) { //fill(0xEC); beginShape(); vertex((wdt) * cubeSize, (len) * cubeSize, (hgt) * cubeSize); vertex((wdt + 1) * cubeSize, (len) * cubeSize, (hgt) * cubeSize); vertex((wdt + 1) * cubeSize, (len) * cubeSize, (hgt + 1) * cubeSize); vertex((wdt) * cubeSize, (len) * cubeSize, (hgt + 1) * cubeSize); endShape(CLOSE); } if (hgt == 0 || world[hgt - 1][len][wdt] == false) { //fill(0xF0); beginShape(); vertex((wdt) * cubeSize, (len + 1) * cubeSize, (hgt) * cubeSize); vertex((wdt + 1) * cubeSize, (len + 1) * cubeSize, (hgt) * cubeSize); vertex((wdt + 1) * cubeSize, (len) * cubeSize, (hgt) * cubeSize); vertex((wdt) * cubeSize, (len) * cubeSize, (hgt) * cubeSize); endShape(CLOSE); } if (wdt == worldWidth - 1 || world[hgt][len][wdt + 1] == false) { //fill(0xD8); beginShape(); vertex((wdt + 1) * cubeSize, (len) * cubeSize, (hgt) * cubeSize); vertex((wdt + 1) * cubeSize, (len) * cubeSize, (hgt + 1) * cubeSize); vertex((wdt + 1) * cubeSize, (len + 1) * cubeSize, (hgt + 1) * cubeSize); vertex((wdt + 1) * cubeSize, (len + 1) * cubeSize, (hgt) * cubeSize); endShape(CLOSE); } if (len == worldLength - 1 || world[hgt][len + 1][wdt] == false) { //fill(0xDC); beginShape(); vertex((wdt) * cubeSize, (len + 1) * cubeSize, (hgt) * cubeSize); vertex((wdt + 1) * cubeSize, (len + 1) * cubeSize, (hgt) * cubeSize); vertex((wdt + 1) * cubeSize, (len + 1) * cubeSize, (hgt + 1) * cubeSize); vertex((wdt) * cubeSize, (len + 1) * cubeSize, (hgt + 1) * cubeSize); endShape(CLOSE); } if (hgt == worldHeight - 1 || world[hgt + 1][len][wdt] == false) { //fill(0xE0); beginShape(); vertex((wdt) * cubeSize, (len + 1) * cubeSize, (hgt + 1) * cubeSize); vertex((wdt + 1) * cubeSize, (len + 1) * cubeSize, (hgt + 1) * cubeSize); vertex((wdt + 1) * cubeSize, (len) * cubeSize, (hgt + 1) * cubeSize); vertex((wdt) * cubeSize, (len) * cubeSize, (hgt + 1) * cubeSize); endShape(CLOSE); } } } } } } class KeysPressed { constructor() { this.w = false; this.s = false; this.a = false; this.d = false; this.q = false; this.e = false; } pressKey(k) { switch (k) { case 'w': this.w = true; break; case 's': this.s = true; break; case 'a': this.a = true; break; case 'd': this.d = true; break; case 'q': this.q = true; break; case 'e': this.e = true; break; } } releaseKey(k) { switch (k) { case 'w': this.w = false; break; case 's': this.s = false; break; case 'a': this.a = false; break; case 'd': this.d = false; break; case 'q': this.q = false; break; case 'e': this.e = false; break; } } } keysPressed = new KeysPressed(); function keyPressed() { keysPressed.pressKey(key); return false; } function keyReleased() { keysPressed.releaseKey(key); return false; } //
Duplicare
Executare
Cod
×
Cod HTML
<iframe sandbox="allow-scripts" src="/p5js/index.php?id=6330" style="width:408px; height:408px;border:solid 1px gray; overflow: scroll;"></iframe>
×
Duplicare script
Denumirea noului script
Du-te sus!