Skip to content

Commit

Permalink
Fixed some World Generation Themes
Browse files Browse the repository at this point in the history
Changes:
* Fixed some world generation themes (Desert, Tundra and Hell), the others are still temporarily broken :(.
* Added support for the Standard Galactic Alphabet.
* The book "AlAzif" was renamed "Grimoire", its sprite was updated, and now its content is a poem written in the Standard Galactic Alphabet.
* Ambient sounds, such as those produced by mobs, are now played non-asynchronously, to avoid over-saturation.
* Beds now display a message directly instead of showing how much time is left before you can sleep.
* The Assembler was completely removed.
* Now the Air Wizard flashes a certain color when it is preparing an attack, and when it is in an advanced phase (as happened in very old versions of Minicraft Plus)
* Completely removed the other types of Bossbars and the other types of death messages to avoid too many redundancies in the code.
* The player's swimming animation is now slower when swimming in Lava.
* The burn mechanic has been temporarily removed and will be rewritten in a better way.
* Heart particles were removed.
* The blindness potion was removed, but not the effect completely :).
* Removed vertical sync option.
* Updated Splashes.json and some translations.
* Particles are now no longer loaded when loading a world, this should avoid the small lag spike that occurs when starting the world.

Bug fixes:
- Fixed the Air Wizard sprite changing when it changes phase
- Fixed a bug in the video options that asked to restart even if nothing had been changed
  • Loading branch information
TheBigEye committed Apr 29, 2024
1 parent fd59a82 commit 2ce86f5
Show file tree
Hide file tree
Showing 76 changed files with 898 additions and 920 deletions.
3 changes: 2 additions & 1 deletion src/main/java/minicraft/core/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jetbrains.annotations.Nullable;
import org.tinylog.Logger;

import minicraft.core.io.CrashHandler;
import minicraft.core.io.FileHandler;
import minicraft.core.io.InputHandler;
import minicraft.core.io.Settings;
Expand Down Expand Up @@ -183,7 +184,7 @@ public static void main(String[] args) {
}

Renderer.canvas.setVisible(false);
Initializer.frame.add(new CrashReport(crashString));
Initializer.frame.add(new CrashHandler(crashString));
Initializer.frame.pack();
Initializer.frame.setVisible(true);
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/minicraft/core/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private Initializer() {}
/**
* Reference to actual frame, also it may be null.
*/
static JFrame frame;
public static JFrame frame;
static LogoSplashCanvas logoSplash = new LogoSplashCanvas();

// These store the number of frames and ticks in the previous second, used for fps, at least.
Expand Down
28 changes: 13 additions & 15 deletions src/main/java/minicraft/core/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.tinylog.Logger;

import minicraft.core.io.Settings;
import minicraft.core.io.Localization;
import minicraft.entity.Entity;
import minicraft.entity.furniture.Bed;
import minicraft.entity.mob.AirWizard;
Expand Down Expand Up @@ -210,7 +210,6 @@ private static void renderLevel() {
}
}

// for earthquakes
level.renderBackground(screen, xScroll, yScroll); // Renders current level background
level.renderSprites(screen, xScroll, yScroll); // Renders level sprites on screen

Expand Down Expand Up @@ -239,10 +238,8 @@ private static void renderLevel() {
// Brightens all
int brightnessMultiplier = player.potionEffects.containsKey(PotionType.Light) ? 12 : 8;
level.renderLight(lightScreen, xScroll, yScroll, brightnessMultiplier); // Finds (and renders) all the light from objects (like the player, lanterns, and lava).
screen.darkness(lightScreen, currentLevel, xScroll, yScroll);

screen.darkness(lightScreen, currentLevel, xScroll, yScroll);
}

}

