import processing.awt.PSurfaceAWT;
import processing.awt.PSurfaceAWT.SmoothCanvas;
import javax.swing.JFrame;
BlackHole blackHole;
ArrayList<Star> objects;
MovableResizableWindow consoleWindow;
MovableResizableHUDWindow hudWindow;
PFont gameFont; // Font for the game HUD
PFont consoleFont; // Font for the console window
int points = 0;
int blackHoleMass = 1;
int gravityPull = 1; // Renamed from gravityBoost
int starSpeedDisplay = 1; // Initial display value for star speed
int starMultiplier = 1; // Initial value for star multiplier
int rainbowMultiplier = 1; // Initial value for rainbow star multiplier
int pointsMultiplier = 1; // Initial points multiplier value
color backgroundColor;
color textColor;
static float starSpeed = 0.25; // Initial slow speed of stars
static float spawnMultiplier = 1.0; // Global spawn multiplier
float starSpawnInterval = 60; // Base spawn interval for regular stars
float rainbowStarSpawnInterval; // Interval for spawning rainbow stars
final int INITIAL_BLACK_HOLE_SIZE = 50; // Initial size for the black hole
boolean pullAreaVisible = false; // Variable to track pull area visibility
boolean delayVisible = false; // Variable to track the visibility of spawn rate info
// Base values and scaling factors for the growth curve
int baseBlackHoleMass = 1;
int baseGravityPull = 1;
int baseStarSpeedDisplay = 1;
int baseStarMultiplier = 1;
// Maximum values
final int MAX_STAR_MULTIPLIER = 73500;
final int MAX_STAR_SPEED = 73500;
final int MAX_GRAVITY_PULL = 5400000;
final int MAX_BLACK_HOLE_MASS = 2850;
final int MAX_POINTS = 9999999;
final int MAX_RAINBOW_MULTIPLIER = MAX_STAR_MULTIPLIER; // Same max value for consistency
float kGrowth = 0.15; // Unified constant for balanced growth
float kGravityPull = 0.20; // Slightly higher growth rate for gravity pull
float kStarSpeed = 0.20; // Slightly higher growth rate for star speed
float kStarMultiplier = 0.20; // Slightly higher growth rate for star multiplier
int lastRainbowStarFrame = 0; // Frame count of the last rainbow star spawn
// New variables for screen management
String screenMode = "windowed";
boolean toggleFullscreen = false;
int targetWidth = 1920;
int targetHeight = 1080;
void settings() {
fullScreen();
}
void setup() {
backgroundColor = color(214, 255, 235); // #d6ffeb color
textColor = color(101, 228, 167); // #65e4a7 color
gameFont = createFont("PaladinsStraight.otf", 32); // Font size for the game HUD
consoleFont = createFont("CascadiaMonoPL-Regular.otf", 16); // Font size for the console window
textFont(gameFont);
blackHole = new BlackHole(width / 2, height / 2, INITIAL_BLACK_HOLE_SIZE); // Initial size set
objects = new ArrayList<Star>();
consoleWindow = new MovableResizableWindow(100, 100, 800, 300, consoleFont, this); // Pass the console font and the current instance to the window
hudWindow = new MovableResizableHUDWindow(100, 450, 400, 300, consoleFont, this); // HUD window for displaying game information
// Set the initial rainbow star spawn interval
rainbowStarSpawnInterval = starSpawnInterval * 50; // 50 times less frequent than regular stars
}
void draw() {
if (toggleFullscreen) {
toggleFullscreen = false;
if (screenMode.equals("fullscreen")) {
surface.setResizable(true);
surface.setSize(displayWidth, displayHeight);
surface.setLocation(0, 0);
surface.setAlwaysOnTop(true);
surface.setAlwaysOnTop(false);
surface.setVisible(false);
surface.setVisible(true);
} else if (screenMode.equals("windowedfullscreen")) {
surface.setResizable(true);
surface.setSize(displayWidth, displayHeight);
surface.setLocation(0, 0);
surface.setAlwaysOnTop(true);
surface.setAlwaysOnTop(false);
surface.setVisible(false);
surface.setVisible(true);
} else if (screenMode.equals("windowed")) {
surface.setResizable(true);
surface.setSize(targetWidth, targetHeight);
surface.setLocation((displayWidth - targetWidth) / 2, (displayHeight - targetHeight) / 2);
surface.setAlwaysOnTop(false);
surface.setVisible(false);
surface.setVisible(true);
restoreWindowedMode(); // Restore window decorations
}
}
background(backgroundColor);
// Game logic for normal stars
if (frameCount % int(starSpawnInterval / spawnMultiplier) == 0) {
objects.add(new StarMeteor(width, random(height), 15)); // Fixed star size
}
// Rainbow star spawning logic
if (frameCount - lastRainbowStarFrame >= rainbowStarSpawnInterval) {
objects.add(new RainbowStar(width, random(height), 15)); // Fixed rainbow star size
lastRainbowStarFrame = frameCount; // Update the last spawn frame
}
blackHole.update();
blackHole.display();
if (pullAreaVisible) {
drawPullArea();
drawSpiralPath(); // Add the spiral path visualization
}
// Process all stars, including removal of marked ones
for (int i = objects.size() - 1; i >= 0; i--) {
Star obj = objects.get(i);
if (obj.markForRemoval) {
println("Removing star at frame: " + frameCount);
objects.remove(i); // Remove the star if marked for removal
continue; // Skip the rest of the loop for this object
}
obj.move();
obj.display();
blackHole.applyGravity(obj); // Apply gravity pull effect
if (blackHole.absorb(obj)) {
if (obj instanceof RainbowStar) {
points = min(points + 100, MAX_POINTS); // Each rainbow star gives 100 points
} else {
points = min(points + 1, MAX_POINTS); // Each star gives exactly 1 point
}
objects.remove(i); // Remove absorbed stars
}
}
if (delayVisible) {
displaySpawnRates(); // Display spawn rate information
}
// Display the movable resizable HUD window
hudWindow.display();
// Display the movable resizable window
consoleWindow.display();
}
void restoreWindowedMode() {
PSurfaceAWT awtSurface = (PSurfaceAWT) surface;
SmoothCanvas smoothCanvas = (SmoothCanvas) awtSurface.getNative();
JFrame frame = (JFrame) smoothCanvas.getFrame();
frame.dispose();
frame.setUndecorated(false);
frame.setResizable(true);
frame.setSize(targetWidth, targetHeight);
frame.setLocation((displayWidth - targetWidth) / 2, (displayHeight - targetHeight) / 2);
frame.setVisible(true);
}
void drawPullArea() {
int numDivisions = 10; // Number of divisions for the pull strength
float maxPullStrength = 5.0; // Maximum pull strength at the center
float minPullStrength = 0.1; // Minimum pull strength at the edge
// Set the font to the console font for consistency
textFont(consoleFont);
textSize(10); // Smaller text size for the numbers
for (int i = 0; i <= numDivisions; i++) {
float strength = map(i, 0, numDivisions, maxPullStrength, minPullStrength);
float radius = map(i, 0, numDivisions, 0, blackHole.gravityPullRadius);
noFill();
stroke(50, 50, 50, 150); // Dark grey with low opacity for the circles
ellipse(blackHole.x, blackHole.y, radius * 2, radius * 2);
// Calculate position for the text in a spiral
float angle = PI / 4 * i; // Adjust the angle increment as needed for spiral effect
float textX = blackHole.x + cos(angle) * radius;
float textY = blackHole.y + sin(angle) * radius;
fill(0); // Black color for text
textAlign(CENTER, CENTER);
text(nf(strength, 1, 1), textX, textY); // Display the strength value in the spiral path
}
}
void drawSpiralPath() {
stroke(255, 0, 0, 150); // Red color with low opacity for the spiral
noFill();
beginShape();
float angle = 0;
float radius = 0;
while (radius < blackHole.gravityPullRadius) {
float x = blackHole.x + cos(angle) * radius;
float y = blackHole.y + sin(angle) * radius;
vertex(x, y);
angle += 0.1;
radius += 0.5;
}
endShape();
}
void displaySpawnRates() {
fill(textColor);
textFont(consoleFont);
textSize(20);
textAlign(LEFT, TOP);
text("Normal Stars Spawn Rate: " + (starSpawnInterval / spawnMultiplier), 20, 20);
text("Rainbow Stars Spawn Rate: " + rainbowStarSpawnInterval, 20, 50);
}
void mousePressed() {
println("Mouse Pressed at: " + mouseX + ", " + mouseY);
// Handle click on "+"" icon for speed
if (hudWindow.mouseOverSpeedIconPlus()) {
println("Speed Icon Plus Clicked");
if (points > 0 && starSpeedDisplay < MAX_STAR_SPEED) {
points -= pointsMultiplier;
hudWindow.updateStarSpeed(starSpeedDisplay + pointsMultiplier);
} else {
println("Star speed is at maximum value.");
}
}
// Handle click on "+"" icon for gravity
if (hudWindow.mouseOverGravityIconPlus()) {
println("Gravity Icon Plus Clicked");
if (points > 0 && gravityPull < MAX_GRAVITY_PULL) {
points -= pointsMultiplier;
hudWindow.updateGravityPull(gravityPull + pointsMultiplier);
} else {
println("Gravity pull is at maximum value.");
}
}
// Handle click on "+"" icon for black hole mass
if (hudWindow.mouseOverBlackHoleMassIconPlus()) {
println("Black Hole Mass Icon Plus Clicked");
if (points > 0 && blackHoleMass < MAX_BLACK_HOLE_MASS) {
points -= pointsMultiplier;
hudWindow.updateBlackHoleMass(blackHoleMass + pointsMultiplier);
} else {
println("Black hole mass is at maximum value.");
}
}
// Handle click on "+"" icon for stars multiplier
if (hudWindow.mouseOverStarMultiplierIconPlus()) {
println("Star Multiplier Icon Plus Clicked");
if (points > 0 && starMultiplier < MAX_STAR_MULTIPLIER) {
points -= pointsMultiplier;
hudWindow.updateStarMultiplier(starMultiplier + pointsMultiplier);
} else {
println("Star multiplier is at maximum value.");
}
}
// Handle click on "+"" icon for rainbow multiplier
if (hudWindow.mouseOverRainbowMultiplierIconPlus()) {
println("Rainbow Multiplier Icon Plus Clicked");
if (points > 0 && rainbowMultiplier < MAX_RAINBOW_MULTIPLIER) {
points -= pointsMultiplier;
hudWindow.updateRainbowMultiplier(rainbowMultiplier + pointsMultiplier);
} else {
println("Rainbow multiplier is at maximum value.");
}
}
// Handle click on the points multiplier text
if (hudWindow.mouseOverPointsMultiplier()) {
println("Points Multiplier Text Clicked");
togglePointsMultiplier();
}
// Handle click on the minimize button
if (hudWindow.overMinimizeButton(mouseX, mouseY)) {
hudWindow.toggleMinimize();
}
if (consoleWindow.visible) {
if (consoleWindow.overTitleBar(mouseX, mouseY)) {
consoleWindow.startDragging(mouseX, mouseY);
} else if (consoleWindow.overResizeArea(mouseX, mouseY)) {
consoleWindow.startResizing(mouseX, mouseY);
} else {
// Handle console window specific mousePressed events
consoleWindow.handleMousePressed();
}
} else if (hudWindow.overWindow(mouseX, mouseY)) {
hudWindow.startDragging(mouseX, mouseY);
} else {
checkHUDClicks();
}
}
void mouseDragged() {
if (consoleWindow.dragging || consoleWindow.resizing) {
consoleWindow.update(mouseX, mouseY);
} else if (consoleWindow.visible) {
// Handle console window specific mouseDragged events
consoleWindow.handleMouseDragged();
} else if (hudWindow.dragging || hudWindow.resizing) {
hudWindow.update(mouseX, mouseY);
}
}
void mouseReleased() {
if (consoleWindow.dragging || consoleWindow.resizing) {
consoleWindow.stopDragging();
consoleWindow.stopResizing();
}
if (hudWindow.dragging || hudWindow.resizing) {
hudWindow.stopDragging();
hudWindow.stopResizing();
}
if (consoleWindow.visible) {
// Handle console window specific mouseReleased events
consoleWindow.handleMouseReleased();
}
}
void mouseWheel(MouseEvent event) {
if (consoleWindow.visible && consoleWindow.overWindow(mouseX, mouseY)) {
consoleWindow.mouseWheel(event);
}
}
void keyPressed() {
if (key == CODED && keyCode == 155) { // Key code for the "Insert" key
consoleWindow.toggleVisibility(); // Toggle console window visibility
} else if (consoleWindow.visible) {
consoleWindow.handleKeyPressed();
}
}
void checkHUDClicks() {
float plusSize = textWidth("+");
int baseY = height - 250;
// Check if click is on the + for Black Hole Mass
if (mouseY > baseY + 40 - gameFont.getSize() && mouseY < baseY + 40) {
if (mouseX > width / 2 - textWidth("Black Hole Mass: " + blackHoleMass) / 2 - plusSize && mouseX < width / 2 - textWidth("Black Hole Mass: " + blackHoleMass) / 2) {
if (points > 0 && blackHoleMass < MAX_BLACK_HOLE_MASS) {
points -= pointsMultiplier;
updateBlackHoleMass(blackHoleMass + pointsMultiplier);
} else {
println("Black hole mass is at maximum value.");
}
}
}
// Check if click is on the + for Gravity Pull
if (mouseY > baseY + 80 - gameFont.getSize() && mouseY < baseY + 80) {
if (mouseX > width / 2 - textWidth("Gravity Pull: " + gravityPull) / 2 - plusSize && mouseX < width / 2 - textWidth("Gravity Pull: " + gravityPull) / 2) {
if (points > 0 && gravityPull < MAX_GRAVITY_PULL) {
points -= pointsMultiplier;
updateGravityPull(gravityPull + pointsMultiplier);
} else {
println("Gravity pull is at maximum value.");
}
}
}
// Check if click is on the + for Stars Speed
if (mouseY > baseY + 120 - gameFont.getSize() && mouseY < baseY + 120) {
if (mouseX > width / 2 - textWidth("Stars Speed: " + starSpeedDisplay) / 2 - plusSize && mouseX < width / 2 - textWidth("Stars Speed: " + starSpeedDisplay) / 2) {
if (points > 0 && starSpeedDisplay < MAX_STAR_SPEED) {
points -= pointsMultiplier;
updateStarSpeed(starSpeedDisplay + pointsMultiplier);
} else {
println("Star speed is at maximum value.");
}
}
}
// Check if click is on the + for Stars Multiplier
if (mouseY > baseY + 160 - gameFont.getSize() && mouseY < baseY + 160) {
if (mouseX > width / 2 - textWidth("Stars Multiplier: " + starMultiplier) / 2 - plusSize && mouseX < width / 2 - textWidth("Stars Multiplier: " + starMultiplier) / 2) {
if (points > 0 && starMultiplier < MAX_STAR_MULTIPLIER) {
points -= pointsMultiplier;
updateStarMultiplier(starMultiplier + pointsMultiplier);
} else {
println("Star multiplier is at maximum value.");
}
}
}
}
void setPoints(int newPoints) {
if (newPoints > MAX_POINTS) {
newPoints = MAX_POINTS;
consoleWindow.consoleText.add("The MAX Value Can Only Be: " + MAX_POINTS);
}
points = min(newPoints, MAX_POINTS);
}
void setGravityPull(int newGravityPull) {
updateGravityPull(newGravityPull);
consoleWindow.consoleText.add("Gravity pull set to: " + gravityPull);
}
void setBlackHoleMass(int mass) {
updateBlackHoleMass(mass);
}
void setStarMultiplier(int multiplier) {
updateStarMultiplier(multiplier);
consoleWindow.consoleText.add("Stars multiplier set to: " + starMultiplier);
}
void setRainbowMultiplier(int multiplier) {
updateRainbowMultiplier(multiplier);
consoleWindow.consoleText.add("Rainbow multiplier set to: " + rainbowMultiplier);
}
void setDelayVisible(boolean visibility) {
delayVisible = visibility;
consoleWindow.consoleText.add("Delay visibility set to: " + (visibility ? "on" : "off"));
}
float calculateBalancedGrowth(int baseValue, float k, int pointsSpent) {
return baseValue * pow(1 + k, log(pointsSpent + 1) * 2);
}
void updateBlackHoleMass(int mass) {
if (mass > MAX_BLACK_HOLE_MASS) {
mass = MAX_BLACK_HOLE_MASS;
consoleWindow.consoleText.add("The MAX Value Can Only Be: " + MAX_BLACK_HOLE_MASS);
}
blackHoleMass = min(max(1, mass), MAX_BLACK_HOLE_MASS);
float newSize = max(INITIAL_BLACK_HOLE_SIZE, calculateBalancedGrowth(INITIAL_BLACK_HOLE_SIZE, kGrowth, blackHoleMass));
blackHole.setSize(newSize);
println("Black hole mass updated: " + blackHoleMass + ", New size: " + newSize);
}
void updateGravityPull(int pull) {
if (pull > MAX_GRAVITY_PULL) {
pull = MAX_GRAVITY_PULL;
consoleWindow.consoleText.add("The MAX Value Can Only Be: " + MAX_GRAVITY_PULL);
}
gravityPull = min(max(1, pull), MAX_GRAVITY_PULL); // Assuming the minimum pull value is 1
blackHole.setGravityPullRadius(calculateBalancedGrowth(baseGravityPull, kGravityPull, gravityPull));
println("Gravity pull radius updated: " + gravityPull);
}
void updateStarSpeed(int speed) {
if (speed > MAX_STAR_SPEED) {
speed = MAX_STAR_SPEED;
consoleWindow.consoleText.add("The MAX Value Can Only Be: " + MAX_STAR_SPEED);
}
starSpeedDisplay = min(max(1, speed), MAX_STAR_SPEED); // Ensure the speed display doesn’t go below 1
BlackHoleFrenzy.starSpeed = calculateBalancedGrowth(baseStarSpeedDisplay, kStarSpeed, starSpeedDisplay) * 0.1;
println("Star speed updated: " + starSpeedDisplay);
}
void updateStarMultiplier(int multiplier) {
if (multiplier > MAX_STAR_MULTIPLIER) {
multiplier = MAX_STAR_MULTIPLIER;
consoleWindow.consoleText.add("The MAX Value Can Only Be: " + MAX_STAR_MULTIPLIER);
}
starMultiplier = min(max(1, multiplier), MAX_STAR_MULTIPLIER); // Ensure the multiplier doesn’t go below 1
BlackHoleFrenzy.spawnMultiplier = calculateBalancedGrowth(baseStarMultiplier, kStarMultiplier, starMultiplier);
println("Star multiplier updated: " + starMultiplier);
}
void updateRainbowMultiplier(int multiplier) {
if (multiplier > MAX_RAINBOW_MULTIPLIER) {
multiplier = MAX_RAINBOW_MULTIPLIER;
consoleWindow.consoleText.add("The MAX Value Can Only Be: " + MAX_RAINBOW_MULTIPLIER);
}
rainbowMultiplier = min(max(1, multiplier), MAX_RAINBOW_MULTIPLIER); // Ensure the multiplier doesn’t go below 1
rainbowStarSpawnInterval = starSpawnInterval * (50 / (1 + log(rainbowMultiplier) * 0.1)); // Adjust spawn interval based on multiplier
println("Rainbow multiplier updated: " + rainbowMultiplier);
}
void togglePointsMultiplier() {
switch (pointsMultiplier) {
case 1:
pointsMultiplier = 10;
break;
case 10:
pointsMultiplier = 100;
break;
case 100:
pointsMultiplier = 1000;
break;
case 1000:
pointsMultiplier = 10000;
break;
case 10000:
pointsMultiplier = MAX_POINTS;
break;
default:
pointsMultiplier = 1;
}
}
String getPointsMultiplierText() {
if (pointsMultiplier == MAX_POINTS) {
return "MAX";
}
return pointsMultiplier + "X";
}
// New console commands
void setResolution(String resolution) {
String[] dims = split(resolution, 'x');
if (dims.length == 2) {
int w = int(trim(dims[0]));
int h = int(trim(dims[1]));
if (w > 0 && h > 0) {
targetWidth = w;
targetHeight = h;
size(targetWidth, targetHeight);
consoleWindow.consoleText.add("Resolution set to: " + w + "x" + h);
} else {
consoleWindow.consoleText.add("Invalid resolution dimensions.");
}
} else {
consoleWindow.consoleText.add("Invalid resolution format. Use WIDTHxHEIGHT (e.g., 1920x1080).");
}
}
void setScreenMode(String mode) {
screenMode = mode.toLowerCase();
toggleFullscreen = true;
if (screenMode.equals("fullscreen")) {
surface.setVisible(false);
fullScreen();
surface.setVisible(true);
} else if (screenMode.equals("windowedfullscreen")) {
surface.setVisible(false);
size(displayWidth, displayHeight, P2D);
surface.setLocation(0, 0);
surface.setVisible(true);
} else if (screenMode.equals("windowed")) {
surface.setVisible(false);
size(targetWidth, targetHeight);
surface.setLocation((displayWidth - targetWidth) / 2, (displayHeight - targetHeight) / 2);
surface.setVisible(true);
restoreWindowedMode(); // Restore window decorations
} else {
consoleWindow.consoleText.add("Invalid screen mode. Use fullscreen, windowedfullscreen, or windowed.");
}
}
That’s my code, for this spesific pde file, i am trying to be able to switch from full screen to windowed without losing the window decorations (the top bar with the X - Minimize icons)
the current problem is that when i use console to switch to from default fullscreen to windowed
the window becomes smaller without the top bar and all that so it’s not really windowed
this is the code related to my console
next comment