/* ============================================================================================== ATOM SMILE + DTIM ZEC DOOM (atom_smile_doom.pde) - VEXO CLIENT FORK Physik-Simulator & Topologic First-Person Observer Framework (Pure Software Raycaster) MIT License Copyright (c) 2024-2026 Jan Bühring & Adaptive Intelligence Synthesis Network (Google AI) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. ============================================================================================== */ import java.util.ArrayList; import java.util.HashMap; // ============================================================================================== // 1. GLOBALE VARIABLEN (ATOM SMILE EDITOR) // ============================================================================================== float feld = 10.0f; int num = 30; int num1 = 30; int level = 0; // Z-Achse int ordner = 0; // Run-ID int iv = 1; int lastSavedFrame = 1; class Particle { int id; int type; int x, y, z; int[] props = new int[16]; } ArrayList particles = new ArrayList(); int[] typeCounters = new int[8]; HashMap> memoryFrames = new HashMap>(); // Visuelles Gitter (0-104) int[][][][] gridData = new int[105][105][105][16]; String[] themeNames = {"Klassik", "C-Blind", "Kontrast"}; color[][] colorThemes = { { color(255, 255, 255), color(255, 50, 50), color(50, 255, 50), color(50, 100, 255), color(255, 255, 50), color(255, 50, 255), color(50, 255, 255), color(255, 150, 50) }, { color(255, 255, 255), color(230, 159, 0), color(86, 180, 233), color(0, 158, 115), color(240, 228, 66), color(0, 114, 178), color(213, 94, 0), color(204, 121, 167) }, { color(255, 255, 255), color(200, 0, 0), color(0, 200, 0), color(0, 0, 200), color(255, 200, 0), color(200, 0, 200), color(0, 200, 200), color(100, 100, 100) } }; int currentTheme = 0; String[] particleNames = {"nix", "proton", "neutron", "elektron", "photon", "positron", "neutrino", "quark"}; int currentParticle = 1; int[] inspectedProps = new int[16]; boolean hasInspected = false; int dom = 1; boolean showHelperGrid = true; boolean isPlaying = false; boolean urknallMode = false; boolean expertMode = false; boolean edgeWrapMode = true; int playTimer = 0; String flashMsg = ""; int flashMsgTimer = 0; int saveFlashTimer = 0; int sign(int v) { if (v > 0) return 1; if (v < 0) return -1; return 0; } // ============================================================================================== // 2. GLOBALE VARIABLEN (DTIM ZEC DOOM RAYCASTER) // ============================================================================================== boolean doomMode = false; // Haupt-Switch zwischen Editor und DOOM float posX = 1.5, posY = 1.5; float dirX = -1.0, dirY = 0.0; float planeX = 0.0, planeY = 0.66; float moveSpeed = 0.08; float rotSpeed = 0.04; float[] zBuffer = new float[800]; boolean[] keys = new boolean[256]; class DoomProjectile { float x, y; float vx, vy; color c; int type; int life = 100; DoomProjectile(float startX, float startY, float vX, float vY, int pType) { x = startX; y = startY; vx = vX; vy = vY; type = pType; c = colorThemes[currentTheme][type]; } } ArrayList doomProjectiles = new ArrayList(); float[] doomParticleSpeeds = { 0.0, 0.15, 0.15, 0.30, 0.40, 0.10, 0.20, 0.05 }; // ============================================================================================== // INITIALISIERUNG // ============================================================================================== void setup() { size(1200, 850); // Purer 2D Canvas für Linux/Wayland Stabilität noSmooth(); background(255); updateGridFromParticles(); drawBlankGrid(); } // ============================================================================================== // HAUPT-ZEICHNUNGSSCHLEIFE (MULTIPLEXER) // ============================================================================================== void draw() { if (doomMode) { drawDoomMode(); } else { drawEditorMode(); } } // ============================================================================================== // MODUS 1: ATOM SMILE EDITOR // ============================================================================================== void drawEditorMode() { if (urknallMode || isPlaying) { playTimer++; if (playTimer > 5) { playTimer = 0; long calcStart = millis(); updateAtomSimulation(false); long calcDuration = millis() - calcStart; if (calcDuration >= 5000) { isPlaying = false; urknallMode = false; showMessage("NOTAUS! Berechnung dauerte > 5 Sekunden.\nFrame " + iv + " eingefroren."); } else { if (urknallMode) { saveFrameData(); iv++; } } } } drawTopBar(); drawPropertyControls(); if (dom == 1) { dom = 0; drawBlankGrid(); } draw3DBlockArea(); if (!urknallMode && !isPlaying) { if (mouseX >= 0 && mouseX < 600 && mouseY >= 30 && mouseY < 630) { int cellX = floor(mouseX / feld); int cellY = floor((mouseY - 30) / feld); if (mousePressed && mouseButton == LEFT) { hasInspected = false; if (cellX <= num && cellY <= num) { for (int i = particles.size() - 1; i >= 0; i--) { Particle p = particles.get(i); if (p.x == cellX && p.y == cellY && p.z == level) particles.remove(i); } if (currentParticle != 0) { Particle p = new Particle(); p.type = currentParticle; p.id = typeCounters[currentParticle]++; p.x = cellX; p.y = cellY; p.z = level; color pCol = colorThemes[0][currentParticle]; p.props[0] = (int)red(pCol); p.props[1] = (int)green(pCol); p.props[2] = (int)blue(pCol); p.props[3] = p.type; for (int i=4; i<16; i++) p.props[i] = 0; setDefaultProps(p); particles.add(p); } updateGridFromParticles(); } fill(colorThemes[currentTheme][currentParticle]); stroke(200); rect(cellX * feld, 30 + cellY * feld, feld, feld); } if (mousePressed && mouseButton == RIGHT) { if (cellX <= num && cellY <= num) { int pType = gridData[cellX][cellY][level][3]; if (pType != 0) { currentParticle = pType; for(int i=0; i<16; i++) inspectedProps[i] = gridData[cellX][cellY][level][i]; hasInspected = true; } else { hasInspected = false; } } } } } if (flashMsgTimer > 0) { fill(0, 200); stroke(255); strokeWeight(2); rect(350, 350, 500, 100, 10); fill(255); textSize(18); textAlign(CENTER, CENTER); text(flashMsg, 600, 400); strokeWeight(1); flashMsgTimer--; } } void drawTopBar() { fill(255); noStroke(); rect(0, 0, 1200, 30); if (saveFlashTimer > 0) { fill(100, 255, 100); saveFlashTimer--; } else if (!frameExistsLocally(iv)) fill(255, 255, 100); else fill(245); rect(5, 3, 50, 24, 4); // Datei Button fill(240); stroke(150); rect(60, 3, 85, 24, 4); // Frame fill(240); rect(150, 3, 55, 24, 4); // Clear fill(isPlaying ? color(100, 255, 100) : color(255, 100, 100)); rect(210, 3, 75, 24, 4); // Sim fill(urknallMode ? color(255, 100, 255) : color(240)); rect(290, 3, 65, 24, 4); // Urknall fill(expertMode ? color(150, 150, 255) : color(240)); rect(360, 3, 85, 24, 4); // Mode fill(edgeWrapMode ? color(100, 255, 200) : color(240)); rect(450, 3, 80, 24, 4); // Wrap fill(240); stroke(150); rect(535, 3, 70, 24, 4); // Size fill(240); stroke(150); rect(610, 3, 70, 24, 4); // Run fill(240); stroke(150); rect(685, 3, 70, 24, 4); // Level fill(showHelperGrid ? color(200, 230, 255) : color(240)); rect(760, 3, 90, 24, 4); // Gitter // BUTTON: DOOM 3D boolean canDoom = (!isPlaying && !urknallMode); fill(canDoom ? color(0, 255, 200) : color(200, 50, 50)); stroke(150); rect(860, 3, 100, 24, 4); fill(240); stroke(150); rect(1060, 3, 130, 24, 4); // Design Button fill(0); textSize(14); textAlign(LEFT, CENTER); text("Datei", 12, 15); text("Frame: " + iv, 67, 15); text("Clear", 160, 15); text(isPlaying ? "Sim: ON" : "Sim: OFF", 217, 15); text("Urknall", 297, 15); text(expertMode ? "Mode: EXPT" : "Mode: NORM", 365, 15); text(edgeWrapMode ? "Wrap: ON" : "Wrap: OFF", 455, 15); text("Size: " + num, 542, 15); text("Run: " + ordner, 617, 15); text("Level: " + level, 692, 15); text(showHelperGrid ? "Gitter: AN" : "Gitter: AUS", 765, 15); textAlign(CENTER, CENTER); fill(canDoom ? color(0, 100, 50) : color(255)); text("DOOM 3D", 910, 15); fill(0); text("Design: " + themeNames[currentTheme], 1125, 15); textAlign(LEFT, CENTER); } // ============================================================================================== // EDITOR SYSTEM FUNKTIONEN (CACHING, SIMULATION) // ============================================================================================== void clearMemoryGrid() { int maxN = min(104, num + 2); for (int l = 0; l <= maxN; l++) { for (int y = 0; y <= maxN; y++) { for (int x = 0; x <= maxN; x++) { for (int p = 0; p < 16; p++) gridData[x][y][l][p] = 0; } } } } void updateGridFromParticles() { clearMemoryGrid(); for (Particle p : particles) { if (p.x >= 0 && p.x <= num && p.y >= 0 && p.y <= num && p.z >= 0 && p.z <= num) { for(int i=0; i<16; i++) gridData[p.x][p.y][p.z][i] = p.props[i]; } } } boolean frameExistsLocally(int targetFrame) { return memoryFrames.containsKey(targetFrame); } void showMessage(String text) { flashMsg = text; flashMsgTimer = 240; } void setDefaultProps(Particle p) { switch(p.type) { case 1: p.props[4]=938; p.props[5]=1; p.props[6]=1; break; case 2: p.props[4]=939; p.props[5]=0; p.props[6]=1; break; case 3: p.props[4]=1; p.props[5]=-1; p.props[6]=1; break; case 4: p.props[4]=0; p.props[5]=0; p.props[6]=2; break; case 5: p.props[4]=1; p.props[5]=1; p.props[6]=1; break; case 6: p.props[4]=0; p.props[5]=0; p.props[6]=1; break; case 7: p.props[4]=5; p.props[5]=2; p.props[6]=1; break; } } void updateAtomSimulation(boolean silent) { if (urknallMode) { if (num < 100) { num++; num1 = num; feld = 600.0f / (num + 1); ArrayList newP = new ArrayList(); for(Particle p : particles) { if(random(1) > 0.3f) { int nx = p.x + (int)random(3) - 1; int ny = p.y + (int)random(3) - 1; int nz = p.z + (int)random(3) - 1; if (edgeWrapMode) { nx = (nx + num + 1) % (num + 1); ny = (ny + num + 1) % (num + 1); nz = (nz + num + 1) % (num + 1); } else { nx = constrain(nx, 0, num); ny = constrain(ny, 0, num); nz = constrain(nz, 0, num); } if (gridData[nx][ny][nz][3] == 0) { Particle np = new Particle(); np.type = (int)random(1, 8); np.id = typeCounters[np.type]++; np.x = nx; np.y = ny; np.z = nz; color nCol = colorThemes[0][np.type]; np.props[0] = (int)red(nCol); np.props[1] = (int)green(nCol); np.props[2] = (int)blue(nCol); np.props[3] = np.type; for(int i=4; i<16; i++) np.props[i] = p.props[i]; setDefaultProps(np); np.props[15] = 255; newP.add(np); gridData[nx][ny][nz][3] = np.type; } } } particles.addAll(newP); } else { urknallMode = false; showMessage("Maximales Array-Limit erreicht.\nUrknall gestoppt."); } } ArrayList spawns = new ArrayList(); for (Particle p : particles) { if (p.props[15] > 0) p.props[15] = max(0, p.props[15] - 15); int moveX = 0, moveY = 0, moveZ = 0; if (p.type == 2 && random(1) < 0.005f) { p.type = 1; p.props[3] = 1; p.props[15] = 255; setDefaultProps(p); gridData[p.x][p.y][p.z][3] = 1; spawnParticleNear(3, p.x, p.y, p.z, spawns); spawnParticleNear(6, p.x, p.y, p.z, spawns); continue; } for (int dx = -2; dx <= 2; dx++) { for (int dy = -2; dy <= 2; dy++) { for (int dz = -2; dz <= 2; dz++) { if (dx == 0 && dy == 0 && dz == 0) continue; int checkX = p.x + dx; int checkY = p.y + dy; int checkZ = p.z + dz; if (edgeWrapMode) { checkX = (checkX + num + 1) % (num + 1); checkY = (checkY + num + 1) % (num + 1); checkZ = (checkZ + num + 1) % (num + 1); } else { if (checkX < 0 || checkX > num || checkY < 0 || checkY > num || checkZ < 0 || checkZ > num) continue; } int neighborType = gridData[checkX][checkY][checkZ][3]; if (neighborType == 0) continue; int distSq = dx*dx + dy*dy + dz*dz; if ((p.type == 1 || p.type == 2) && (neighborType == 1 || neighborType == 2)) { if (distSq <= 3) { moveX += sign(dx); moveY += sign(dy); moveZ += sign(dz); if (random(1) < 0.05f) p.props[15] = 255; } else if (p.type == 1 && neighborType == 1 && distSq > 3) { moveX -= sign(dx); moveY -= sign(dy); moveZ -= sign(dz); } } if (p.type == 3) { if (neighborType == 1) { if (distSq <= 2) { moveX -= sign(dx); moveY -= sign(dy); moveZ -= sign(dz); } else { moveX += sign(dx); moveY += sign(dy); moveZ += sign(dz); } } else if (neighborType == 3) { moveX -= sign(dx); moveY -= sign(dy); moveZ -= sign(dz); } } } } } int finalDx = 0, finalDy = 0, finalDz = 0; if (moveX != 0) finalDx = sign(moveX); else if (random(1) < 0.2f) finalDx = (int)random(3) - 1; if (moveY != 0) finalDy = sign(moveY); else if (random(1) < 0.2f) finalDy = (int)random(3) - 1; if (moveZ != 0) finalDz = sign(moveZ); else if (random(1) < 0.2f) finalDz = (int)random(3) - 1; int nx = p.x + finalDx; int ny = p.y + finalDy; int nz = p.z + finalDz; if (edgeWrapMode) { nx = (nx + num + 1) % (num + 1); ny = (ny + num + 1) % (num + 1); nz = (nz + num + 1) % (num + 1); } else { nx = constrain(nx, 0, num); ny = constrain(ny, 0, num); nz = constrain(nz, 0, num); } if (gridData[nx][ny][nz][3] == 0) { gridData[p.x][p.y][p.z][3] = 0; p.x = nx; p.y = ny; p.z = nz; gridData[nx][ny][nz][3] = p.type; } } particles.addAll(spawns); if (!silent) { updateGridFromParticles(); loadLevelToScreen(); } } void spawnParticleNear(int type, int x, int y, int z, ArrayList spawns) { for (int dx=-1; dx<=1; dx++) { for (int dy=-1; dy<=1; dy++) { for (int dz=-1; dz<=1; dz++) { int nx = x + dx; int ny = y + dy; int nz = z + dz; if (edgeWrapMode) { nx = (nx + num + 1) % (num + 1); ny = (ny + num + 1) % (num + 1); nz = (nz + num + 1) % (num + 1); } else { nx = constrain(nx, 0, num); ny = constrain(ny, 0, num); nz = constrain(nz, 0, num); } if (gridData[nx][ny][nz][3] == 0) { Particle np = new Particle(); np.type = type; np.id = typeCounters[type]++; np.x = nx; np.y = ny; np.z = nz; color nCol = colorThemes[0][type]; np.props[0] = (int)red(nCol); np.props[1] = (int)green(nCol); np.props[2] = (int)blue(nCol); np.props[3] = type; setDefaultProps(np); np.props[15] = 255; gridData[nx][ny][nz][3] = type; spawns.add(np); return; } } } } } color getParticleColor2D(int x, int y, int z) { int pType = gridData[x][y][z][3]; color baseC = colorThemes[currentTheme][pType]; int blinkTimer = gridData[x][y][z][15]; if (blinkTimer > 0) { float amt = (sin(blinkTimer * 0.2f) * 0.5f + 0.5f) * (blinkTimer / 255.0f); return lerpColor(baseC, color(255), amt); } return baseC; } void loadLevelToScreen() { fill(255); noStroke(); rect(0, 30, 600, 600); feld = 600.0f / (num + 1); stroke(220); strokeWeight(1); for (int i = 0; i <= num + 1; i++) { line(i * feld, 30, i * feld, 30 + 600); line(0, 30 + i * feld, 600, 30 + i * feld); } stroke(150, 100); strokeWeight(2); for (Particle p : particles) { if (p.z == level) { for(int dx=0; dx<=1; dx++) { for(int dy=0; dy<=1; dy++) { if(dx==0 && dy==0) continue; int nx = p.x + dx; int ny = p.y + dy; if(edgeWrapMode) { nx = (nx+num+1)%(num+1); ny = (ny+num+1)%(num+1); } if(nx>=0 && nx<=num && ny>=0 && ny<=num) { if(gridData[nx][ny][level][3] != 0 && abs(p.x - nx) <= 1 && abs(p.y - ny) <= 1) { line(p.x * feld + feld/2, 30 + p.y * feld + feld/2, nx * feld + feld/2, 30 + ny * feld + feld/2); } } } } } } strokeWeight(1); for (int y = 0; y <= num; y++) { for (int x = 0; x <= num; x++) { int pType = gridData[x][y][level][3]; if (pType != 0) { fill(getParticleColor2D(x, y, level)); stroke(150); rect(x * feld, 30 + y * feld, feld, feld); } } } } void drawBlankGrid() { fill(255); noStroke(); rect(0, 30, 600, 600); feld = 600.0f / (num + 1); stroke(220); strokeWeight(1); for (int i = 0; i <= num + 1; i++) { line(i * feld, 30, i * feld, 30 + 600); line(0, 30 + i * feld, 600, 30 + i * feld); } } void drawIsoCube(float sx, float sy, float S, color c) { fill(c); stroke(40, 60); beginShape(); vertex(sx, sy); vertex(sx + S, sy + S * 0.5f); vertex(sx, sy + S); vertex(sx - S, sy + S * 0.5f); endShape(CLOSE); fill(red(c) * 0.75f, green(c) * 0.75f, blue(c) * 0.75f); stroke(40, 60); beginShape(); vertex(sx - S, sy + S * 0.5f); vertex(sx, sy + S); vertex(sx, sy + S + S); vertex(sx - S, sy + S * 0.5f + S); endShape(CLOSE); fill(red(c) * 0.55f, green(c) * 0.55f, blue(c) * 0.55f); stroke(40, 60); beginShape(); vertex(sx, sy + S); vertex(sx + S, sy + S * 0.5f); vertex(sx + S, sy + S * 0.5f + S); vertex(sx, sy + S + S); endShape(CLOSE); } void draw3DBlockArea() { fill(245); stroke(180); rect(630, 30, 560, 600); fill(0); textSize(14); textAlign(LEFT, CENTER); text("3D Atom-Ansicht (Clean Voxel Mode)", 645, 48); float S = 265.0f / (num + 1); float originX = 910; float originY = 345; if (showHelperGrid) { stroke(180, 120); noFill(); for (int y = 0; y <= num; y++) { float x1 = originX + (0 - y) * S; float y1 = originY + (0 + y) * (S * 0.5f); float x2 = originX + (num - y) * S; float y2 = originY + (num + y) * (S * 0.5f); line(x1, y1, x2, y2); } for (int x = 0; x <= num; x++) { float x1 = originX + (x - 0) * S; float y1 = originY + (x + 0) * (S * 0.5f); float x2 = originX + (x - num) * S; float y2 = originY + (x + num) * (S * 0.5f); line(x1, y1, x2, y2); } } for (int l = 0; l <= num; l++) { for (int y = 0; y <= num; y++) { for (int x = 0; x <= num; x++) { int pType = gridData[x][y][l][3]; if (pType != 0) { color c = colorThemes[currentTheme][pType]; if (showHelperGrid && l != level) c = color(red(c), green(c), blue(c), 100); float sx = originX + (x - y) * S; float sy = originY + (x + y) * (S * 0.5f) - (l * S * 1.0f); drawIsoCube(sx, sy, S, c); } } } } } void drawPropertyControls() { noStroke(); fill(240); stroke(180); rect(5, 675, 400, 150, 6); if (!hasInspected) { fill(100); textSize(14); textAlign(LEFT, TOP); text("INSPEKTOR\n\nKlicke mit der RECHTEN Maustaste auf\nein Partikel im 2D-Gitter,\num seine Werte zu analysieren.", 20, 700); } else { fill(0); textSize(14); textAlign(LEFT, TOP); text("INSPEKTOR (LMT Klick ins Gitter zum Beenden)", 15, 685); text("Typ: " + particleNames[inspectedProps[3]].toUpperCase(), 15, 710); text("Energie: " + (inspectedProps[4] * 1.0f) + " MeV", 15, 730); text("Ladung: " + (inspectedProps[5] * 1.0f) + " e", 15, 750); text("Spin: " + (inspectedProps[6] * 0.5f) + " ħ", 15, 770); text("Zusatz: " + (inspectedProps[7] * 0.01f), 15, 790); if (expertMode) { text("Vel X: " + (inspectedProps[8] * 10.0f) + " m/s", 200, 710); text("Vel Y: " + (inspectedProps[9] * 10.0f) + " m/s", 200, 730); text("Vel Z: " + (inspectedProps[10] * 10.0f) + " m/s", 200, 750); text("Starke K.: " + (inspectedProps[11] * 2.5f) + " N", 200, 770); text("Schwache: " + (inspectedProps[12] * 0.1f) + " %", 200, 790); } } fill(colorThemes[currentTheme][currentParticle]); stroke(0); rect(0, 830, 405, 15); fill(currentParticle == 0 ? 0 : 255); textAlign(CENTER, CENTER); text("AKTIVES PARTIKEL: " + particleNames[currentParticle].toUpperCase(), 202, 837); fill(240); stroke(180); rect(410, 680, 480, 140, 6); fill(0); textSize(14); textAlign(LEFT, CENTER); text("Partikel-Palette (Klick zum Auswählen):", 425, 700); for (int i = 0; i < 8; i++) { float hx = 425 + (i * 55); float hy = 715; fill(colorThemes[currentTheme][i]); stroke(0); rect(hx, hy, 45, 45, 4); fill(0); textSize(10); textAlign(CENTER, CENTER); text(particleNames[i], hx + 22, hy + 55); if (currentParticle == i) { noFill(); stroke(0, 255, 0); strokeWeight(3); rect(hx - 2, hy - 2, 49, 49, 6); strokeWeight(1); } } } // Memory System void saveFrameData() { ArrayList cloneList = new ArrayList(); for(Particle p : particles) { Particle cp = new Particle(); cp.id = p.id; cp.type = p.type; cp.x = p.x; cp.y = p.y; cp.z = p.z; for(int i=0; i<16; i++) cp.props[i] = p.props[i]; cloneList.add(cp); } memoryFrames.put(iv, cloneList); lastSavedFrame = max(lastSavedFrame, iv); } void loadFrameData(int targetFrame) { if (memoryFrames.containsKey(targetFrame)) { particles.clear(); hasInspected = false; for (Particle mp : memoryFrames.get(targetFrame)) { Particle p = new Particle(); p.id = mp.id; p.type = mp.type; p.x = mp.x; p.y = mp.y; p.z = mp.z; for(int i=0; i<16; i++) p.props[i] = mp.props[i]; particles.add(p); } updateGridFromParticles(); loadLevelToScreen(); } } // ============================================================================================== // MODUS 2: DTIM ZEC DOOM RAYCASTER // ============================================================================================== void enterDoomMode() { doomMode = true; posX = num / 2.0f; posY = num / 2.0f; for (int r = 0; r <= num/2; r++) { for (int dx = -r; dx <= r; dx++) { for (int dy = -r; dy <= r; dy++) { int cx = constrain((int)posX + dx, 0, num); int cy = constrain((int)posY + dy, 0, num); if (getDoomMapCell(cx, cy) == 0) { posX = cx + 0.5f; posY = cy + 0.5f; return; } } } } } void exitDoomMode() { doomMode = false; background(255); // DOOM Bildschirm löschen loadLevelToScreen(); // Den Editor zwingen, sein 2D-Gitter frisch neu zu rendern } int getDoomMapCell(int x, int y) { if (x < 0 || x > num || y < 0 || y > num) return -1; return gridData[x][y][level][3]; } void drawDoomMode() { background(0); handleDoomKinematics(); updateDoomProjectiles(); renderRaycast3D(); renderDoomProjectiles3D(); renderDoomHUD2D(); } void handleDoomKinematics() { if (keys['W'] || keys['w']) { if (getDoomMapCell((int)(posX + dirX * moveSpeed), (int)posY) == 0) posX += dirX * moveSpeed; if (getDoomMapCell((int)posX, (int)(posY + dirY * moveSpeed)) == 0) posY += dirY * moveSpeed; } if (keys['S'] || keys['s']) { if (getDoomMapCell((int)(posX - dirX * moveSpeed), (int)posY) == 0) posX -= dirX * moveSpeed; if (getDoomMapCell((int)posX, (int)(posY - dirY * moveSpeed)) == 0) posY -= dirY * moveSpeed; } if (keys['A'] || keys['a']) { float sX = dirY; float sY = -dirX; if (getDoomMapCell((int)(posX + sX * moveSpeed), (int)posY) == 0) posX += sX * moveSpeed; if (getDoomMapCell((int)posX, (int)(posY + sY * moveSpeed)) == 0) posY += sY * moveSpeed; } if (keys['D'] || keys['d']) { float sX = -dirY; float sY = dirX; if (getDoomMapCell((int)(posX + sX * moveSpeed), (int)posY) == 0) posX += sX * moveSpeed; if (getDoomMapCell((int)posX, (int)(posY + sY * moveSpeed)) == 0) posY += sY * moveSpeed; } } void renderRaycast3D() { int viewW = 800; int viewH = height; int startX = 400; noStroke(); fill(10, 15, 25); rect(startX, 0, viewW, viewH / 2); // Decke fill(20, 30, 40); rect(startX, viewH / 2, viewW, viewH / 2); // Boden for (int x = 0; x < viewW; x++) { float cameraX = 2 * x / float(viewW) - 1; float rayDirX = dirX + planeX * cameraX; float rayDirY = dirY + planeY * cameraX; int mapX = (int)posX; int mapY = (int)posY; float deltaDistX = (rayDirX == 0) ? 1e30 : abs(1 / rayDirX); float deltaDistY = (rayDirY == 0) ? 1e30 : abs(1 / rayDirY); float perpWallDist; int stepX, stepY; float sideDistX, sideDistY; if (rayDirX < 0) { stepX = -1; sideDistX = (posX - mapX) * deltaDistX; } else { stepX = 1; sideDistX = (mapX + 1.0 - posX) * deltaDistX; } if (rayDirY < 0) { stepY = -1; sideDistY = (posY - mapY) * deltaDistY; } else { stepY = 1; sideDistY = (mapY + 1.0 - posY) * deltaDistY; } int hit = 0; int side = 0; int hitType = 0; while (hit == 0) { if (sideDistX < sideDistY) { sideDistX += deltaDistX; mapX += stepX; side = 0; } else { sideDistY += deltaDistY; mapY += stepY; side = 1; } hitType = getDoomMapCell(mapX, mapY); if (hitType != 0) hit = 1; } if (side == 0) perpWallDist = (mapX - posX + (1 - stepX) / 2) / rayDirX; else perpWallDist = (mapY - posY + (1 - stepY) / 2) / rayDirY; zBuffer[x] = perpWallDist; int lineHeight = (int)(viewH / perpWallDist); int drawStart = max(0, -lineHeight / 2 + viewH / 2); int drawEnd = min(viewH - 1, lineHeight / 2 + viewH / 2); color wallColor = (hitType == -1) ? color(100) : colorThemes[currentTheme][hitType]; if (side == 1) wallColor = color(red(wallColor)*0.7, green(wallColor)*0.7, blue(wallColor)*0.7); stroke(wallColor); line(startX + x, drawStart, startX + x, drawEnd); if (x % 20 == 0 || drawStart % 20 == 0) { stroke(255, 50); line(startX + x, drawStart, startX + x, drawEnd); } } } void fireDoomParticle() { if (currentParticle == 0) return; float spd = doomParticleSpeeds[currentParticle]; doomProjectiles.add(new DoomProjectile(posX, posY, dirX * spd, dirY * spd, currentParticle)); } void updateDoomProjectiles() { for (int i = doomProjectiles.size() - 1; i >= 0; i--) { DoomProjectile q = doomProjectiles.get(i); // Nächste berechnete Position des Projektils float nextX = q.x + q.vx; float nextY = q.y + q.vy; int nextCx = (int)nextX; int nextCy = (int)nextY; int hitType = getDoomMapCell(nextCx, nextCy); if (q.life <= 0 || hitType != 0) { // Wenn das Projektil eine Wand trifft (-1 oder Partikel) if (hitType != 0) { int currCx = (int)q.x; int currCy = (int)q.y; // Block dort einfügen, wo das Projektil VOR dem Aufprall war if (currCx >= 0 && currCx <= num && currCy >= 0 && currCy <= num) { // Schutzschaltung: Baue den Block nicht in den eigenen Körper! if (!(currCx == (int)posX && currCy == (int)posY)) { // Wenn der Platz frei ist, baue das Partikel als Wand if (gridData[currCx][currCy][level][3] == 0) { Particle p = new Particle(); p.type = q.type; p.id = typeCounters[q.type]++; p.x = currCx; p.y = currCy; p.z = level; color pCol = colorThemes[0][q.type]; p.props[0] = (int)red(pCol); p.props[1] = (int)green(pCol); p.props[2] = (int)blue(pCol); p.props[3] = p.type; for (int j = 4; j < 16; j++) p.props[j] = 0; setDefaultProps(p); p.props[15] = 255; // Kurzer visueller Flash // 1. In die Liste einfügen (für den 2D Editor) particles.add(p); // 2. Direkt ins Gitter schreiben (sofort sichtbar im DOOM Raycaster) for (int j = 0; j < 16; j++) { gridData[currCx][currCy][level][j] = p.props[j]; } } } } } doomProjectiles.remove(i); } else { q.x = nextX; q.y = nextY; q.life--; } } } void renderDoomProjectiles3D() { int viewW = 800; int viewH = height; int startX = 400; for (DoomProjectile q : doomProjectiles) { float spriteX = q.x - posX; float spriteY = q.y - posY; float invDet = 1.0 / (planeX * dirY - dirX * planeY); float transformX = invDet * (dirY * spriteX - dirX * spriteY); float transformY = invDet * (-planeY * spriteX + planeX * spriteY); if (transformY <= 0) continue; int spriteScreenX = (int)((viewW / 2) * (1 + transformX / transformY)); int spriteSize = abs((int)(viewH / transformY)) / 2; int drawStartY = max(0, -spriteSize / 2 + viewH / 2); int drawEndY = min(viewH - 1, spriteSize / 2 + viewH / 2); int drawStartX = max(0, -spriteSize / 2 + spriteScreenX); int drawEndX = min(viewW - 1, spriteSize / 2 + spriteScreenX); for (int stripe = drawStartX; stripe < drawEndX; stripe++) { if (transformY < zBuffer[stripe]) { float nx = map(stripe, drawStartX, drawEndX, -1, 1); for (int y = drawStartY; y < drawEndY; y++) { float ny = map(y, drawStartY, drawEndY, -1, 1); if (nx*nx + ny*ny < 1.0) { stroke(q.c); point(startX + stripe, y); } } } } } } void renderDoomHUD2D() { fill(5, 10, 15); noStroke(); rect(0, 0, 400, height); stroke(0, 150, 255); strokeWeight(2); line(400, 0, 400, height); fill(0, 255, 255); textSize(18); textAlign(LEFT, TOP); text("DTIM-ZEC QUANTUM TERMINAL", 20, 20); fill(100, 150, 200); textSize(12); text("Subsystem Self-Observation Framework", 20, 45); fill(255, 255, 0); text("Z-EBENE: " + level + " (Wechseln mit Q / E)", 20, 60); stroke(0, 100, 150); line(20, 75, 380, 75); // Minimap float mapX = 20, mapY = 90, mapW = 360, mapH = 360; fill(0, 5, 10); stroke(0, 100, 150); rect(mapX, mapY, mapW, mapH); float tileSize = min(mapW / (num+1), mapH / (num+1)); pushMatrix(); translate(mapX, mapY); noStroke(); for (int x = 0; x <= num; x++) { for (int y = 0; y <= num; y++) { int pType = getDoomMapCell(x, y); if (pType > 0) { fill(colorThemes[currentTheme][pType]); rect(x * tileSize, y * tileSize, tileSize - 1, tileSize - 1); } } } for (DoomProjectile q : doomProjectiles) { fill(q.c); ellipse(q.x * tileSize, q.y * tileSize, tileSize/2, tileSize/2); } fill(255, 255, 0); ellipse(posX * tileSize, posY * tileSize, tileSize/1.5, tileSize/1.5); stroke(255, 0, 0); line(posX * tileSize, posY * tileSize, (posX + dirX) * tileSize, (posY + dirY) * tileSize); popMatrix(); // Waffenarsenal fill(0, 255, 255); textSize(14); text("QUANTEN-EMITTER ARSENAL (Tasten 1-7)", 20, 470); for (int i = 1; i < 8; i++) { float yPos = 490 + (i * 28); if (i == currentParticle) { fill(50, 100, 150); noStroke(); rect(20, yPos - 4, 360, 24, 4); } fill(colorThemes[currentTheme][i]); stroke(255); rect(25, yPos, 16, 16); fill(i == currentParticle ? color(255) : color(150, 150, 200)); textSize(13); text("[" + i + "] " + particleNames[i], 55, yPos + 1); } // Zurück Button fill(200, 50, 50); stroke(255); rect(20, 780, 360, 40, 5); fill(255); textSize(16); textAlign(CENTER, CENTER); text("ZURÜCK ZUM EDITOR (Oder ESC drücken)", 200, 800); // Fadenkreuz stroke(0, 255, 0); strokeWeight(2); int cx = 400 + 800/2; int cy = height/2; line(cx - 10, cy, cx + 10, cy); line(cx, cy - 10, cx, cy + 10); noFill(); ellipse(cx, cy, 30, 30); strokeWeight(1); } // ============================================================================================== // GEMEINSAME EINGABE-EVENTS // ============================================================================================== void keyPressed() { if (keyCode < 256) keys[keyCode] = true; if (doomMode) { if (key >= '1' && key <= '7') currentParticle = key - '0'; if (key == 'e' || key == 'E') level = min(num, level + 1); if (key == 'q' || key == 'Q') level = max(0, level - 1); if (key == ESC) { key = 0; exitDoomMode(); } // Escape abfangen und Editor sauber wiederherstellen } } void keyReleased() { if (keyCode < 256) keys[keyCode] = false; } void mousePressed() { if (doomMode) { // Zurück-Button geklickt if (mouseX >= 20 && mouseX <= 380 && mouseY >= 780 && mouseY <= 820) { exitDoomMode(); return; } if (mouseX > 400 && mouseButton == LEFT) fireDoomParticle(); } else { // Top-Bar UI in Atom Smile (Moduswechsel) if (mouseY >= 0 && mouseY <= 30) { // DOOM BUTTON if (mouseX >= 860 && mouseX <= 960) { if (!isPlaying && !urknallMode) enterDoomMode(); return; } if (mouseX >= 150 && mouseX <= 205 && !isPlaying && !urknallMode) { particles.clear(); memoryFrames.clear(); for (int l = 0; l < 105; l++) { for (int y = 0; y < 105; y++) { for (int x = 0; x < 105; x++) gridData[x][y][l][3] = 0; } } updateGridFromParticles(); drawBlankGrid(); return; } if (mouseX >= 210 && mouseX <= 285) { isPlaying = !isPlaying; return; } if (mouseX >= 290 && mouseX <= 355) { urknallMode = !urknallMode; if (urknallMode) { if (particles.isEmpty()) { num = 2; num1 = num; iv = 1; feld = 600.0f / (num + 1); for(int i=0; i<8; i++) typeCounters[i]=0; Particle p = new Particle(); p.type = 7; p.id = typeCounters[7]++; p.x = 1; p.y = 1; p.z = 1; setDefaultProps(p); particles.add(p); clearMemoryGrid(); updateGridFromParticles(); loadLevelToScreen(); } isPlaying = true; hasInspected = false; } return; } if (mouseX >= 360 && mouseX <= 445) { expertMode = !expertMode; return; } if (mouseX >= 450 && mouseX <= 530) { edgeWrapMode = !edgeWrapMode; return; } if (mouseX >= 760 && mouseX <= 850) { showHelperGrid = !showHelperGrid; return; } if (mouseX >= 1060 && mouseX <= 1190) { currentTheme = (currentTheme + 1) % 3; loadLevelToScreen(); return; } if (mouseX >= 60 && mouseX <= 145 && !isPlaying && !urknallMode) { if (mouseButton == LEFT) iv = max(1, iv - 1); if (mouseButton == RIGHT) iv++; if (frameExistsLocally(iv)) loadFrameData(iv); else { particles.clear(); updateGridFromParticles(); drawBlankGrid(); } return; } if (mouseX >= 535 && mouseX <= 605 && !isPlaying && !urknallMode) { if (mouseButton == LEFT) num = min(100, num + 1); if (mouseButton == RIGHT) num = max(2, num - 1); num1 = num; feld = 600.0f / (num + 1); for (int i = particles.size() - 1; i >= 0; i--) { Particle p = particles.get(i); if (p.x > num || p.y > num || p.z > num) { gridData[p.x][p.y][p.z][3] = 0; particles.remove(i); } } updateGridFromParticles(); loadLevelToScreen(); return; } if (mouseX >= 610 && mouseX <= 680 && !isPlaying && !urknallMode) { if (mouseButton == LEFT) ordner++; if (mouseButton == RIGHT) ordner = max(0, ordner - 1); particles.clear(); memoryFrames.clear(); iv = 1; clearMemoryGrid(); updateGridFromParticles(); drawBlankGrid(); return; } if (mouseX >= 685 && mouseX <= 755 && !isPlaying && !urknallMode) { if (mouseButton == LEFT) level = min(num, level + 1); if (mouseButton == RIGHT) level = max(0, level - 1); loadLevelToScreen(); return; } if (mouseX >= 5 && mouseX <= 55 && !isPlaying && !urknallMode) { if (mouseButton == RIGHT) { saveFrameData(); saveFlashTimer = 20; iv++; } else if (mouseButton == LEFT) { iv = lastSavedFrame; loadFrameData(iv); } } } // Palette im Editor Modus if (mouseY >= 715 && mouseY <= 760 && mouseX >= 425 && mouseX <= 425 + (8 * 55)) { int clickedIdx = floor((mouseX - 425) / 55.0f); if (clickedIdx >= 0 && clickedIdx < 8) { currentParticle = clickedIdx; hasInspected = false; return; } } } } void mouseDragged() { if (doomMode && mouseX > 400) { float deltaX = mouseX - pmouseX; float rot = -deltaX * rotSpeed * 0.5; float oldDirX = dirX; dirX = dirX * cos(rot) - dirY * sin(rot); dirY = oldDirX * sin(rot) + dirY * cos(rot); float oldPlaneX = planeX; planeX = planeX * cos(rot) - planeY * sin(rot); planeY = oldPlaneX * sin(rot) + planeY * cos(rot); } }