/**
Expand Down Expand Up @@ -289,11 +286,11 @@ private static void renderGui() {
ArrayList<String> permStatus = new ArrayList<>();

if (Updater.saving) {
permStatus.add("Saving... " + Math.round(LoadingDisplay.getPercentage()) + "%");
permStatus.add(Localization.getLocalized("Saving") + " " + Math.round(LoadingDisplay.getPercentage()) + "%");
}

if (Bed.sleeping()) {
permStatus.add("Sleeping" + ellipsis.updateAndGet());
permStatus.add(Localization.getLocalized("Sleeping") + ellipsis.updateAndGet());
}

if (!permStatus.isEmpty()) {
Expand Down Expand Up @@ -469,7 +466,7 @@ private static void renderGui() {
}

// Render the bosses health bar on screen
if (!player.isRemoved() && Settings.get("bossbar").equals("On screen")) {
if (!player.isRemoved()) {
// Check if are a boss close to the player in the current level
List<Entity> entitiesInRange = Game.levels[Game.currentLevel].getEntitiesInRect(new Rectangle(player.x, player.y, 360 << 1, 360 << 1, Rectangle.CENTER_DIMS));

Expand Down Expand Up @@ -547,23 +544,24 @@ private static void renderDebugInfo() {
info.add("Base: " + "Minicraft Plus Legacy"); subinfo.add("J: " + Utils.JAVA_VERSION + " x" + Utils.JAVA_ARCH);
info.add("" + TimeData.date()); subinfo.add(Utils.getGeneralMemoryUsage());
info.add(Initializer.fra + " fps" ); subinfo.add(Utils.getMemoryAllocation());
info.add("Day tiks: " + Updater.tickCount + " (" + Updater.getTime() + ")");
info.add("Day tiks: " + Updater.tickCount + " (" + Updater.getTime() + ")"); subinfo.add("");
info.add((Updater.normalSpeed * Updater.gameSpeed) + " tps");

// player info
info.add("Walk spd: " + player.moveSpeed);
info.add("X: " + (player.x >> 4) + "." + (player.x % 16));
info.add("Y: " + (player.y >> 4) + "." + (player.y % 16));
info.add("");

info.add("Walk spd: " + player.moveSpeed); subinfo.add("AW beaten: " + AirWizard.beaten);
info.add("X: " + (player.x >> 4) + "." + (player.x % 16)); subinfo.add("AW active: " + EyeQueen.active);
info.add("Y: " + (player.y >> 4) + "." + (player.y % 16)); subinfo.add("");
info.add(""); subinfo.add("EQ beaten: " + AirWizard.beaten);
subinfo.add("EQ active: " + AirWizard.active);
info.add("Tile: " + levels[currentLevel].getTile(player.x >> 4, player.y >> 4).name);
info.add("Id: " + levels[currentLevel].getTile(player.x >> 4, player.y >> 4).id);
info.add("ID: " + levels[currentLevel].getTile(player.x >> 4, player.y >> 4).id);
info.add("Data: " + levels[currentLevel].getData(player.x >> 4, player.y >> 4));
info.add("Depth: " + levels[currentLevel].depth + " (" + levels[currentLevel].w +"x" + levels[currentLevel].h +")");
info.add("");

if (isMode("score")) {
info.add("Score " + player.getScore());
info.add("");
}

if (levels[currentLevel] != null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/minicraft/core/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import minicraft.screen.PlayerDeathDisplay;
import minicraft.screen.WorldGenDisplay;
import minicraft.screen.WorldSelectDisplay;
import minicraft.util.Action;

public class World extends Game {
private World() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,84 +1,89 @@
package minicraft.core;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class CrashReport extends JPanel {
private static final long serialVersionUID = 1L;

private JTextArea crashTextArea;
private JScrollPane crashScrollPane;
private JLabel crashIconLabel;

// TODO: Add a crash log save, save all into a txt file

public CrashReport(String crash) {
// Crash log Structure
crashTextArea = new JTextArea(5, 5);
crashIconLabel = new JLabel();

Image icon = null;
try (
InputStream is = Game.class.getResourceAsStream("/resources/title.png")) {
BufferedImage titleIcon = ImageIO.read(is);
icon = titleIcon.getScaledInstance(258 + 16, 60 + 8, Image.SCALE_REPLICATE);
crashIconLabel.setIcon(new ImageIcon(icon));
} catch (IOException exception) {
exception.printStackTrace();
}

crashTextArea.setForeground(Color.BLACK);
crashTextArea.setBackground(Color.WHITE);

// Crash message
crashTextArea.setText(crash);
crashTextArea.setEditable(false);
crashTextArea.setFont(new Font("Consolas", Font.PLAIN, 12));

// All white, is better
UIManager.put("OptionPane.background", Color.white);
UIManager.put("Panel.background", Color.white);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException exception) {
exception.printStackTrace();
}

// Adjust size and set layout
setPreferredSize(new Dimension(Renderer.getWindowSize()));
setLayout(null);

// Add components to parent widget
crashScrollPane = new JScrollPane(crashTextArea);
crashTextArea.select(0, 0); // Reset the scroll bars position
add(crashScrollPane);
add(crashIconLabel);

// Set component bounds (only needed by absolute positioning)
crashScrollPane.setBounds(69, 100, 732, 380);
crashIconLabel.setBounds((Renderer.getWindowSize().width / 2) - (icon.getWidth(Initializer.frame) / 2), 25, 258 + 16, 60 + 8);
setBackground(new Color(46, 53, 69));
}

/**
* Manually launched crash!
*/
public static void crashMePlease() {
throw new NullPointerException("Manually initiated crash! :D");
}

}
package minicraft.core.io;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import minicraft.core.Game;
import minicraft.core.Initializer;
import minicraft.core.Renderer;

