// ========================================================== // TLW-Modell: Mars-Kolonisations-Demo & Automatisierte Abwehr // Website: jan-buehring.de | Hard Sci-Fi Story-Simulation // ========================================================== float shipX, shipY; float velocityX = 0, velocityY = 0; float tlwEnergy = 40.0; float maxEnergy = 150.0; // Upgrades & Automatisierung boolean hasIdleCharger = false; boolean coreActive = false; boolean shieldActive = false; boolean isruActive = false; boolean hasTLWDefense = false; // Neue Abwehr-Funktion für automatischen Schutz // Story & Katastrophen-Steuerung boolean disasterMode = false; boolean firstAutoFireTriggered = false; // Für das erste Auto-Fire Popup float meteorX, meteorY; float meteorSize = 70; float meteorHP = 120.0; float meteorMaxHP = 120.0; int spawnTimer = 0; String activePopupTitle = ""; String activePopupText = ""; boolean showPopup = false; boolean pauseForWarning = false; // Pausiert das Spiel beim Alarm-Popup ArrayList tokens; ArrayList projectiles; ArrayList particles; ArrayList gridCells; void setup() { size(900, 680); shipX = width / 2; shipY = (height - 120) / 2; tokens = new ArrayList(); projectiles = new ArrayList(); particles = new ArrayList(); gridCells = new ArrayList(); for (int i = 0; i < 6; i++) { tokens.add(new TLWToken(random(50, width-50), random(50, height-170))); } for (int x = 30; x < width; x += 60) { for (int y = 30; y < height - 140; y += 60) { gridCells.add(new FieldCell(x, y)); } } triggerStory("KOLONIE IM AUFBAU", "Sammle Energie, erweitere dein Lager (Idle-Ladetool) und bereite die Mars-Besiedlung vor. Die Fachwelt blickt gespannt auf das TLW-Modell!"); } void draw() { background(8, 10, 18); // 1. TLW-Feldmatrix zeichnen drawTLWMatrix(); // 2. Idle-Laden (wenn kein Alarm-Pause aktiv ist) if (hasIdleCharger && !pauseForWarning) { if (frameCount % 15 == 0 && tlwEnergy < maxEnergy) { tlwEnergy += 0.9; } } // 3. Gameplay-Loop (nur wenn nicht pausiert) if (!pauseForWarning) { if (!disasterMode) { updateNormalGameplay(); // Random Meteoriten-Spawn nach vollständigem Aufbau if (isruActive) { spawnTimer++; if (spawnTimer > 450 && random(100) < 2) { triggerDisaster(); } } } else { updateDisasterGameplay(); } } // 4. Globale Updates & UI updateParticles(); drawHUD(); drawStoryPopup(); } void updateNormalGameplay() { updateShipMovement(); manageTokens(); drawShip(); } void updateDisasterGameplay() { shipX = lerp(shipX, constrain(mouseX, 30, width - 30), 0.2); shipY = lerp(shipY, constrain(mouseY, 30, height - 140), 0.2); meteorY += 0.5; meteorX += sin(frameCount * 0.03) * 0.6; // Wenn automatische TLW-Abwehr gekauft wurde: Automatisches Feuern! if (hasTLWDefense) { if (!firstAutoFireTriggered) { triggerStory("TLW-ABWEHR AKTIVIERT", "Die automatische Zielerfassung hat den Meteoriten erkannt! Das TLW-Feld feuert selbstständig Energiewellen ab, um den Einschlag zu verhindern."); firstAutoFireTriggered = true; } // Auto-Fire Schüsse if (frameCount % 12 == 0 && tlwEnergy >= 1.5) { tlwEnergy -= 1.5; projectiles.add(new Projectile(shipX, shipY, meteorX, meteorY)); } } // Meteorit zeichnen pushStyle(); fill(180, 60, 40); stroke(255, 120, 50); strokeWeight(2); ellipse(meteorX, meteorY, meteorSize, meteorSize); fill(40); noStroke(); rect(meteorX - 40, meteorY - 50, 80, 8, 3); fill(255, 50, 50); float hpW = map(meteorHP, 0, meteorMaxHP, 0, 80); rect(meteorX - 40, meteorY - 50, hpW, 8, 3); popStyle(); // Projektile aktualisieren & Kollision for (int i = projectiles.size() - 1; i >= 0; i--) { Projectile p = projectiles.get(i); p.update(); p.display(); if (dist(p.x, p.y, meteorX, meteorY) < meteorSize/2) { meteorHP -= 15; projectiles.remove(i); for(int k=0; k<4; k++) { particles.add(new Particle(p.x, p.y, random(-2,2), random(-2,2), color(255,200,100))); } if (meteorHP <= 0) { disasterMode = false; meteorHP = meteorMaxHP; spawnTimer = 0; triggerStory("BEDROHUNG ABGEWENDET", "Das TLW-Modell hat seine Praxistauglichkeit bewiesen. Der Meteorit wurde durch Feldverzerrung und Partikelbeschuss im Vakuum neutralisiert!"); } } else if (p.isOffScreen()) { projectiles.remove(i); } } drawShip(); if (meteorY > height - 160) { meteorY = height - 160; triggerStory("SCHILD-TREFFER", "Der Meteorit schlägt ein! Kaufe unbedingt die automatische Abwehr-Funktion, um solche Krisen künftig eigenständig abzuwehren."); } } void updateShipMovement() { float targetX = mouseX; float targetY = mouseY; float dx = targetX - shipX; float dy = targetY - shipY; if (mousePressed && mouseY < height - 120 && tlwEnergy > 0.2) { velocityX += dx * 0.005; velocityY += dy * 0.005; tlwEnergy -= 0.1; if (frameCount % 3 == 0) { particles.add(new Particle(shipX, shipY, -velocityX * 0.5, -velocityY * 0.5, color(255, 100, 255))); } } velocityX *= 0.94; velocityY *= 0.94; shipX += velocityX; shipY += velocityY; shipX = constrain(shipX, 30, width - 30); shipY = constrain(shipY, 30, height - 140); } void triggerDisaster() { disasterMode = true; pauseForWarning = true; // Spiel pausiert beim Alarm meteorX = width / 2 + random(-120, 120); meteorY = -50; triggerStory("⚠️ KRISEN-ALARM: METEORIT NÄHERT SICH!", "Die Sensoren melden einen Himmelskörper auf Kollisionskurs! Wir müssen uns schützen. Aktiviere die TLW-Abwehr, um das Lager und die Kolonie zu verteidigen!"); } void drawTLWMatrix() { strokeWeight(1); for (FieldCell c : gridCells) { c.updateAndDisplay(shipX, shipY, disasterMode ? meteorX : 0, disasterMode ? meteorY : 0); } fill(120, 45, 25); noStroke(); rect(0, height - 120, width, 120); fill(190, 75, 40); rect(0, height - 128, width, 8); } void manageTokens() { for (int i = tokens.size() - 1; i >= 0; i--) { TLWToken t = tokens.get(i); t.display(); if (dist(shipX, shipY, t.x, t.y) < 25) { tlwEnergy = min(maxEnergy, tlwEnergy + 20.0); tokens.remove(i); tokens.add(new TLWToken(random(50, width-50), random(50, height-170))); } } } void updateParticles() { for (int i = particles.size() - 1; i >= 0; i--) { Particle p = particles.get(i); p.update(); p.display(); if (p.isDead()) { particles.remove(i); } } } void drawShip() { pushStyle(); pushMatrix(); translate(shipX, shipY); float angle = disasterMode ? atan2(meteorY - shipY, meteorX - shipX) - HALF_PI : atan2(velocityY, velocityX) + HALF_PI; rotate(angle); fill(0, 200, 255); stroke(255); strokeWeight(1.5); triangle(0, -18, -12, 16, 12, 16); fill(255, 100, 255); ellipse(0, 2, 6, 6); popMatrix(); popStyle(); } void drawHUD() { pushStyle(); fill(15, 20, 35, 235); stroke(60, 110, 190); strokeWeight(2); rect(15, 15, width - 30, 95, 8); fill(40); noStroke(); rect(25, 45, 180, 16, 4); fill(disasterMode ? color(255, 50, 50) : color(255, 0, 200)); float energyWidth = map(tlwEnergy, 0, maxEnergy, 0, 180); rect(25, 45, energyWidth, 16, 4); fill(255); textSize(12); text("TLW-ENERGIE: " + int(tlwEnergy) + " / " + int(maxEnergy), 25, 35); if (disasterMode) { fill(255, 80, 80); text("⚠️ METEORIT IM ANFLUG! (ABWEHR BZW. SCHIESSEN AKTIV)", 215, 35); } else if (hasIdleCharger) { fill(0, 255, 120); text("[IDLE LAGER-TOOL AKTIV]", 215, 35); } textSize(11); fill(200, 220, 255); text("UPGRADES & SCHUTZ:", 25, 85); // Upgrades fill(hasIdleCharger ? color(0,255,100) : color(80)); rect(165, 72, 100, 26, 4); fill(0); textSize(10); text(hasIdleCharger ? "Lager: AN" : "Lager (50E)", 173, 88); fill(coreActive ? color(0,255,100) : color(80)); rect(275, 72, 90, 26, 4); fill(0); text(coreActive ? "1. Kern: OK" : "1. Kern (70E)", 281, 88); fill(shieldActive ? color(0,255,100) : color(80)); rect(375, 72, 90, 26, 4); fill(0); text(shieldActive ? "2. Schild: OK" : "2. Schild (90E)", 381, 88); fill(isruActive ? color(0,255,100) : color(80)); rect(475, 72, 90, 26, 4); fill(0); text(isruActive ? "3. ISRU: OK" : "3. ISRU (110E)", 481, 88); fill(hasTLWDefense ? color(0,255,100) : color(80)); rect(575, 72, 115, 26, 4); fill(0); text(hasTLWDefense ? "Abwehr: AN" : "Abwehr (80E)", 582, 88); // Visualisierung Basis if (coreActive) { stroke(0,255,100); noFill(); ellipse(width/2 - 120, height - 60, 45, 45); } if (shieldActive) { stroke(100,200,255,180); noFill(); arc(width/2, height - 60, 200, 130, PI, TWO_PI); } if (isruActive) { stroke(255,180,0); noFill(); rect(width/2 + 90, height - 85, 40, 40, 4); } popStyle(); } void drawStoryPopup() { if (showPopup) { pushStyle(); fill(10, 15, 30, 250); stroke(0, 200, 255); strokeWeight(2); rect(width/2 - 220, height/2 - 90, 440, 150, 10); fill(0, 255, 200); textSize(14); text("📡 STORY EVENT: " + activePopupTitle, width/2 - 200, height/2 - 60); fill(255); textSize(11); text(activePopupText, width/2 - 200, height/2 - 30, 400, 80); textSize(10); fill(150, 180, 220); text("[Klicken zum Schließen & Weiter]", width/2 - 90, height/2 + 40); popStyle(); } } void mousePressed() { if (showPopup) { showPopup = false; pauseForWarning = false; // Spiel läuft nach Schließen des Popups weiter return; } if (disasterMode && !hasTLWDefense) { if (tlwEnergy >= 3.0) { tlwEnergy -= 3.0; projectiles.add(new Projectile(shipX, shipY, meteorX, meteorY)); } return; } // Upgrades kaufen if (mouseX > 165 && mouseX < 265 && mouseY > 72 && mouseY < 98) { if (!hasIdleCharger && tlwEnergy >= 50) { tlwEnergy -= 50; hasIdleCharger = true; triggerStory("LAGER-TOOL AKTIVIERT", "Das Idle-Lager sammelt nun eigenständig Vakuum-Energie im Hintergrund."); } } if (mouseX > 275 && mouseX < 365 && mouseY > 72 && mouseY < 98) { if (!coreActive && tlwEnergy >= 70) { tlwEnergy -= 70; coreActive = true; triggerStory("PHASE 1: KERN", "TLW-Kern online."); } } if (mouseX > 375 && mouseX < 465 && mouseY > 72 && mouseY < 98) { if (!shieldActive && tlwEnergy >= 90) { tlwEnergy -= 90; shieldActive = true; triggerStory("PHASE 2: SCHILD", "Magnetischer Deflektor-Schild aufgebaut."); } } if (mouseX > 475 && mouseX < 565 && mouseY > 72 && mouseY < 98) { if (!isruActive && tlwEnergy >= 110) { tlwEnergy -= 110; isruActive = true; triggerStory("PHASE 3: ISRU", "Terraforming-Fabrik aktiv. Der Mars stabilisiert sich."); } } if (mouseX > 575 && mouseX < 690 && mouseY > 72 && mouseY < 98) { if (!hasTLWDefense && tlwEnergy >= 80) { tlwEnergy -= 80; hasTLWDefense = true; triggerStory("ABWEHR-SYSTEM BEREIT", "Automatische TLW-Zielerfassung installiert. Eingehende Bedrohungen werden ab sofort neutralisiert!"); } } } void triggerStory(String title, String txt) { activePopupTitle = title; activePopupText = txt; showPopup = true; pauseForWarning = true; // Pausiert das Spiel automatisch bei jedem Story-Popup } class FieldCell { float baseX, baseY; FieldCell(float x, float y) { baseX = x; baseY = y; } void updateAndDisplay(float sx, float sy, float mx, float my) { float x = baseX; float y = baseY; float dShip = dist(x, y, sx, sy); if (dShip < 120) { float angle = atan2(y - sy, x - sx); x += cos(angle) * (120 - dShip) * 0.15; y += sin(angle) * (120 - dShip) * 0.15; } if (disasterMode) { float dMeteor = dist(x, y, mx, my); if (dMeteor < 180) { float angleM = atan2(my - y, mx - x); x -= cos(angleM) * (180 - dMeteor) * 0.2; y -= sin(angleM) * (180 - dMeteor) * 0.2; } } stroke(30, 65, 120, 60); point(x, y); if (baseX < width - 60 && baseY < height - 160) { stroke(35, 60, 110, 40); line(baseX, baseY, x, y); } } } class TLWToken { float x, y; TLWToken(float px, float py) { x = px; y = py; } void display() { pushStyle(); noStroke(); fill(0, 255, 220, 210); ellipse(x, y, 12, 12); fill(255); ellipse(x, y, 5, 5); popStyle(); } } class Projectile { float x, y, vx, vy; Projectile(float startX, float startY, float targetX, float targetY) { x = startX; y = startY; float angle = atan2(targetY - startY, targetX - startX); float speed = 12.0; vx = cos(angle) * speed; vy = sin(angle) * speed; } void update() { x += vx; y += vy; } void display() { pushStyle(); noStroke(); fill(255, 100, 255); ellipse(x, y, 8, 16); fill(255); ellipse(x, y, 4, 10); popStyle(); } boolean isOffScreen() { return x < 0 || x > width || y < 0 || y > height; } } class Particle { float x, y, vx, vy, alpha; color col; Particle(float px, float py, float dirX, float dirY, color c) { x = px; y = py; vx = dirX + random(-0.5, 0.5); vy = dirY + random(-0.5, 0.5); alpha = 255; col = c; } void update() { x += vx; y += vy; alpha -= 15; } void display() { pushStyle(); noStroke(); fill(col, alpha); ellipse(x, y, 5, 5); popStyle(); } boolean isDead() { return alpha <= 0; } }