public class CrashHandler extends JPanel {
private static final long serialVersionUID = 1L;

private JTextArea crashTextArea;
private JScrollPane crashScrollPane;
private JLabel crashIconLabel;

// TODO: Add a crash log save, save all into a txt file

public CrashHandler(String crash) {
// Crash log Structure
crashTextArea = new JTextArea(5, 5);
crashIconLabel = new JLabel();

Image icon = null;

try (
InputStream is = Game.class.getResourceAsStream("/resources/title.png")) {
BufferedImage titleIcon = ImageIO.read(is);
icon = titleIcon.getScaledInstance(258 + 16, 60 + 8, Image.SCALE_REPLICATE);
crashIconLabel.setIcon(new ImageIcon(icon));
} catch (IOException exception) {
exception.printStackTrace();
}

crashTextArea.setForeground(Color.BLACK);
crashTextArea.setBackground(Color.WHITE);

// Crash message
crashTextArea.setText(crash);
crashTextArea.setEditable(false);
crashTextArea.setFont(new Font("Consolas", Font.PLAIN, 12));

// All white, is better
UIManager.put("OptionPane.background", Color.white);
UIManager.put("Panel.background", Color.white);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException exception) {
exception.printStackTrace();
}

// Adjust size and set layout
setPreferredSize(new Dimension(Renderer.getWindowSize()));
setLayout(null);

// Add components to parent widget
crashScrollPane = new JScrollPane(crashTextArea);
crashTextArea.select(0, 0); // Reset the scroll bars position
add(crashScrollPane);
add(crashIconLabel);

// Set component bounds (only needed by absolute positioning)
crashScrollPane.setBounds(69, 100, 732, 380);
crashIconLabel.setBounds((Renderer.getWindowSize().width / 2) - (icon.getWidth(Initializer.frame) / 2), 25, 258 + 16, 60 + 8);
setBackground(new Color(46, 53, 69));
}

/**
* Manually launched crash!
*/
public static void crashMePlease() {
throw new NullPointerException("Manually initiated crash! :D");
}

}
13 changes: 1 addition & 12 deletions src/main/java/minicraft/core/io/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ public class Settings {
options.put("sound", new BooleanEntry("Sound", true));
options.put("autosave", new BooleanEntry("Autosave", true));

options.put("ambient", new ArrayEntry<>("Ambient", "Nice", "Normal", "Scary"));

options.put("cheats", new BooleanEntry("Cheats", true));

options.put("size", new ArrayEntry<>("World Size", 256, 512));
options.get("size").setSelection(0);

options.put("theme", new ArrayEntry<>("World Theme", "Normal", "Forest", "Desert", "Plain", "Hell", "Snow"));
options.put("theme", new ArrayEntry<>("World Theme", "Normal", "Forest", "Desert", "Plain", "Tundra", "Hell"));
options.put("type", new ArrayEntry<>("Terrain Type", "Island", "Box", "Mountain", "Irregular"));

options.put("unlockedskin", new BooleanEntry("Wear Suit", false));
Expand All @@ -56,20 +54,11 @@ public class Settings {
Game.player.suitOn = (boolean) value;
}
});

options.put("textures", new ArrayEntry<>("Textures", "Original", "Custom"));
options.get("textures").setSelection(0);

// Video options
options.put("fps", new RangeEntry("Max FPS", 30, 300, getRefreshRate()));
options.put("vsync", new BooleanEntry("V.Sync", false));

options.put("bossbar", new ArrayEntry<>("Bossbar type", "On screen", "On entity", "Percent"));
options.get("bossbar").setSelection(0);

options.put("particles", new BooleanEntry("Particles", true));
options.put("shadows", new BooleanEntry("Shadows", true));

}

public static void initialize() {
Expand Down
37 changes: 23 additions & 14 deletions src/main/java/minicraft/core/io/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ public static void play(String key) {
public static void playAt(String key, int x, int y) {
Sound sound = sounds.get(key);
// Logger.debug("Playing sound clip '{}', at ({}, {}) ...", key, x, y);
if (sound != null) sound.playAt(x, y);
if (sound != null) sound.playAt(x, y, true);
}

public static void playAt(String key, int x, int y, boolean async) {
Sound sound = sounds.get(key);
// Logger.debug("Playing sound clip '{}', at ({}, {}) ...", key, x, y);
if (sound != null) sound.playAt(x, y, async);
}

public static void loop(String key, boolean start) {
Expand All @@ -179,7 +185,7 @@ public static void stop(String key) {
if (sound != null) al.alSourceStop(sound.source);
}

private void playAt(int x, int y) {
private void playAt(int x, int y, boolean async) {
if (!Settings.getBoolean("sound")) {
return;
}
Expand All @@ -189,22 +195,26 @@ private void playAt(int x, int y) {
if (player == null) {
return;
}

if (!async) {
int[] state = new int[1];
al.alGetSourcei(source, AL.AL_SOURCE_STATE, state, 0);
if (state[0] != AL.AL_PLAYING) {
al.alSourcePlay(source);
}
} else {
al.alSourcePlay(source);
}

// Play the source without setting the volume
al.alSourcePlay(source);

// Calculate the distance between the sound source and the player
double distance = Math.sqrt(Math.pow(x - player.x, 2) + Math.pow(y - player.y, 2));

// TODO: improve this using an thread to dynamically change the 'Sound Gain' while the player moves

// Set the volume based on the distance from the player
float volume = 1.0f - (float) distance / 180.0f;
if (volume < 0.0f) {
return;
float volume = 1.0f - ((float) distance / 175.0f);

if (volume <= 0.0f) {
return;
}

// Set the source volume

al.alSourcef(source, AL.AL_GAIN, volume);
}

Expand All @@ -216,7 +226,6 @@ private void play() {
al.alSourcePlay(source);
}


private void loop(boolean start) {
if (!Settings.getBoolean("sound")) {
return;
Expand Down
Loading

0 comments on commit 2ce86f5

Please sign in to comment.