diff --git a/.classpath b/.classpath index 3f029df..a21c1f8 100755 --- a/.classpath +++ b/.classpath @@ -41,6 +41,6 @@ - + diff --git a/.gitignore b/.gitignore index fb5a5ff..adb385c 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /bin/ hs_err_pid* -settings.bdf -layer.bdf +*.bdf diff --git a/src/projectzombie/Main.java b/src/projectzombie/Main.java index 3405ca7..f0e2155 100755 --- a/src/projectzombie/Main.java +++ b/src/projectzombie/Main.java @@ -1,5 +1,7 @@ package projectzombie; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; import java.io.IOException; import java.util.Random; @@ -9,14 +11,11 @@ import projectzombie.audio.AudioEngine; import projectzombie.audio.AudioSources; import projectzombie.display.DisplayStatsEventHandler; import projectzombie.display.DisplayWindow; -import projectzombie.display.bossbar.BossBars; import projectzombie.entity.EntityEventHandler; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Entities; import projectzombie.init.Items; import projectzombie.init.LayerGenerators; -import projectzombie.init.Layers; -import projectzombie.init.Models; import projectzombie.init.Resources; import projectzombie.init.Sounds; import projectzombie.init.Tasks; @@ -38,6 +37,7 @@ import projectzombie.world.chunk.ChunkEventHandler; public class Main { + public static Clipboard clipboard; public static MainloopManager mainloop; public static DisplayWindow window; public static EntityPlayer player; @@ -51,56 +51,68 @@ public class Main public static void main(String[] args) throws IOException { - MathHelpers.init(); - Settings.init(); - Environment.init(args); - Cheats.init(args); + try + { + clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + + worker = new Worker(); + worker.start(); + + MathHelpers.init(); + Settings.init(); + Environment.init(args); + Cheats.init(args); + + Items.init(); + Entities.init(); + Tasks.init(); + Tiles.init(); + LayerGenerators.init(); + + // Create the display + window = new DisplayWindow(); + window.init(); + + // Load the resources + Resources.loadResources(); + + // Initialize the sound engine + audio = new AudioEngine(); + audio.init(); + + // Initialise the sounds + AudioSources.init(); + Sounds.init(); + + // Initialize the gamepad + JoystickCallback.JOYSTICK_CALLBACK.init(); + + // Create the mainloop + mainloop = new MainloopManager(MainloopEventHandler.MAINLOOP_EVENT_HANDLER); + mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER); + mainloop.register(MainloopEventHandler.MAINLOOP_EVENT_HANDLER); + mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER); + mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER); + mainloop.register(JoystickCallback.JOYSTICK_CALLBACK); + mainloop.register(new MainloopHelpers()); + mainloop.register(new KeyCallback()); + mainloop.register(new GameTimer()); + mainloop.register(new NoSleep()); + mainloop.register(window); + + // Start the mainloop + menu = new MenuMain(); + mainloop.start(); + } - worker = new Worker(); - worker.start(); + catch(IOException e) { + e.printStackTrace(); + } - Items.init(); - Entities.init(); - Tasks.init(); - Tiles.init(); - LayerGenerators.init(); - - // Create the display - window = new DisplayWindow(); - window.init(); - - // Load the resources - Resources.loadResources(); - - // Initialize the sound engine - audio = new AudioEngine(); - audio.init(); - - // Initialise the sounds - AudioSources.init(); - Sounds.init(); - - // Initialize the gamepad - JoystickCallback.JOYSTICK_CALLBACK.init(); - - // Create the mainloop - mainloop = new MainloopManager(MainloopEventHandler.MAINLOOP_EVENT_HANDLER); - mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER); - mainloop.register(MainloopEventHandler.MAINLOOP_EVENT_HANDLER); - mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER); - mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER); - mainloop.register(JoystickCallback.JOYSTICK_CALLBACK); - mainloop.register(new MainloopHelpers()); - mainloop.register(new KeyCallback()); - mainloop.register(new GameTimer()); - mainloop.register(new NoSleep()); - mainloop.register(window); - - // Start the mainloop - menu = new MenuMain(); - mainloop.start(); - - // Kill the worker thread - worker.kill(); + finally + { + // Kill the worker thread + worker.kill(); + } } } diff --git a/src/projectzombie/display/Camera.java b/src/projectzombie/display/Camera.java index d1b8a76..e148e7a 100755 --- a/src/projectzombie/display/Camera.java +++ b/src/projectzombie/display/Camera.java @@ -3,9 +3,7 @@ package projectzombie.display; import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec3d; import projectzombie.Main; -import projectzombie.time.GameTimer; import projectzombie.world.chunk.Chunk; -import projectzombie.world.layer.Layer; public class Camera { diff --git a/src/projectzombie/display/DisplayLighting.java b/src/projectzombie/display/DisplayLighting.java index e2234fd..d890b4d 100755 --- a/src/projectzombie/display/DisplayLighting.java +++ b/src/projectzombie/display/DisplayLighting.java @@ -26,7 +26,7 @@ public class DisplayLighting int x, y; private int getID(int x, int y) { - return (x + y * w) * 4 + 1; + return (x + y * w) * 3; } } @@ -87,7 +87,7 @@ public class DisplayLighting lighting_dirty = false; int size = (Chunk.RENDER_DISTANCE * 2 + 1) * 16; - float[] lights = new float[size * size * 3]; + float[] lights = new float[size * size * 2]; for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) { for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++) @@ -115,14 +115,11 @@ public class DisplayLighting ft.tile.getLightLevel(ft, tpos), bt.tile.getLightLevel(bt, tpos)); - float lightSun = ft.tile.passNaturalLight && bt.tile.passNaturalLight ? 1 : 0; - int id = ((cx * 16 + x + Chunk.RENDER_DISTANCE * 16) + - (cy * 16 + y + Chunk.RENDER_DISTANCE * 16) * size) * 3; + (cy * 16 + y + Chunk.RENDER_DISTANCE * 16) * size) * 2; - lights[id+0] = lightSun; - lights[id+1] = lightSrc; - lights[id+2] = transparency; + lights[id+0] = lightSrc; + lights[id+1] = transparency; } } } @@ -259,7 +256,7 @@ public class DisplayLighting if(lighting_new) { - for(int i=0;i 0) { pos.y = new_pos.y; - } else { + } else if(pos.y >= 0) { velocity.y *= -0.25; velocity.x *= slipperiness; velocity.z *= slipperiness; diff --git a/src/projectzombie/entity/EntityBoss.java b/src/projectzombie/entity/EntityBoss.java index 19e675d..ca42ca7 100755 --- a/src/projectzombie/entity/EntityBoss.java +++ b/src/projectzombie/entity/EntityBoss.java @@ -42,6 +42,8 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic public EntityBoss(BdfObject bdf) { super(bdf); + + BdfClassLoad(bdf); } @Override @@ -72,10 +74,10 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic super.BdfClassSave(bdf); BdfNamedList nl = bdf.getNamedList(); - nl.set("health", BdfObject.withDouble(health)); - nl.set("bullet_freq", BdfObject.withInteger(bullet_frequency)); - nl.set("spawn_freq", BdfObject.withInteger(spawn_frequency)); - nl.set("seed", BdfObject.withLong(seed)); + nl.set("health", bdf.newObject().setDouble(health)); + nl.set("bullet_freq", bdf.newObject().setInteger(bullet_frequency)); + nl.set("spawn_freq", bdf.newObject().setInteger(spawn_frequency)); + nl.set("seed", bdf.newObject().setLong(seed)); } public EntityBoss(Vec3d pos, Vec3d velocity) { diff --git a/src/projectzombie/entity/EntityBullet.java b/src/projectzombie/entity/EntityBullet.java index 503f02f..bad3bc1 100755 --- a/src/projectzombie/entity/EntityBullet.java +++ b/src/projectzombie/entity/EntityBullet.java @@ -7,10 +7,8 @@ import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2i; import gl_engine.vec.Vec3d; import projectzombie.entity.particle.ParticleBlood; -import projectzombie.init.Models; import projectzombie.init.Resources; import projectzombie.init.Sounds; -import projectzombie.model.Model; import projectzombie.tiles.Tile; import projectzombie.tiles.TileBulletBreakable; import projectzombie.util.math.random.RandomHelpers; @@ -28,6 +26,8 @@ public class EntityBullet extends EntityParticle public EntityBullet(BdfObject bdf) { super(bdf); + + BdfClassLoad(bdf); } @Override @@ -44,8 +44,8 @@ public class EntityBullet extends EntityParticle super.BdfClassSave(bdf); BdfNamedList nl = bdf.getNamedList(); - nl.set("time", BdfObject.withInteger(time)); - nl.set("damage", BdfObject.withDouble(damage)); + nl.set("time", bdf.newObject().setInteger(time)); + nl.set("damage", bdf.newObject().setDouble(damage)); } public EntityBullet(Vec3d pos, Vec3d velocity, Entity parent, double damage, int despawn_time) { diff --git a/src/projectzombie/entity/EntityContainer.java b/src/projectzombie/entity/EntityContainer.java index 2cfc31d..28f6e81 100644 --- a/src/projectzombie/entity/EntityContainer.java +++ b/src/projectzombie/entity/EntityContainer.java @@ -15,6 +15,8 @@ public class EntityContainer extends Entity implements EntityHoldsEntities public EntityContainer(BdfObject bdf) { super(bdf); + + BdfClassLoad(bdf); } public EntityContainer(Vec3d pos, Vec3d velocity, Entity[] entities) { @@ -77,9 +79,9 @@ public class EntityContainer extends Entity implements EntityHoldsEntities super.BdfClassSave(bdf); BdfNamedList nl = bdf.getNamedList(); - BdfArray array = new BdfArray(); + BdfArray array = bdf.newArray(); - nl.set("entities", BdfObject.withArray(array)); + nl.set("entities", bdf.newObject().setArray(array)); for(int i=0;i(); + BdfClassLoad(bdf); } @Override @@ -88,6 +83,9 @@ public class EntityPlayer extends Entity implements angle = nl.get("angle").getDouble(); temperature = nl.get("temperature").getDouble(); hydration = nl.get("hydration").getDouble(); + in_animation = nl.get("inAnimation").getBoolean(); + moving = nl.get("moving").getBoolean(); + inventory_hand = nl.get("hand").getInteger(); tasks = new ArrayList(); @@ -106,15 +104,18 @@ public class EntityPlayer extends Entity implements public void BdfClassSave(BdfObject bdf) { super.BdfClassSave(bdf); BdfNamedList nl = bdf.getNamedList(); - nl.set("health", BdfObject.withDouble(health)); - nl.set("dead", BdfObject.withBoolean(dead)); + nl.set("health", bdf.newObject().setDouble(health)); + nl.set("dead", bdf.newObject().setBoolean(dead)); inventory.BdfClassSave(nl.get("inventory")); armor.BdfClassSave(nl.get("armor")); clothing.BdfClassSave(nl.get("clothing")); - nl.set("angle", BdfObject.withDouble(angle)); - nl.set("temperature", BdfObject.withDouble(temperature)); - nl.set("hydration", BdfObject.withDouble(hydration)); - nl.set("tasks", Task.saveTasks(tasks.toArray(new Task[0]))); + nl.set("angle", bdf.newObject().setDouble(angle)); + nl.set("temperature", bdf.newObject().setDouble(temperature)); + nl.set("hydration", bdf.newObject().setDouble(hydration)); + nl.set("tasks", Task.saveTasks(bdf.newObject(), tasks.toArray(new Task[0]))); + nl.set("inAnimation", bdf.newObject().setBoolean(in_animation)); + nl.set("moving", bdf.newObject().setBoolean(moving)); + nl.set("hand", bdf.newObject().setInteger(inventory_hand)); } public EntityPlayer() { @@ -133,8 +134,6 @@ public class EntityPlayer extends Entity implements inventory = new Inventory(42); armor = new InventoryArmor(); clothing = new InventoryClothing(); - - clothing.setShirt(new ItemStack(Items.SPAWN_ZOMBIE, 99, (short)0)); } @Override diff --git a/src/projectzombie/init/Layers.java b/src/projectzombie/init/Layers.java index fc42150..b1012f3 100755 --- a/src/projectzombie/init/Layers.java +++ b/src/projectzombie/init/Layers.java @@ -1,37 +1,9 @@ package projectzombie.init; -import java.util.Random; - -import projectzombie.Main; -import projectzombie.display.bossbar.BossBars; -import projectzombie.entity.player.EntityPlayer; -import projectzombie.time.GameTimer; -import projectzombie.world.World; import projectzombie.world.layer.Layer; -import projectzombie.world.layer.layergen.LayerGenBossArena; public class Layers { - public static void createWorld(String path, long seed) - { - // Create all the layers - EARTH = new Layer(new Random(seed), LayerGenerators.EARTH); - CAVES = new Layer(new Random(seed), LayerGenerators.CAVES); - LAVA_CAVES = new Layer(new Random(seed), LayerGenerators.LAVA_CAVES); - - // Create the world and set the earth as the default layer - Main.world = new World(path); - Main.world.addLayer(EARTH); - Main.world.addLayer(CAVES); - Main.world.addLayer(LAVA_CAVES); - Main.world.setLayer(0); - - // Initialize some other objects - Main.player = new EntityPlayer(); - GameTimer.resetTime(); - BossBars.clear(); - } - public static Layer EARTH; public static Layer CAVES; public static Layer LAVA_CAVES; diff --git a/src/projectzombie/init/Models.java b/src/projectzombie/init/Models.java index cee3c0a..bdbceec 100755 --- a/src/projectzombie/init/Models.java +++ b/src/projectzombie/init/Models.java @@ -17,7 +17,6 @@ import projectzombie.model.ModelTile; import projectzombie.model.ModelTree; import projectzombie.model.ModelTreeSnow; import projectzombie.model.ModelVertical; -import projectzombie.model.player.ModelPlayerHead; public class Models { @@ -94,6 +93,8 @@ public class Models new ModelVertical(Resources.ATLAS.get("/particle/smoke_4.png")), new ModelVertical(Resources.ATLAS.get("/particle/smoke_5.png"))); + public static final ModelGui UI_PIXEL_WHITE = new ModelGui(Resources.ATLAS.get("/gui/pixel_white.png")); + public static final ModelGui UI_PIXEL_BLACK = new ModelGui(Resources.ATLAS.get("/gui/pixel_black.png")); public static final ModelGui UI_BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button_normal.png"), new Vec2d(12, 1.5)); public static final ModelGui UI_BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_hover.png"), new Vec2d(12, 1.5)); public static final ModelGui UI_BUTTON_DELETE = new ModelGui(Resources.ATLAS.get("/gui/button_delete.png"), new Vec2d(1.875, 1.875)); @@ -101,6 +102,10 @@ public class Models public static final ModelGui UI_BUTTON_PLAY = new ModelGui(Resources.ATLAS.get("/gui/button_play.png"), new Vec2d(1.875, 1.875)); public static final ModelGui UI_BUTTON_PLAY_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_play_hover.png"), new Vec2d(1.875, 1.875)); public static final ModelGui UI_LABEL = new ModelGui(Resources.ATLAS.get("/gui/label.png"), new Vec2d(24, 3)); + public static final ModelGui UI_SELECTION_BOX_WIDE = new ModelGui(Resources.ATLAS.get("/gui/selection_box_wide.png"), new Vec2d(24, 12)); + public static final ModelGui UI_SELECTION_BOX_BIG = new ModelGui(Resources.ATLAS.get("/gui/selection_box_big.png"), new Vec2d(12, 12)); + public static final ModelGui UI_TEXT_BOX = new ModelGui(Resources.ATLAS.get("/gui/text_box.png"), new Vec2d(12, 1.5)); + public static final ModelGui UI_TEXT_CURSOR = new ModelGui(Resources.ATLAS.get("/gui/text_cursor.png"), 2, 50); public static final ModelGui UI_HEALTH_FG = new ModelGui(Resources.ATLAS.get("/gui/health_full.png"), new Vec2d(6, 0.375)); public static final ModelGui UI_HEALTH_BG = new ModelGui(Resources.ATLAS.get("/gui/health_empty.png"), new Vec2d(6, 0.375)); diff --git a/src/projectzombie/input/CursorPosCallback.java b/src/projectzombie/input/CursorPosCallback.java index 518b6dd..0a8807f 100755 --- a/src/projectzombie/input/CursorPosCallback.java +++ b/src/projectzombie/input/CursorPosCallback.java @@ -11,11 +11,13 @@ public class CursorPosCallback implements GLFWCursorPosCallbackI { public static double mx, my; + public static Vec2d getCursorPos() { + return new Vec2d(mx, my); + } + @Override public void invoke(long window, double x, double y) { - Main.menu.input.mousePos(new Vec2d(x, y)); - Main.window.setMouseVisibility(!Main.menu.keepMouse); InputMode.Controller = false; diff --git a/src/projectzombie/input/JoystickCallback.java b/src/projectzombie/input/JoystickCallback.java index dbc9f40..2fa2e72 100755 --- a/src/projectzombie/input/JoystickCallback.java +++ b/src/projectzombie/input/JoystickCallback.java @@ -1,6 +1,15 @@ package projectzombie.input; -import static projectzombie.input.GameInput.*; +import static projectzombie.input.GameInput.activateItem_last; +import static projectzombie.input.GameInput.activate_last; +import static projectzombie.input.GameInput.backButton_last; +import static projectzombie.input.GameInput.dropItem_last; +import static projectzombie.input.GameInput.hotbar_l; +import static projectzombie.input.GameInput.hotbar_r; +import static projectzombie.input.GameInput.moveDown; +import static projectzombie.input.GameInput.moveUp; +import static projectzombie.input.GameInput.move_last; +import static projectzombie.input.GameInput.startButton_last; import java.nio.ByteBuffer; import java.nio.FloatBuffer; diff --git a/src/projectzombie/input/KeyCallback.java b/src/projectzombie/input/KeyCallback.java index 289b433..f176cf4 100755 --- a/src/projectzombie/input/KeyCallback.java +++ b/src/projectzombie/input/KeyCallback.java @@ -15,11 +15,20 @@ import static org.lwjgl.glfw.GLFW.GLFW_KEY_D; import static org.lwjgl.glfw.GLFW.GLFW_KEY_E; import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE; import static org.lwjgl.glfw.GLFW.GLFW_KEY_F11; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL; import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_RIGHT_CONTROL; import static org.lwjgl.glfw.GLFW.GLFW_KEY_S; import static org.lwjgl.glfw.GLFW.GLFW_KEY_W; import static org.lwjgl.glfw.GLFW.GLFW_RELEASE; -import static projectzombie.input.GameInput.*; +import static projectzombie.input.GameInput.backButton_last; +import static projectzombie.input.GameInput.buttonL; +import static projectzombie.input.GameInput.buttonR; +import static projectzombie.input.GameInput.moveDown; +import static projectzombie.input.GameInput.moveLeft; +import static projectzombie.input.GameInput.moveRight; +import static projectzombie.input.GameInput.moveUp; +import static projectzombie.input.GameInput.move_last; import org.lwjgl.glfw.GLFWKeyCallbackI; @@ -27,7 +36,6 @@ import gl_engine.vec.Vec2d; import mainloop.task.IMainloopTask; import projectzombie.Main; import projectzombie.input.types.Input; -import projectzombie.menu.MenuInventory; public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask { @@ -37,6 +45,8 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask private boolean buttonL_last = false; private boolean buttonR_last = false; private boolean inventory_last = false; + private boolean lctrl_pressed = false; + private boolean rctrl_pressed = false; @Override public void invoke(long window, int key, int scancode, int action, int mods) @@ -46,6 +56,13 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask InputMode.Controller = false; + if(key == GLFW_KEY_LEFT_CONTROL) { + lctrl_pressed = pressed; + } + if(key == GLFW_KEY_RIGHT_CONTROL) { + rctrl_pressed = pressed; + } + if(key == GLFW_KEY_W) { moveUp = pressed; } @@ -62,35 +79,44 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask moveRight = pressed; } - if(key == GLFW_KEY_1 && pressed) { - input.hotbarGoto(true, 0); - } - if(key == GLFW_KEY_2 && pressed) { - input.hotbarGoto(true, 1); - } - if(key == GLFW_KEY_3 && pressed) { - input.hotbarGoto(true, 2); - } - if(key == GLFW_KEY_4 && pressed) { - input.hotbarGoto(true, 3); - } - if(key == GLFW_KEY_5 && pressed) { - input.hotbarGoto(true, 4); - } - if(key == GLFW_KEY_6 && pressed) { - input.hotbarGoto(true, 5); - } - if(key == GLFW_KEY_7 && pressed) { - input.hotbarGoto(true, 6); - } - if(key == GLFW_KEY_8 && pressed) { - input.hotbarGoto(true, 7); - } - if(key == GLFW_KEY_9 && pressed) { - input.hotbarGoto(true, 8); - } - if(key == GLFW_KEY_0 && pressed) { - input.hotbarGoto(true, 9); + if(pressed) + { + input.key(key); + + if(lctrl_pressed || rctrl_pressed) { + input.keyCtrl(key); + } + + if(key == GLFW_KEY_1) { + input.hotbarGoto(true, 0); + } + if(key == GLFW_KEY_2) { + input.hotbarGoto(true, 1); + } + if(key == GLFW_KEY_3) { + input.hotbarGoto(true, 2); + } + if(key == GLFW_KEY_4) { + input.hotbarGoto(true, 3); + } + if(key == GLFW_KEY_5) { + input.hotbarGoto(true, 4); + } + if(key == GLFW_KEY_6) { + input.hotbarGoto(true, 5); + } + if(key == GLFW_KEY_7) { + input.hotbarGoto(true, 6); + } + if(key == GLFW_KEY_8) { + input.hotbarGoto(true, 7); + } + if(key == GLFW_KEY_9) { + input.hotbarGoto(true, 8); + } + if(key == GLFW_KEY_0) { + input.hotbarGoto(true, 9); + } } if(key == GLFW_KEY_Q) { diff --git a/src/projectzombie/input/KeyCharCallback.java b/src/projectzombie/input/KeyCharCallback.java index 611d57d..dfd5e9e 100755 --- a/src/projectzombie/input/KeyCharCallback.java +++ b/src/projectzombie/input/KeyCharCallback.java @@ -2,12 +2,15 @@ package projectzombie.input; import org.lwjgl.glfw.GLFWCharCallbackI; +import projectzombie.Main; + public class KeyCharCallback implements GLFWCharCallbackI { @Override - public void invoke(long arg0, int arg1) { + public void invoke(long window, int character) { InputMode.Controller = false; + Main.menu.input.type((char)(character)); } } diff --git a/src/projectzombie/input/MouseButtonCallback.java b/src/projectzombie/input/MouseButtonCallback.java index 792c6e0..75f674c 100755 --- a/src/projectzombie/input/MouseButtonCallback.java +++ b/src/projectzombie/input/MouseButtonCallback.java @@ -3,8 +3,6 @@ package projectzombie.input; import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWMouseButtonCallbackI; -import projectzombie.Main; - public class MouseButtonCallback implements GLFWMouseButtonCallbackI { diff --git a/src/projectzombie/input/types/Input.java b/src/projectzombie/input/types/Input.java index 2b3d70a..775793a 100755 --- a/src/projectzombie/input/types/Input.java +++ b/src/projectzombie/input/types/Input.java @@ -4,6 +4,7 @@ import gl_engine.vec.Vec2d; public interface Input { + public void type(char character); public void move(boolean state, double angle); public void fire(boolean state); public void camera(boolean state, double amount); @@ -12,8 +13,9 @@ public interface Input public void pause(boolean state); public void hotbarGoto(boolean state, int pos); public void hotbarShift(boolean state, int amount); - public void mousePos(Vec2d pos); public void back(boolean state); public void activate(boolean state); public void openInventory(); + public void key(int key); + public void keyCtrl(int key); } diff --git a/src/projectzombie/input/types/InputGUI.java b/src/projectzombie/input/types/InputGUI.java index 13c86bb..69d9c76 100755 --- a/src/projectzombie/input/types/InputGUI.java +++ b/src/projectzombie/input/types/InputGUI.java @@ -15,6 +15,10 @@ public class InputGUI implements Input this.gui = gui; } + public GUI getGUI() { + return gui; + } + @Override public void move(boolean state, double angle) { this.gui.onMove(state, angle); @@ -60,15 +64,6 @@ public class InputGUI implements Input public void hotbarShift(boolean state, int amount) { gui.onScroll(amount); } - - @Override - public void mousePos(Vec2d pos) - { - double mx = (pos.x / Main.window.getWidth() * 20 - 10) * GlHelpers.getAspectRatio(); - double my = -pos.y / Main.window.getHeight() * 20 + 10; - - this.gui.updateMousePos(new Vec2d(mx, my)); - } @Override public void back(boolean state) { @@ -83,5 +78,20 @@ public class InputGUI implements Input @Override public void openInventory() { } + + @Override + public void type(char character) { + gui.type(character); + } + + @Override + public void key(int key) { + gui.keyPress(key); + } + + @Override + public void keyCtrl(int key) { + gui.keyPressCtrl(key); + } } diff --git a/src/projectzombie/input/types/InputGUITextBox.java b/src/projectzombie/input/types/InputGUITextBox.java new file mode 100644 index 0000000..299da6a --- /dev/null +++ b/src/projectzombie/input/types/InputGUITextBox.java @@ -0,0 +1,12 @@ +package projectzombie.input.types; + +public interface InputGUITextBox { + public void onBackspace(); + public void onDelete(); + public void onPressed(char character); + public void onMoveCursor(int direction); + public void setFocus(boolean focus); + public void onPaste(); + public void onHome(); + public void onEnd(); +} diff --git a/src/projectzombie/input/types/InputGame.java b/src/projectzombie/input/types/InputGame.java index 35181c2..0ffd613 100755 --- a/src/projectzombie/input/types/InputGame.java +++ b/src/projectzombie/input/types/InputGame.java @@ -5,6 +5,7 @@ import gl_engine.vec.Vec2d; import projectzombie.Main; import projectzombie.menu.MenuGamePause; import projectzombie.menu.MenuInventory; +import projectzombie.menu.MenuInventoryBasic; import projectzombie.world.chunk.ChunkEventHandler; public class InputGame implements Input @@ -65,10 +66,6 @@ public class InputGame implements Input Main.player.inventory_hand += amount; Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 10); } - - @Override - public void mousePos(Vec2d pos) { - } @Override public void back(boolean state) { @@ -80,7 +77,19 @@ public class InputGame implements Input @Override public void openInventory() { - Main.menu = new MenuInventory(Main.menu); + Main.menu = new MenuInventoryBasic(Main.menu); + } + + @Override + public void type(char character) { + } + + @Override + public void key(int key) { + } + + @Override + public void keyCtrl(int key) { } } diff --git a/src/projectzombie/inventory/Crafting.java b/src/projectzombie/inventory/Crafting.java new file mode 100644 index 0000000..1b6c2a5 --- /dev/null +++ b/src/projectzombie/inventory/Crafting.java @@ -0,0 +1,5 @@ +package projectzombie.inventory; + +public enum Crafting { + BASIC +} diff --git a/src/projectzombie/inventory/Inventory.java b/src/projectzombie/inventory/Inventory.java index 671972d..127b82a 100755 --- a/src/projectzombie/inventory/Inventory.java +++ b/src/projectzombie/inventory/Inventory.java @@ -158,11 +158,11 @@ public class Inventory implements IInventory, IBdfClassManager { BdfNamedList nl = bdf.getNamedList(); - nl.set("size", BdfObject.withInteger(items.length)); + nl.set("size", bdf.newObject().setInteger(items.length)); BdfArray array = nl.get("items").getArray(); for(ItemStack stack : items) { - BdfObject stack_bdf = new BdfObject(); + BdfObject stack_bdf = bdf.newObject(); stack.BdfClassSave(stack_bdf); array.add(stack_bdf); } diff --git a/src/projectzombie/inventory/InventoryArmor.java b/src/projectzombie/inventory/InventoryArmor.java index 09f8209..0ae2290 100644 --- a/src/projectzombie/inventory/InventoryArmor.java +++ b/src/projectzombie/inventory/InventoryArmor.java @@ -59,7 +59,7 @@ public class InventoryArmor implements IBdfClassManager, IInventoryArmor @Override public void BdfClassSave(BdfObject bdf) { - BdfNamedList nl = new BdfNamedList(); + BdfNamedList nl = bdf.newNamedList(); helmet.BdfClassSave(nl.get("helmet")); chest.BdfClassSave(nl.get("chest")); leggings.BdfClassSave(nl.get("leggings")); diff --git a/src/projectzombie/inventory/InventoryClothing.java b/src/projectzombie/inventory/InventoryClothing.java index 2f92e08..d60533b 100644 --- a/src/projectzombie/inventory/InventoryClothing.java +++ b/src/projectzombie/inventory/InventoryClothing.java @@ -59,7 +59,7 @@ public class InventoryClothing implements IBdfClassManager, IInventoryClothing @Override public void BdfClassSave(BdfObject bdf) { - BdfNamedList nl = new BdfNamedList(); + BdfNamedList nl = bdf.newNamedList(); shirt.BdfClassSave(nl.get("shirt")); pants.BdfClassSave(nl.get("pants")); boots.BdfClassSave(nl.get("boots")); diff --git a/src/projectzombie/inventory/recipe/Recipe.java b/src/projectzombie/inventory/recipe/Recipe.java new file mode 100644 index 0000000..4c6ce78 --- /dev/null +++ b/src/projectzombie/inventory/recipe/Recipe.java @@ -0,0 +1,13 @@ +package projectzombie.inventory.recipe; + +import projectzombie.inventory.Inventory; +import projectzombie.inventory.Crafting; +import projectzombie.util.math.ItemStack; + +public abstract class Recipe +{ + public abstract ItemStack getResult(); + public abstract boolean canCraft(Crafting tool); + public abstract boolean hasResourcesToCraft(Inventory inventory); + public abstract ItemStack craftResult(Inventory inventory); +} diff --git a/src/projectzombie/inventory/recipe/RecipeBasic.java b/src/projectzombie/inventory/recipe/RecipeBasic.java new file mode 100644 index 0000000..b473d75 --- /dev/null +++ b/src/projectzombie/inventory/recipe/RecipeBasic.java @@ -0,0 +1,57 @@ +package projectzombie.inventory.recipe; + +import projectzombie.inventory.Crafting; +import projectzombie.inventory.Inventory; +import projectzombie.util.math.ItemStack; + +public class RecipeBasic extends Recipe +{ + protected ItemStack[] stacks_required; + protected Crafting[] tools_required; + protected ItemStack result; + + public RecipeBasic(ItemStack[] stacks_required, Crafting[] tools_required, ItemStack result) + { + this.stacks_required = stacks_required; + this.tools_required = tools_required; + } + + @Override + public ItemStack getResult() { + return result.copy(); + } + + @Override + public boolean canCraft(Crafting tool) + { + for(Crafting tool_required : tools_required) { + if(tool == tool_required) { + return true; + } + } + + return false; + } + + @Override + public boolean hasResourcesToCraft(Inventory inventory) + { + for(ItemStack item : stacks_required) { + if(inventory.getItemCount(item) < item.count) { + return false; + } + } + + return true; + } + + @Override + public ItemStack craftResult(Inventory inventory) + { + for(ItemStack item : stacks_required) { + inventory.removeItem(item.copy()); + } + + return result.copy(); + } +} diff --git a/src/projectzombie/items/Item.java b/src/projectzombie/items/Item.java index 5111662..23a6d39 100755 --- a/src/projectzombie/items/Item.java +++ b/src/projectzombie/items/Item.java @@ -4,7 +4,6 @@ import projectzombie.entity.Entity; import projectzombie.entity.EntityHasInventory; import projectzombie.entity.player.EntityPlayer; import projectzombie.inventory.IInventory; -import projectzombie.inventory.Inventory; import projectzombie.model.ModelItem; import projectzombie.util.math.ItemStack; import projectzombie.world.chunk.Chunk; diff --git a/src/projectzombie/items/ItemAmmo.java b/src/projectzombie/items/ItemAmmo.java index 142f287..c3297e9 100755 --- a/src/projectzombie/items/ItemAmmo.java +++ b/src/projectzombie/items/ItemAmmo.java @@ -1,11 +1,7 @@ package projectzombie.items; -import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; import projectzombie.model.ModelItem; -import projectzombie.util.math.ItemStack; -import projectzombie.world.chunk.Chunk; -import projectzombie.world.layer.Layer; public class ItemAmmo extends Item { diff --git a/src/projectzombie/items/ItemEmpty.java b/src/projectzombie/items/ItemEmpty.java index 75f1384..f4fa04d 100755 --- a/src/projectzombie/items/ItemEmpty.java +++ b/src/projectzombie/items/ItemEmpty.java @@ -1,7 +1,6 @@ package projectzombie.items; import projectzombie.entity.Entity; -import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; import projectzombie.model.ModelItem; import projectzombie.util.math.ItemStack; diff --git a/src/projectzombie/items/ItemFlint.java b/src/projectzombie/items/ItemFlint.java index 82aba11..fbc5302 100644 --- a/src/projectzombie/items/ItemFlint.java +++ b/src/projectzombie/items/ItemFlint.java @@ -2,7 +2,6 @@ package projectzombie.items; import projectzombie.init.Models; import projectzombie.model.ModelItem; -import projectzombie.util.math.ItemStack; public class ItemFlint extends Item { diff --git a/src/projectzombie/items/ItemRock.java b/src/projectzombie/items/ItemRock.java index c9d6d92..82a092d 100755 --- a/src/projectzombie/items/ItemRock.java +++ b/src/projectzombie/items/ItemRock.java @@ -1,11 +1,8 @@ package projectzombie.items; -import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; import projectzombie.model.ModelItem; import projectzombie.util.math.ItemStack; -import projectzombie.world.chunk.Chunk; -import projectzombie.world.layer.Layer; public class ItemRock extends Item implements ItemTool { diff --git a/src/projectzombie/menu/MenuDeath.java b/src/projectzombie/menu/MenuDeath.java index 8e39829..97871cc 100755 --- a/src/projectzombie/menu/MenuDeath.java +++ b/src/projectzombie/menu/MenuDeath.java @@ -2,10 +2,10 @@ package projectzombie.menu; import projectzombie.Main; import projectzombie.input.types.InputGUI; -import projectzombie.menu.gui.GUIButtonGroup; -import projectzombie.menu.gui.GUIButtonGroupPause; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUIButtonBasic; +import projectzombie.menu.gui.GUIButtonGroup; +import projectzombie.menu.gui.GUIButtonGroupPause; public class MenuDeath extends Menu { diff --git a/src/projectzombie/menu/MenuGamePause.java b/src/projectzombie/menu/MenuGamePause.java index 1eec8e5..01b65c9 100755 --- a/src/projectzombie/menu/MenuGamePause.java +++ b/src/projectzombie/menu/MenuGamePause.java @@ -1,17 +1,13 @@ package projectzombie.menu; -import java.io.FileOutputStream; -import java.util.zip.DeflaterOutputStream; - -import bdf.types.BdfObject; import projectzombie.Main; import projectzombie.input.types.InputGUI; -import projectzombie.menu.gui.GUIButtonGroup; -import projectzombie.menu.gui.GUIButtonGroupPause; -import projectzombie.menu.gui.GUILabelPause; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUIBackToMenu; import projectzombie.menu.gui.GUIButtonBasic; +import projectzombie.menu.gui.GUIButtonGroup; +import projectzombie.menu.gui.GUIButtonGroupPause; +import projectzombie.menu.gui.GUILabelPause; public class MenuGamePause extends Menu { @@ -44,48 +40,7 @@ public class MenuGamePause extends Menu public void saveAndQuit() { - long now, cur = 0; - - BdfObject bdf = new BdfObject(); - - now = System.currentTimeMillis(); - Main.world.BdfClassSave(bdf); - cur = System.currentTimeMillis(); - System.out.println("Time for BdfClassSave: " + (cur - now)); - now = cur; - - System.out.println("Size on file: " + bdf.serialize().size()); - //System.out.println(bdf.serializeHumanReadable()); - - try { - - /* - - FileOutputStream os = new FileOutputStream("./layer.hbdf"); - os.write(bdf.serializeHumanReadable(new BdfIndent("\t", "\n")).getBytes()); - os.close(); - - cur = System.currentTimeMillis(); - System.out.println("Time for HBDF: " + (cur - now)); - now = cur; - - */ - - FileOutputStream os2 = new FileOutputStream("./layer.bdf"); - DeflaterOutputStream dos = new DeflaterOutputStream(os2); - dos.write(bdf.serialize().getBytes()); - dos.close(); - os2.close(); - - cur = System.currentTimeMillis(); - System.out.println("Time for BDF: " + (cur - now)); - now = cur; - } - - catch(Exception e) { - e.printStackTrace(); - } - + Main.world.save(); Main.menu = new MenuMain(); } } diff --git a/src/projectzombie/menu/MenuInventory.java b/src/projectzombie/menu/MenuInventory.java index fc5d44d..694272c 100644 --- a/src/projectzombie/menu/MenuInventory.java +++ b/src/projectzombie/menu/MenuInventory.java @@ -1,12 +1,9 @@ package projectzombie.menu; -import gl_engine.MathHelpers; import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.Main; -import projectzombie.display.Camera; -import projectzombie.init.Items; import projectzombie.init.Models; import projectzombie.input.CursorPosCallback; import projectzombie.input.types.InputGUI; @@ -15,24 +12,25 @@ import projectzombie.inventory.InventoryArmor; import projectzombie.inventory.InventoryClothing; import projectzombie.items.ItemArmor; import projectzombie.items.ItemClothing; -import projectzombie.menu.gui.GUIButton; +import projectzombie.menu.gui.GUI; +import projectzombie.menu.gui.GUIBackToMenu; import projectzombie.menu.gui.GUIItemHolder; import projectzombie.menu.gui.GUIItemSlot; import projectzombie.menu.gui.GUIItemSlotGetter; import projectzombie.menu.gui.GUIItemSlotGetterStorage; -import projectzombie.menu.gui.GUI; -import projectzombie.menu.gui.GUIBackToMenu; import projectzombie.model.Model; -import projectzombie.util.gl.GlHelpers; +import projectzombie.model.ModelGui; import projectzombie.util.math.ItemStack; -public class MenuInventory extends Menu +public abstract class MenuInventory extends Menu { - private Menu parent; - private GUI gui; + protected Menu parent; + protected GUIItemHolder itemHolder; + protected GUI gui; + private GUI top_gui; - private GUIItemSlot[] item_slots; - private GUIItemSlot[] armor_slots; + protected GUIItemSlot[] item_slots; + protected GUIItemSlot[] armor_slots; public MenuInventory(Menu parent) { @@ -44,12 +42,13 @@ public class MenuInventory extends Menu keepMouse = false; - gui = new GUIBackToMenu(parent); - input = new InputGUI(gui); + top_gui = new GUIBackToMenu(parent); + input = new InputGUI(top_gui); + gui = new GUI(); Inventory inventory = Main.player.getInventory(); - GUIItemHolder itemHolder = new GUIItemHolder(); + itemHolder = new GUIItemHolder(); item_slots = new GUIItemSlot[42]; armor_slots = new GUIItemSlot[6]; @@ -185,9 +184,8 @@ public class MenuInventory extends Menu } } - - - gui.add(itemHolder); + top_gui.add(gui); + top_gui.add(itemHolder); } @Override @@ -230,14 +228,14 @@ public class MenuInventory extends Menu player_matrix = Matrix4.multiply(Matrix4.rotate(ay, 1, 0, 0), player_matrix); player_matrix = Matrix4.multiply(Matrix4.translate(-width * (10.8 / 256.0), -height * (10.8 / 256.0), 0), player_matrix);*/ - gui.render(); + top_gui.render(); } @Override public void update() { super.update(); - gui.update(new Vec2d(CursorPosCallback.mx, CursorPosCallback.my)); + top_gui.update(new Vec2d(CursorPosCallback.mx, CursorPosCallback.my)); } } diff --git a/src/projectzombie/menu/MenuInventoryBasic.java b/src/projectzombie/menu/MenuInventoryBasic.java new file mode 100644 index 0000000..b6226df --- /dev/null +++ b/src/projectzombie/menu/MenuInventoryBasic.java @@ -0,0 +1,36 @@ +package projectzombie.menu; + +import gl_engine.matrix.Matrix4; +import gl_engine.vec.Vec2d; +import projectzombie.init.Models; +import projectzombie.menu.gui.GUIContainerSlider; + +public class MenuInventoryBasic extends MenuInventory +{ + private GUIContainerSlider slider; + + public MenuInventoryBasic(Menu parent) { + super(parent); + + slider = new GUIContainerSlider(new Vec2d( + Models.UI_INVENTORY.getWidth() * 1 / 256.0, + -Models.UI_INVENTORY.getHeight() * 127 / 256.0), new Vec2d( + Models.UI_INVENTORY.getWidth() * 254 / 256.0, + Models.UI_INVENTORY.getHeight() * 254 / 256.0), 100); + + gui.add(slider); + } + + @Override + public void render() + { + Matrix4 matrix = Matrix4.translate(0, -Models.UI_INVENTORY.getHeight() / 2, 0); + + // Render the inventory gui + Models.UI_SELECTION_BOX_BIG.setModel(matrix); + Models.UI_SELECTION_BOX_BIG.render(); + + super.render(); + } + +} diff --git a/src/projectzombie/menu/MenuMain.java b/src/projectzombie/menu/MenuMain.java index 8a377f0..a9279ed 100755 --- a/src/projectzombie/menu/MenuMain.java +++ b/src/projectzombie/menu/MenuMain.java @@ -2,14 +2,16 @@ package projectzombie.menu; import java.util.Random; +import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.Main; -import projectzombie.init.Layers; import projectzombie.input.types.InputGUI; -import projectzombie.menu.gui.GUIButtonGroup; -import projectzombie.menu.gui.GUILabelMain; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUIButtonBasic; +import projectzombie.menu.gui.GUIButtonGroup; +import projectzombie.menu.gui.GUILabelMain; +import projectzombie.menu.gui.GUITextBox; +import projectzombie.world.World; public class MenuMain extends Menu { @@ -45,7 +47,7 @@ public class MenuMain extends Menu gui.add(group); gui.setSelected(group.get(0)); - Layers.createWorld(null, rand.nextLong()); + World.createWorld(null, rand.nextLong()); Main.player.dead = true; } diff --git a/src/projectzombie/menu/MenuSaves.java b/src/projectzombie/menu/MenuSaves.java index 9a32069..eacff0f 100644 --- a/src/projectzombie/menu/MenuSaves.java +++ b/src/projectzombie/menu/MenuSaves.java @@ -1,33 +1,51 @@ package projectzombie.menu; +import java.io.File; +import java.util.ArrayList; import java.util.Random; -import org.lwjgl.opengl.GL33; - +import bdf.file.BdfFileManager; +import bdf.types.BdfArray; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; +import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; import projectzombie.Main; -import projectzombie.init.Layers; import projectzombie.init.Models; import projectzombie.input.types.InputGUI; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUIAlignment; -import projectzombie.menu.gui.GUIButton; +import projectzombie.menu.gui.GUIBackToMenu; import projectzombie.menu.gui.GUIButtonBasic; -import projectzombie.menu.gui.GUIButtonCallback; +import projectzombie.menu.gui.GUIContainerSlider; import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.GUISavesCard; -import projectzombie.menu.gui.GUIButtonModel; -import projectzombie.menu.gui.GUIButtonSetting; -import projectzombie.menu.gui.GUIContainerSlider; +import projectzombie.model.ModelGui; +import projectzombie.world.World; public class MenuSaves extends Menu { private static final Random rand = new Random(); + private BdfFileManager reader; + private ArrayList saves; + private int saves_remove = -1; + private Menu parent; private GUIContainerSlider slider; private GUI gui; + private class SaveCard + { + String text, filename; + + public SaveCard(String text, String filename) + { + this.text = text; + this.filename = filename; + } + } + public MenuSaves(Menu parent) { this.parent = parent; @@ -36,8 +54,8 @@ public class MenuSaves extends Menu doGameRender = parent.doGameRender; showIngameGUI = parent.showIngameGUI; - gui = new GUI(); - + gui = new GUIBackToMenu(parent); + saves = new ArrayList(); input = new InputGUI(gui); keepMouse = false; @@ -47,14 +65,16 @@ public class MenuSaves extends Menu }); GUIButtonBasic buttonCreate = new GUIButtonBasic("Create", button -> { - Layers.createWorld(null, rand.nextLong()); - Main.menu = new MenuGame(); + createWorld(); }); - slider = new GUIContainerSlider(new Vec2d(-20, -5), new Vec2d(40, 10), 10); + slider = new GUIContainerSlider(new Vec2d( + -Models.UI_SELECTION_BOX_WIDE.getWidth() * 127 / 256.0, + -Models.UI_SELECTION_BOX_WIDE.getHeight() * 63 / 128.0), new Vec2d( + Models.UI_SELECTION_BOX_WIDE.getWidth() * 254 / 256.0, + Models.UI_SELECTION_BOX_WIDE.getHeight() * 126 / 128.0), 10); - GUISavesCard savesCard = new GUISavesCard(new Vec2d(0, 0)); - slider.add(savesCard); + reloadDatabase(); buttonBack.setAlign(GUIAlignment.RIGHT); buttonCreate.setAlign(GUIAlignment.LEFT); @@ -72,10 +92,100 @@ public class MenuSaves extends Menu gui.add(buttonCreate); gui.add(slider); } + + private void createWorld() { + Main.menu = new MenuWorldNew(this); + } + + private void loadSave(int index) + { + BdfObject bdf = reader.getObject(); + BdfNamedList nl = bdf.getNamedList(); + BdfArray array = nl.get("saves").getArray(); + + BdfObject save_bdf = array.remove(index); + array.add(save_bdf); + + reader.saveDatabase(); + + Main.world = new World(saves.get(index).filename); + Main.menu = new MenuGame(); + } + + private void deleteSave(int index) + { + SaveCard save = saves.get(index); + Main.menu = new MenuWorldDelete(this, save.text, save.filename); + } + + public void reloadDatabase() + { + saves.clear(); + reader = new BdfFileManager("./saves.bdf", true); + BdfNamedList nl = reader.getObject().getNamedList(); + BdfArray array = nl.get("saves").getArray(); + + for(BdfObject save_bdf : array) + { + BdfNamedList save_nl = save_bdf.getNamedList(); + + SaveCard save = new SaveCard( + save_nl.get("name").getString(), + save_nl.get("path").getString()); + + saves.add(save); + } + + generateSaveCards(); + } + + private void generateSaveCards() + { + double slider_length = Models.UI_LABEL.getHeight() * 18.0 * saves.size() / 16.0; + double selection_length = Models.UI_SELECTION_BOX_WIDE.getHeight() * 248 / 256.0; + + slider.clear(); + slider.setLength(slider_length > selection_length ? slider_length - selection_length : 0); + + for(int i=0;i { + Main.menu = parent; + }); + + GUIButtonBasic buttonDelete = new GUIButtonBasic("Delete", button -> { + deleteSave(); + }); + + buttonCancel.setAlign(GUIAlignment.RIGHT); + buttonDelete.setAlign(GUIAlignment.LEFT); + + buttonCancel.setPos(new Vec2d(-0.5, -4)); + buttonDelete.setPos(new Vec2d(0.5, -4)); + + { + // Delete world title + GUILabel label = new GUILabel(); + label.setText("Delete World"); + label.setSize(new Vec2d(1, 1)); + label.setPos(new Vec2d(0, 4)); + gui.add(label); + } + + { + // Delete world confirm message + GUILabel label = new GUILabel(); + label.setText("Are you sure you want to delete \"" + name + "\"?"); + label.setSize(new Vec2d(0.4, 0.4)); + label.setPos(new Vec2d(0, 3)); + gui.add(label); + } + + gui.add(buttonCancel); + gui.add(buttonDelete); + } + + private void deleteSave() + { + BdfFileManager reader = new BdfFileManager("./saves.bdf", true); + BdfObject bdf = reader.getObject(); + BdfNamedList nl = bdf.getNamedList(); + BdfArray array = nl.get("saves").getArray(); + + File save_file = new File("./saves/" + path + ".bdf"); + save_file.delete(); + + for(int i=0;i { + Main.menu = parent; + }); + + GUIButtonBasic buttonCreate = new GUIButtonBasic("Generate", button -> { + generateWorld(); + }); + + buttonBack.setAlign(GUIAlignment.RIGHT); + buttonCreate.setAlign(GUIAlignment.LEFT); + + buttonBack.setPos(new Vec2d(-0.5, -8)); + buttonCreate.setPos(new Vec2d(0.5, -8)); + + { + // New world title label + GUILabel label = new GUILabel(); + label.setText("Create New World"); + label.setSize(new Vec2d(1, 1)); + label.setPos(new Vec2d(0, 6.8)); + gui.add(label); + } + + { + // Set the world name + + double offset = -Models.UI_TEXT_BOX.getWidth() / 2; + + GUILabel label = new GUILabel(); + label.setAlign(GUIAlignment.RIGHT); + label.setText("World Name"); + label.setSize(new Vec2d(0.4, 0.4)); + label.setPos(new Vec2d(offset + Models.UI_TEXT_BOX.getWidth() * 2 / 128.0, 4)); + gui.add(label); + + world_name = new GUITextBox(new Vec2d(offset, 3.8 - Models.UI_TEXT_BOX.getHeight()), true); + world_name.setText(name); + gui.add(world_name); + } + + gui.add(buttonBack); + gui.add(buttonCreate); + } + + private void generateWorld() + { + name = world_name.getText(); + + String path = name; + path = path.toLowerCase(); + + char[] path_chars = path.toCharArray(); + + for(int i=0;i= '0' && c <= '9') || (c >= 'a' && c <= 'z')) { + path_chars[i] = c; + } else { + path_chars[i] = '_'; + } + } + + path = new String(path_chars); + + if(name.length() == 0) { + return; + } + + BdfFileManager reader = new BdfFileManager("./saves.bdf", true); + BdfObject bdf = reader.getObject(); + BdfNamedList nl = bdf.getNamedList(); + BdfArray array = nl.get("saves").getArray(); + + // Find a unique name and path + + String name_new = name; + String path_new = path; + + boolean duplicate = true; + + for(int i=1;duplicate;i++) + { + duplicate = false; + + for(BdfObject save_bdf : array) + { + BdfNamedList save_nl = save_bdf.getNamedList(); + String save_name = save_nl.get("name").getString(); + String save_path = save_nl.get("path").getString(); + + if(i > 1) { + name_new = name + " (" + i + ")"; + path_new = path + "_" + i; + } + + if(name_new.contentEquals(save_name) || path_new.contentEquals(save_path)) { + duplicate = true; + break; + } + } + } + + BdfObject save_bdf = bdf.newObject(); + BdfNamedList save_nl = save_bdf.getNamedList(); + + save_nl.set("name", bdf.newObject().setString(name_new)); + save_nl.set("path", bdf.newObject().setString(path_new)); + + array.add(save_bdf); + reader.saveDatabase(); + + World.createWorld(path_new, seed); + Main.menu = new MenuGame(); + } + + @Override + public void update() + { + super.update(); + parent.update(); + } + + @Override + public void render() { + gui.render(); + } + +} diff --git a/src/projectzombie/menu/gui/GUI.java b/src/projectzombie/menu/gui/GUI.java index 1111807..90bd14e 100755 --- a/src/projectzombie/menu/gui/GUI.java +++ b/src/projectzombie/menu/gui/GUI.java @@ -2,18 +2,26 @@ package projectzombie.menu.gui; import java.util.ArrayList; +import org.lwjgl.glfw.GLFW; + import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; +import projectzombie.input.CursorPosCallback; +import projectzombie.input.types.InputGUITextBox; public class GUI implements GUIContainer { private ArrayList components = new ArrayList(); - private Vec2d mousePos = new Vec2d(0, 0); public GUISelectable selected; + private InputGUITextBox text_box; private static boolean move_last = false; + public void setTextBox(InputGUITextBox text_box) { + this.text_box = text_box; + } + public void setSelected(GUISelectable selected) { if(this.selected != null) { this.selected.setSelected(false); @@ -31,8 +39,12 @@ public class GUI implements GUIContainer } } + public Vec2d getCursorPos() { + return CursorPosCallback.getCursorPos(); + } + public void render() { - this.render(Matrix4.identity(), mousePos, true); + this.render(Matrix4.identity(), getCursorPos(), true); } @Override @@ -40,10 +52,6 @@ public class GUI implements GUIContainer components.add(c); } - public void updateMousePos(Vec2d pos) { - this.mousePos = pos; - } - public void onMove(boolean status, double angle) { if(this.selected == null) { @@ -96,35 +104,56 @@ public class GUI implements GUIContainer } @Override - public void onMouseClick(Vec2d pos) { + public void onMouseClick(Vec2d pos) + { + if(text_box != null && text_box instanceof GUIComponent && !((GUIComponent)text_box).checkMouseHover(pos)) { + text_box.setFocus(false); + text_box = null; + } + + Vec2d cursorPos = getCursorPos(); + for(GUIComponent c : components) { - if(c.checkMouseHover(mousePos)) { - c.onMouseClick(mousePos); + if(c.checkMouseHover(cursorPos)) { + c.onMouseClick(cursorPos); } } } @Override - public void onRightClick(Vec2d pos) { + public void onRightClick(Vec2d pos) + { + Vec2d cursorPos = getCursorPos(); + for(GUIComponent c : components) { - if(c.checkMouseHover(mousePos)) { - c.onRightClick(mousePos); + if(c.checkMouseHover(cursorPos)) { + c.onRightClick(cursorPos); } } } public void onMouseClick() { - this.onMouseClick(mousePos); + this.onMouseClick(getCursorPos()); } public void onRightClick() { - this.onRightClick(mousePos); + this.onRightClick(getCursorPos()); } @Override - public void onBack() { - for(GUIComponent c : components) { - c.onBack(); + public void onBack() + { + if(text_box == null) + { + for(GUIComponent c : components) { + c.onBack(); + } + } + + else + { + text_box.setFocus(false); + text_box = null; } } @@ -150,7 +179,63 @@ public class GUI implements GUIContainer } public void onScroll(int amount) { - onScroll(mousePos, amount / 10.0); + onScroll(getCursorPos(), amount); + } + + @Override + public void clear() { + components.clear(); + } + + public void type(char character) { + if(text_box != null) { + text_box.onPressed(character); + } + } + + public void pasteKey() { + if(text_box != null) { + text_box.onDelete(); + } + } + + public void keyPress(int key) { + if(text_box != null) + { + switch(key) + { + case GLFW.GLFW_KEY_LEFT: + text_box.onMoveCursor(-1); + break; + case GLFW.GLFW_KEY_RIGHT: + text_box.onMoveCursor(1); + break; + case GLFW.GLFW_KEY_DELETE: + text_box.onDelete(); + break; + case GLFW.GLFW_KEY_BACKSPACE: + text_box.onBackspace(); + break; + case GLFW.GLFW_KEY_HOME: + text_box.onHome(); + break; + case GLFW.GLFW_KEY_END: + text_box.onEnd(); + break; + } + } + } + + public void keyPressCtrl(int key) { + if(text_box != null) + { + switch(key) + { + case GLFW.GLFW_KEY_V: + text_box.onPaste(); + break; + } + } } } diff --git a/src/projectzombie/menu/gui/GUIButton.java b/src/projectzombie/menu/gui/GUIButton.java index 217b3f8..0e225be 100755 --- a/src/projectzombie/menu/gui/GUIButton.java +++ b/src/projectzombie/menu/gui/GUIButton.java @@ -3,12 +3,10 @@ package projectzombie.menu.gui; import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; -import projectzombie.Main; import projectzombie.init.Models; import projectzombie.input.InputMode; import projectzombie.model.ModelGui; import projectzombie.text.Text; -import projectzombie.util.gl.GlHelpers; public class GUIButton implements GUIComponent, GUISelectable { diff --git a/src/projectzombie/menu/gui/GUIButtonGroup.java b/src/projectzombie/menu/gui/GUIButtonGroup.java index fde57f3..8296e5e 100755 --- a/src/projectzombie/menu/gui/GUIButtonGroup.java +++ b/src/projectzombie/menu/gui/GUIButtonGroup.java @@ -104,5 +104,10 @@ public class GUIButtonGroup implements GUIContainer c.onScroll(mousePos, amount); } } + + @Override + public void clear() { + buttons.clear(); + } } diff --git a/src/projectzombie/menu/gui/GUIButtonGroupPause.java b/src/projectzombie/menu/gui/GUIButtonGroupPause.java index d5643ef..7206e1a 100755 --- a/src/projectzombie/menu/gui/GUIButtonGroupPause.java +++ b/src/projectzombie/menu/gui/GUIButtonGroupPause.java @@ -9,7 +9,6 @@ public class GUIButtonGroupPause extends GUIButtonGroup public GUIButtonGroupPause() { add(new GUIButtonBasic("Settings", button -> { - Main.menu.input.mousePos(new Vec2d(0, 0)); Main.menu = new MenuSettings(Main.menu); })); diff --git a/src/projectzombie/menu/gui/GUIContainer.java b/src/projectzombie/menu/gui/GUIContainer.java index e4aef94..cdfd50b 100755 --- a/src/projectzombie/menu/gui/GUIContainer.java +++ b/src/projectzombie/menu/gui/GUIContainer.java @@ -3,4 +3,5 @@ package projectzombie.menu.gui; public interface GUIContainer extends GUIComponent { public void add(GUIComponent c); + public void clear(); } diff --git a/src/projectzombie/menu/gui/GUIContainerSlider.java b/src/projectzombie/menu/gui/GUIContainerSlider.java index 6d23cc1..e1d4a51 100644 --- a/src/projectzombie/menu/gui/GUIContainerSlider.java +++ b/src/projectzombie/menu/gui/GUIContainerSlider.java @@ -6,8 +6,9 @@ import org.lwjgl.opengl.GL33; import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; -import gl_engine.vec.Vec4d; +import gl_engine.vec.Vec3d; import projectzombie.Main; +import projectzombie.init.Models; public class GUIContainerSlider implements GUIComponent, GUIContainer { @@ -39,8 +40,8 @@ public class GUIContainerSlider implements GUIComponent, GUIContainer canHover = false; } - matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -scroll, 0)); - mousePos = mousePos.add(new Vec2d(0, scroll)); + matrix = Matrix4.multiply(matrix, Matrix4.translate(0, scroll, 0)); + mousePos = mousePos.add(new Vec2d(0, -scroll)); GL33.glUniform1i(Main.window.glsl_do_discard_coords, 1); GL33.glUniform4f(Main.window.glsl_discard_coords, @@ -50,6 +51,26 @@ public class GUIContainerSlider implements GUIComponent, GUIContainer c.render(matrix, mousePos, canHover); } + if(length > 0) + { + GL33.glUniform4f(Main.window.glsl_color, 0.25f, 0.25f, 0.25f, 1); + + double start = size.y * scroll / (length + size.y); + double end = size.y * (scroll + size.y) / (length + size.y); + + Matrix4 matrix_scroll_bar = Matrix4.translate( + pos.x + size.x - 0.125f, + pos.y + size.y - end, 0); + + matrix_scroll_bar = Matrix4.multiply(Matrix4.scale( + new Vec3d(1, (float)(end - start), 1)), matrix_scroll_bar); + + Models.UI_PIXEL_WHITE.setModel(matrix_scroll_bar); + Models.UI_PIXEL_WHITE.render(); + + GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1); + } + GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0); } @@ -60,7 +81,7 @@ public class GUIContainerSlider implements GUIComponent, GUIContainer return; } - mousePos = mousePos.add(new Vec2d(0, scroll)); + mousePos = mousePos.add(new Vec2d(0, -scroll)); for(GUIComponent c : components) { c.update(mousePos); @@ -79,7 +100,7 @@ public class GUIContainerSlider implements GUIComponent, GUIContainer return; } - mousePos = mousePos.add(new Vec2d(0, scroll)); + mousePos = mousePos.add(new Vec2d(0, -scroll)); for(GUIComponent c : components) { if(c.checkMouseHover(mousePos)) { @@ -95,7 +116,7 @@ public class GUIContainerSlider implements GUIComponent, GUIContainer return; } - mousePos = mousePos.add(new Vec2d(0, scroll)); + mousePos = mousePos.add(new Vec2d(0, -scroll)); for(GUIComponent c : components) { if(c.checkMouseHover(mousePos)) { @@ -141,5 +162,10 @@ public class GUIContainerSlider implements GUIComponent, GUIContainer c.onScroll(mousePos, amount); } } + + @Override + public void clear() { + components.clear(); + } } diff --git a/src/projectzombie/menu/gui/GUIItemHolder.java b/src/projectzombie/menu/gui/GUIItemHolder.java index e703a76..15e77e6 100644 --- a/src/projectzombie/menu/gui/GUIItemHolder.java +++ b/src/projectzombie/menu/gui/GUIItemHolder.java @@ -1,6 +1,5 @@ package projectzombie.menu.gui; -import gl_engine.MathHelpers; import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; @@ -8,7 +7,6 @@ import projectzombie.Main; import projectzombie.entity.EntityItem; import projectzombie.model.Model; import projectzombie.text.Text; -import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.ItemStack; import projectzombie.world.layer.Layer; diff --git a/src/projectzombie/menu/gui/GUIItemSlot.java b/src/projectzombie/menu/gui/GUIItemSlot.java index 548f15d..ece97d9 100644 --- a/src/projectzombie/menu/gui/GUIItemSlot.java +++ b/src/projectzombie/menu/gui/GUIItemSlot.java @@ -3,12 +3,10 @@ package projectzombie.menu.gui; import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; -import projectzombie.Main; import projectzombie.init.Models; import projectzombie.model.Model; import projectzombie.model.ModelItem; import projectzombie.text.Text; -import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.ItemStack; public class GUIItemSlot implements GUIComponent diff --git a/src/projectzombie/menu/gui/GUISavesCard.java b/src/projectzombie/menu/gui/GUISavesCard.java index ce2d75c..80501f3 100644 --- a/src/projectzombie/menu/gui/GUISavesCard.java +++ b/src/projectzombie/menu/gui/GUISavesCard.java @@ -2,8 +2,10 @@ package projectzombie.menu.gui; import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; +import gl_engine.vec.Vec3d; import projectzombie.init.Models; import projectzombie.model.ModelGui; +import projectzombie.text.Text; public class GUISavesCard implements GUIComponent { @@ -12,12 +14,12 @@ public class GUISavesCard implements GUIComponent private Vec2d pos = new Vec2d(0, 0); private GUIButtonModel buttonDelete; private GUIButtonModel buttonPlay; + private String text; - public GUISavesCard(Vec2d pos) + public GUISavesCard(String text, Vec2d pos) { - pos.x -= LABEL.getWidth() / 2; - this.pos = pos; + this.text = text; buttonDelete = new GUIButtonModel(Models.UI_BUTTON_DELETE, Models.UI_BUTTON_DELETE_HOVER, button -> { onDeletePressed(); @@ -27,8 +29,8 @@ public class GUISavesCard implements GUIComponent onPlayPressed(); }); - buttonPlay.setPos(new Vec2d(-LABEL.getWidth()*122/256.0, LABEL.getHeight()*6/32.0)); - buttonDelete.setPos(new Vec2d(LABEL.getWidth()*102/256.0, LABEL.getHeight()*6/32.0)); + buttonPlay.setPos(pos.add(new Vec2d(LABEL.getWidth()*10/256.0, LABEL.getHeight()*6/32.0))); + buttonDelete.setPos(pos.add(new Vec2d(LABEL.getWidth()*226/256.0, LABEL.getHeight()*6/32.0))); } public void onPlayPressed() { @@ -42,9 +44,19 @@ public class GUISavesCard implements GUIComponent @Override public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover) { - LABEL.setModel(Matrix4.multiply(Matrix4.translate(pos.x, pos.y, 0), matrix)); + Matrix4 label_matrix = Matrix4.multiply(Matrix4.translate(pos.x, pos.y, 0), matrix); + + LABEL.setModel(label_matrix); LABEL.render(); + Matrix4 text_matrix = label_matrix; + text_matrix = Matrix4.multiply(text_matrix, Matrix4.translate( + LABEL.getWidth() * 38 / 256.0, + LABEL.getHeight() / 2 - 0.25, 0)); + text_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(0.5, 0.5, 0.5)), text_matrix); + + Text.render(text, text_matrix); + buttonDelete.render(matrix, mousePos, canHover); buttonPlay.render(matrix, mousePos, canHover); } @@ -57,8 +69,7 @@ public class GUISavesCard implements GUIComponent @Override public boolean checkMouseHover(Vec2d pos) { - return (this.pos.x > pos.x && this.pos.x + LABEL.getWidth() < pos.x && - this.pos.y > pos.y && this.pos.y + LABEL.getHeight() < pos.y); + return true; } @Override diff --git a/src/projectzombie/menu/gui/GUITextBox.java b/src/projectzombie/menu/gui/GUITextBox.java new file mode 100644 index 0000000..4ccd63a --- /dev/null +++ b/src/projectzombie/menu/gui/GUITextBox.java @@ -0,0 +1,243 @@ +package projectzombie.menu.gui; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; + +import org.lwjgl.opengl.GL33; + +import gl_engine.matrix.Matrix4; +import gl_engine.vec.Vec2d; +import gl_engine.vec.Vec3d; +import projectzombie.Main; +import projectzombie.init.Models; +import projectzombie.input.types.InputGUI; +import projectzombie.input.types.InputGUITextBox; +import projectzombie.model.ModelGui; +import projectzombie.text.Text; + +public class GUITextBox implements GUIComponent, InputGUITextBox +{ + private static final ModelGui BOX = Models.UI_TEXT_BOX; + private static final ModelGui CURSOR = Models.UI_TEXT_CURSOR; + + private Vec2d pos; + private String text = ""; + private int cursor_pos = 0; + private boolean in_focus = false; + private double offset = 0; + private int max; + + public GUITextBox(Vec2d pos, int max) { + this.pos = pos; + this.max = max; + } + + public GUITextBox(Vec2d pos, boolean max) { + this(pos, max ? 22 : -1); + } + + public GUITextBox(Vec2d pos) { + this(pos, -1); + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + @Override + public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover) + { + Matrix4 box_matrix = Matrix4.multiply(matrix, Matrix4.translate(pos.x, pos.y, 0)); + + BOX.setModel(box_matrix); + BOX.render(); + + // Set text to black and make sure text gets clipped outside the text box + GL33.glUniform4f(Main.window.glsl_color, 0.1f, 0.1f, 0.1f, 1); + GL33.glUniform4f(Main.window.glsl_discard_coords, + (float)(pos.x + BOX.getWidth() * 2 / 128.0), + (float)(pos.y + BOX.getHeight() * 2 / 16.0), + (float)(pos.x + BOX.getWidth() * 126 / 128.0), + (float)(pos.y + BOX.getHeight() * 14 / 16.0)); + GL33.glUniform1i(Main.window.glsl_do_discard_coords, 1); + + Matrix4 text_matrix = box_matrix; + text_matrix = Matrix4.multiply(text_matrix, Matrix4.translate((1 - offset) * 0.5, 0.5, 0)); + text_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(0.5, 0.5, 0.5)), text_matrix); + + Text.render(text, text_matrix); + + if(in_focus) { + CURSOR.setModel(Matrix4.multiply(text_matrix, Matrix4.translate(cursor_pos * 0.5, 0, 0))); + CURSOR.render(); + } + + // Reset the settings back to default + GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1); + GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0); + } + + @Override + public void update(Vec2d mousePos) { + } + + @Override + public boolean checkMouseHover(Vec2d mousePos) { + return (mousePos.x > this.pos.x && mousePos.x < this.pos.x + BOX.getWidth() && + mousePos.y > this.pos.y && mousePos.y < this.pos.y + BOX.getHeight()); + } + + @Override + public void onMouseClick(Vec2d mousePos) + { + ((InputGUI)Main.menu.input).getGUI().setTextBox(this); + in_focus = true; + + cursor_pos = (int)((mousePos.x - pos.x + offset * 0.5 - 0.5) * 2 + 0.5); + + if(cursor_pos > text.length()) { + cursor_pos = text.length(); + } + } + + private void updateText() + { + // Update the text fields offset to + // keep the cursor in the text field + double o = BOX.getWidth() - 1; + + if(cursor_pos - o < offset) { + offset = cursor_pos - o; + } + + if(cursor_pos - o * 2 > offset) { + offset = cursor_pos - o * 2; + } + + if(offset < 0) { + offset = 0; + } + } + + @Override + public void onPaste() + { + try + { + String clipboard = (String)(Main.clipboard.getData(DataFlavor.stringFlavor)); + + if(max == -1 || text.length() + clipboard.length() <= max) + { + text = text.substring(0, cursor_pos) + clipboard + text.substring(cursor_pos, text.length()); + cursor_pos += clipboard.length(); + + updateText(); + } + + else if(text.length() < max) + { + clipboard = clipboard.substring(0, max - text.length()); + + text = text.substring(0, cursor_pos) + clipboard + text.substring(cursor_pos, text.length()); + cursor_pos += clipboard.length(); + + updateText(); + } + } + + catch (UnsupportedFlavorException | IOException e) { + e.printStackTrace(); + } + } + + @Override + public void onBackspace() + { + if(cursor_pos == 0) { + return; + } + + text = text.substring(0, cursor_pos - 1) + text.substring(cursor_pos, text.length()); + cursor_pos -= 1; + + updateText(); + } + + @Override + public void onDelete() + { + if(cursor_pos == text.length()) { + return; + } + + text = text.substring(0, cursor_pos) + text.substring(cursor_pos + 1, text.length()); + + updateText(); + } + + @Override + public void onMoveCursor(int direction) + { + cursor_pos += direction; + + if(cursor_pos < 0) { + cursor_pos = 0; + } + + if(cursor_pos > text.length()) { + cursor_pos = text.length(); + } + + updateText(); + } + + @Override + public void onHome() { + cursor_pos = 0; + updateText(); + } + + @Override + public void onEnd() { + cursor_pos = text.length(); + updateText(); + } + + @Override + public void onPressed(char character) + { + if(max == -1 || text.length() < max) + { + text = text.substring(0, cursor_pos) + character + text.substring(cursor_pos, text.length()); + cursor_pos += 1; + + updateText(); + } + } + + @Override + public void setFocus(boolean focus) { + in_focus = focus; + } + + @Override + public void onScroll(Vec2d mousePos, double amount) { + } + + @Override + public void onRightClick(Vec2d mousePos) { + } + + @Override + public void onActivate() { + } + + @Override + public void onBack() { + } +} diff --git a/src/projectzombie/model/Model.java b/src/projectzombie/model/Model.java index db68cf7..331f30f 100644 --- a/src/projectzombie/model/Model.java +++ b/src/projectzombie/model/Model.java @@ -19,14 +19,13 @@ import gl_engine.MathHelpers; import gl_engine.matrix.Matrix4; import gl_engine.texture.TextureRef3D; import projectzombie.Main; -import projectzombie.init.Models; import projectzombie.init.Resources; public abstract class Model implements IModel { private static final Random rand = new Random(); - public static final float OFFSET = 0.001f; + public static final float OFFSET = 0.00001f; public static final int SIZE = 16; public static IModel bound = null; diff --git a/src/projectzombie/model/ModelGrass.java b/src/projectzombie/model/ModelGrass.java index bd9bdcb..e6c8642 100644 --- a/src/projectzombie/model/ModelGrass.java +++ b/src/projectzombie/model/ModelGrass.java @@ -1,6 +1,5 @@ package projectzombie.model; -import gl_engine.texture.TextureRef3D; import projectzombie.init.Resources; public class ModelGrass extends ModelTile diff --git a/src/projectzombie/model/ModelRock.java b/src/projectzombie/model/ModelRock.java index ca93b46..b94bb6d 100644 --- a/src/projectzombie/model/ModelRock.java +++ b/src/projectzombie/model/ModelRock.java @@ -1,7 +1,6 @@ package projectzombie.model; import gl_engine.texture.TextureRef3D; -import gl_engine.vec.Vec2d; public class ModelRock extends Model { diff --git a/src/projectzombie/model/ModelTallGrass.java b/src/projectzombie/model/ModelTallGrass.java index ba2a44f..3f1591d 100644 --- a/src/projectzombie/model/ModelTallGrass.java +++ b/src/projectzombie/model/ModelTallGrass.java @@ -1,6 +1,5 @@ package projectzombie.model; -import gl_engine.texture.TextureRef3D; import projectzombie.init.Resources; public class ModelTallGrass extends ModelCross diff --git a/src/projectzombie/settings/Settings.java b/src/projectzombie/settings/Settings.java index bcc74ee..4161bcf 100755 --- a/src/projectzombie/settings/Settings.java +++ b/src/projectzombie/settings/Settings.java @@ -1,21 +1,18 @@ package projectzombie.settings; -import bdf.classes.BdfClassManager; import bdf.classes.IBdfClassManager; import bdf.file.BdfFileManager; import bdf.types.BdfNamedList; import bdf.types.BdfObject; import bdf.types.BdfTypes; -import projectzombie.Main; import projectzombie.display.DisplayRender; import projectzombie.display.DisplayRenderUI; import projectzombie.display.DisplayWindow; -import projectzombie.entity.EntityParticle; import projectzombie.world.chunk.Chunk; public class Settings implements IBdfClassManager { - public static final BdfClassManager SETTINGS = new BdfClassManager(new Settings()); + public static final Settings SETTINGS = new Settings(); private static BdfFileManager FILE_MANAGER; @Override @@ -114,21 +111,21 @@ public class Settings implements IBdfClassManager } BdfNamedList nl = bdf.getNamedList(); - nl.set("render_distance", BdfObject.withInteger(Chunk.RENDER_DISTANCE)); - nl.set("show_fps", BdfObject.withBoolean(DisplayRenderUI.showFPS)); - nl.set("debug", BdfObject.withBoolean(DisplayRenderUI.debug)); - nl.set("shadow_size", BdfObject.withInteger(shadow_size)); - nl.set("fullscreen", BdfObject.withBoolean(DisplayWindow.fullscreen)); - nl.set("vsync", BdfObject.withBoolean(DisplayWindow.vsync)); + nl.set("render_distance", bdf.newObject().setInteger(Chunk.RENDER_DISTANCE)); + nl.set("show_fps", bdf.newObject().setBoolean(DisplayRenderUI.showFPS)); + nl.set("debug", bdf.newObject().setBoolean(DisplayRenderUI.debug)); + nl.set("shadow_size", bdf.newObject().setInteger(shadow_size)); + nl.set("fullscreen", bdf.newObject().setBoolean(DisplayWindow.fullscreen)); + nl.set("vsync", bdf.newObject().setBoolean(DisplayWindow.vsync)); } public static void init() { FILE_MANAGER = new BdfFileManager(Environment.gdir + "/settings.bdf", true); - SETTINGS.load(FILE_MANAGER); + SETTINGS.BdfClassLoad(FILE_MANAGER.getObject()); } public static void update() { - SETTINGS.save(FILE_MANAGER); + SETTINGS.BdfClassSave(FILE_MANAGER.getObject()); FILE_MANAGER.saveDatabase(); } diff --git a/src/projectzombie/task/Task.java b/src/projectzombie/task/Task.java index c173d57..c8fe267 100644 --- a/src/projectzombie/task/Task.java +++ b/src/projectzombie/task/Task.java @@ -2,14 +2,12 @@ package projectzombie.task; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; import bdf.classes.IBdfClassManager; import bdf.types.BdfArray; import bdf.types.BdfNamedList; import bdf.types.BdfObject; import projectzombie.entity.Entity; -import projectzombie.init.Entities; import projectzombie.init.Tasks; public abstract class Task implements IBdfClassManager @@ -50,7 +48,7 @@ public abstract class Task implements IBdfClassManager // Send back null if the id is out of range if(id < 0 || id >= Tasks.TASKS.size()) { - System.out.println("Warning: Invalid ID detected: " + id); + System.out.println("Invalid task ID found: " + id); return null; } @@ -85,7 +83,7 @@ public abstract class Task implements IBdfClassManager @Override public void BdfClassSave(BdfObject bdf) { BdfNamedList nl = bdf.getNamedList(); - nl.set("id", BdfObject.withInteger(getID())); + nl.set("id", bdf.newObject().setInteger(getID())); } public static Task[] loadTasks(Entity parent, BdfObject bdf) @@ -100,16 +98,17 @@ public abstract class Task implements IBdfClassManager return tasks; } - public static BdfObject saveTasks(Task[] tasks) + public static BdfObject saveTasks(BdfObject bdf, Task[] tasks) { - BdfArray array = new BdfArray(); + BdfArray array = bdf.getArray(); + bdf.setArray(array); for(int i=0;i'): l = CHAR_G_THAN; break; case('<'): l = CHAR_L_THAN; break; + case('`'): l = CHAR_GRAVE; break; + case('~'): l = CHAR_TILDE; break; + case('\''): l = CHAR_APOSTROPHE; break; + case('"'): l = CHAR_QUOTATION; break; + case(';'): l = CHAR_SEMICOLON; break; + case('@'): l = CHAR_AT; break; + case('&'): l = CHAR_AND; break; + case('*'): l = CHAR_STAR; break; + case('^'): l = CHAR_POW; break; + case('['): l = CHAR_BRACKET_OS; break; + case(']'): l = CHAR_BRACKET_CS; break; + case('{'): l = CHAR_BRACKET_OC; break; + case('}'): l = CHAR_BRACKET_CC; break; } if(l != null) diff --git a/src/projectzombie/tiles/TileGrass.java b/src/projectzombie/tiles/TileGrass.java index 2ddbc6b..95aae73 100755 --- a/src/projectzombie/tiles/TileGrass.java +++ b/src/projectzombie/tiles/TileGrass.java @@ -1,6 +1,5 @@ package projectzombie.tiles; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2i; import projectzombie.init.Models; import projectzombie.init.Tiles; diff --git a/src/projectzombie/tiles/TileLadderUp.java b/src/projectzombie/tiles/TileLadderUp.java index 21890f6..44e7f24 100755 --- a/src/projectzombie/tiles/TileLadderUp.java +++ b/src/projectzombie/tiles/TileLadderUp.java @@ -1,16 +1,13 @@ package projectzombie.tiles; import gl_engine.vec.Vec2i; -import mainloop.task.IMainloopTask; import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; -import projectzombie.mainloop.MainloopEventHandler; import projectzombie.model.Model; import projectzombie.task.TaskLadderUp; import projectzombie.util.math.TileState; -import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.layer.Layer; public class TileLadderUp extends Tile diff --git a/src/projectzombie/tiles/TilePortalDown.java b/src/projectzombie/tiles/TilePortalDown.java index 527bbed..4cb6115 100755 --- a/src/projectzombie/tiles/TilePortalDown.java +++ b/src/projectzombie/tiles/TilePortalDown.java @@ -1,16 +1,13 @@ package projectzombie.tiles; import gl_engine.vec.Vec2i; -import mainloop.task.IMainloopTask; import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; -import projectzombie.mainloop.MainloopEventHandler; import projectzombie.model.Model; import projectzombie.task.TaskLadderDown; import projectzombie.util.math.TileState; -import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.layer.Layer; public class TilePortalDown extends Tile diff --git a/src/projectzombie/tiles/TileRock.java b/src/projectzombie/tiles/TileRock.java index 12e6561..31a892d 100755 --- a/src/projectzombie/tiles/TileRock.java +++ b/src/projectzombie/tiles/TileRock.java @@ -1,16 +1,11 @@ package projectzombie.tiles; -import gl_engine.vec.Vec2i; -import gl_engine.vec.Vec3d; -import projectzombie.entity.Entity; -import projectzombie.entity.EntityItem; import projectzombie.init.Items; import projectzombie.init.Models; import projectzombie.items.ItemTool; import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import projectzombie.util.math.TileState; -import projectzombie.world.layer.Layer; public class TileRock extends Tile implements TileBulletBreakable { diff --git a/src/projectzombie/tiles/TileTree.java b/src/projectzombie/tiles/TileTree.java index a85bc75..a9dffbc 100755 --- a/src/projectzombie/tiles/TileTree.java +++ b/src/projectzombie/tiles/TileTree.java @@ -1,14 +1,11 @@ package projectzombie.tiles; -import gl_engine.vec.Vec2i; -import projectzombie.entity.Entity; import projectzombie.init.Items; import projectzombie.init.Models; import projectzombie.items.ItemTool; import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import projectzombie.util.math.TileState; -import projectzombie.world.layer.Layer; public class TileTree extends Tile implements TileBulletBreakable { diff --git a/src/projectzombie/tiles/TileWater.java b/src/projectzombie/tiles/TileWater.java index b3845eb..a2dd176 100755 --- a/src/projectzombie/tiles/TileWater.java +++ b/src/projectzombie/tiles/TileWater.java @@ -1,7 +1,6 @@ package projectzombie.tiles; import gl_engine.vec.Vec2i; -import gl_engine.vec.Vec3d; import projectzombie.entity.Entity; import projectzombie.entity.particle.ParticleWater; import projectzombie.entity.player.EntityPlayer; diff --git a/src/projectzombie/util/math/ItemStack.java b/src/projectzombie/util/math/ItemStack.java index f8667b2..b4366c3 100755 --- a/src/projectzombie/util/math/ItemStack.java +++ b/src/projectzombie/util/math/ItemStack.java @@ -46,9 +46,9 @@ public class ItemStack implements IBdfClassManager @Override public void BdfClassSave(BdfObject bdf) { BdfNamedList nl = bdf.getNamedList(); - nl.set("meta", BdfObject.withShort(meta)); - nl.set("count", BdfObject.withInteger(count)); - nl.set("item", BdfObject.withInteger(item.id)); + nl.set("meta", bdf.newObject().setShort(meta)); + nl.set("count", bdf.newObject().setInteger(count)); + nl.set("item", bdf.newObject().setInteger(item.id)); } public ItemStack(BdfObject bdf) { diff --git a/src/projectzombie/worker/Worker.java b/src/projectzombie/worker/Worker.java index e7ce624..28d65c6 100644 --- a/src/projectzombie/worker/Worker.java +++ b/src/projectzombie/worker/Worker.java @@ -6,9 +6,10 @@ import java.io.OutputStream; import java.lang.ProcessBuilder.Redirect; import java.nio.ByteBuffer; -import bdf.data.BdfDatabase; +import bdf.data.IBdfDatabase; import bdf.types.BdfNamedList; import bdf.types.BdfObject; +import bdf.types.BdfReader; import projectzombie.display.DisplayLighting; public class Worker extends Thread @@ -24,9 +25,9 @@ public class Worker extends Thread public Worker() throws IOException { pb = new ProcessBuilder("java", "-jar", "worker.jar"); - pb.redirectError(Redirect.INHERIT); pb.redirectOutput(Redirect.PIPE); pb.redirectInput(Redirect.PIPE); + pb.redirectError(Redirect.INHERIT); process = pb.start(); @@ -38,39 +39,41 @@ public class Worker extends Thread public void processLighting(float[] lights, int width, int height, int x, int y) { - BdfObject bdf = new BdfObject(); + BdfReader reader = new BdfReader(); + BdfObject bdf = reader.getObject(); BdfNamedList nl = bdf.getNamedList(); - nl.set("task", BdfObject.withString("light")); - nl.set("light", BdfObject.withFloatArray(lights)); - nl.set("w", BdfObject.withInteger(width)); - nl.set("h", BdfObject.withInteger(height)); - nl.set("x", BdfObject.withInteger(x)); - nl.set("y", BdfObject.withInteger(y)); + nl.set("task", bdf.newObject().setString("light")); + nl.set("light", bdf.newObject().setFloatArray(lights)); + nl.set("w", bdf.newObject().setInteger(width)); + nl.set("h", bdf.newObject().setInteger(height)); + nl.set("x", bdf.newObject().setInteger(x)); + nl.set("y", bdf.newObject().setInteger(y)); - sendData(bdf); + sendData(reader); } public void updateTime() { - BdfObject bdf = new BdfObject(); + BdfReader reader = new BdfReader(); + BdfObject bdf = reader.getObject(); BdfNamedList nl = bdf.getNamedList(); - nl.set("task", BdfObject.withString("time")); - nl.set("millis", BdfObject.withLong(System.currentTimeMillis())); + nl.set("task", bdf.newObject().setString("time")); + nl.set("millis", bdf.newObject().setLong(System.currentTimeMillis())); - sendData(bdf); + sendData(reader); } - private void sendData(BdfObject bdf) + private void sendData(BdfReader reader) { - byte[] data = bdf.serialize().getBytes(); + IBdfDatabase data = reader.serialize(); ByteBuffer size_buff = ByteBuffer.allocate(4); - size_buff.putInt(0, data.length); + size_buff.putInt(0, data.size()); try { out.write(size_buff.array()); - out.write(data); + data.writeToStream(out); out.write('\n'); out.flush(); } @@ -97,7 +100,8 @@ public class Worker extends Thread in.read(data); in.read(new byte[1]); - BdfObject bdf = new BdfObject(new BdfDatabase(data)); + BdfReader reader = new BdfReader(data); + BdfObject bdf = reader.getObject(); BdfNamedList nl = bdf.getNamedList(); switch(nl.get("task").getString()) diff --git a/src/projectzombie/world/World.java b/src/projectzombie/world/World.java index 787c7e8..f5f01fa 100755 --- a/src/projectzombie/world/World.java +++ b/src/projectzombie/world/World.java @@ -1,13 +1,15 @@ package projectzombie.world; +import java.io.File; import java.nio.ByteBuffer; -import java.nio.FloatBuffer; import java.util.ArrayList; +import java.util.Random; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL33; import bdf.classes.IBdfClassManager; +import bdf.file.BdfFileManager; import bdf.types.BdfArray; import bdf.types.BdfNamedList; import bdf.types.BdfObject; @@ -16,7 +18,10 @@ import gl_engine.vec.Vec3d; import projectzombie.Main; import projectzombie.display.Camera; import projectzombie.display.DisplayLighting; +import projectzombie.display.bossbar.BossBars; import projectzombie.entity.player.EntityPlayer; +import projectzombie.init.LayerGenerators; +import projectzombie.init.Layers; import projectzombie.model.Model; import projectzombie.time.GameTimer; import projectzombie.world.chunk.ChunkEventHandler; @@ -28,6 +33,7 @@ public class World implements IBdfClassManager private Layer loaded; private ArrayList layers = new ArrayList(); + private BdfFileManager file_manager; private String path; private int pool_vao, pool_vbo, pool_ibo; @@ -37,6 +43,48 @@ public class World implements IBdfClassManager public World(String path) { this.path = path; + + if(path != null) + { + path = "./saves/" + path + ".bdf"; + File save_file = new File(path); + File save_dir = save_file.getParentFile(); + + if(!save_dir.exists()) { + save_dir.mkdirs(); + } + + if(save_file.exists()) { + file_manager = new BdfFileManager(path); + BdfClassLoad(file_manager.getObject()); + } + + else { + file_manager = new BdfFileManager(path); + } + } + } + + public static void createWorld(String path, long seed) + { + // Create all the layers + Layers.EARTH = new Layer(new Random(seed), LayerGenerators.EARTH); + Layers.CAVES = new Layer(new Random(seed), LayerGenerators.CAVES); + Layers.LAVA_CAVES = new Layer(new Random(seed), LayerGenerators.LAVA_CAVES); + + // Create the world and set the earth as the default layer + Main.world = new World(path); + Main.world.addLayer(Layers.EARTH); + Main.world.addLayer(Layers.CAVES); + Main.world.addLayer(Layers.LAVA_CAVES); + Main.world.setLayer(0); + + // Initialize some other objects + Main.player = new EntityPlayer(); + GameTimer.resetTime(); + BossBars.clear(); + + Main.world.save(); } public String getSavePath() { @@ -181,6 +229,24 @@ public class World implements IBdfClassManager public Layer getLayer() { return loaded; } + + public void save() + { + if(file_manager != null) + { + BdfObject bdf = file_manager.resetObject(); + BdfClassSave(bdf); + + file_manager.saveDatabase(); + } + } + + public void free() + { + for(Layer layer : layers) { + layer.free(); + } + } @Override public void BdfClassLoad(BdfObject bdf) @@ -219,32 +285,25 @@ public class World implements IBdfClassManager } // Save layer data - BdfArray layers_bdf = new BdfArray(); - nl.set("loaded", BdfObject.withInteger(loaded_id)); - nl.set("layers", BdfObject.withArray(layers_bdf)); + BdfArray layers_bdf = bdf.newArray(); + nl.set("loaded", bdf.newObject().setInteger(loaded_id)); + nl.set("layers", bdf.newObject().setArray(layers_bdf)); for(Layer l : layers) { - BdfObject o = new BdfObject(); + BdfObject o = bdf.newObject(); l.BdfClassSave(o); layers_bdf.add(o); } // Save player data - BdfArray players = new BdfArray(); - nl.set("players", BdfObject.withArray(players)); + BdfArray players = bdf.newArray(); + nl.set("players", bdf.newObject().setArray(players)); - BdfObject player = new BdfObject(); + BdfObject player = bdf.newObject(); Main.player.BdfClassSave(player); players.add(player); // Save the game timer - nl.set("time", BdfObject.withLong(GameTimer.getTime())); - } - - public void free() - { - for(Layer layer : layers) { - layer.free(); - } + nl.set("time", bdf.newObject().setLong(GameTimer.getTime())); } } diff --git a/src/projectzombie/world/chunk/Chunk.java b/src/projectzombie/world/chunk/Chunk.java index 0ece4c1..1532004 100755 --- a/src/projectzombie/world/chunk/Chunk.java +++ b/src/projectzombie/world/chunk/Chunk.java @@ -49,8 +49,7 @@ public class Chunk implements IBdfClassManager private Tile tiles_front[] = new Tile[CHUNK_INDEX]; private byte tiles_front_meta[] = new byte[CHUNK_INDEX]; private byte tiles_back_meta[] = new byte[CHUNK_INDEX]; - private byte tiles_lighting_src[] = new byte[CHUNK_INDEX]; - private byte tiles_lighting_day[] = new byte[CHUNK_INDEX]; + private byte tiles_lighting[] = new byte[CHUNK_INDEX]; public ArrayList entities = new ArrayList(); private Layer layer; public Vec2i c_pos; @@ -93,10 +92,10 @@ public class Chunk implements IBdfClassManager BdfNamedList nl = bdf.getNamedList(); // Load all the tiles and meta - short[] tb = nl.get("tb").getShortArray(); - short[] tf = nl.get("tf").getShortArray(); - byte[] mb = nl.get("mb").getByteArray(); - byte[] mf = nl.get("mf").getByteArray(); + short[] tb = nl.get("tilesBack").getShortArray(); + short[] tf = nl.get("tilesFront").getShortArray(); + byte[] mb = nl.get("metaBack").getByteArray(); + byte[] mf = nl.get("metaFront").getByteArray(); for(int i=0;i chunk : dirty_chunks) { - BdfNamedList chunk_nl = new BdfNamedList(); + BdfNamedList chunk_nl = bdf.newNamedList(); chunk.pos.BdfClassSave(chunk_nl.get("pos")); chunk.o.BdfClassSave(chunk_nl.get("chunk")); - bdf_chunks.add(BdfObject.withNamedList(chunk_nl)); + bdf_chunks.add(bdf.newObject().setNamedList(chunk_nl)); } for(Map2DElement chunk : chunks) { @@ -330,10 +313,10 @@ public class Layer implements IBdfClassManager if(!chunk.o.isDirty()) continue; - BdfNamedList chunk_nl = new BdfNamedList(); + BdfNamedList chunk_nl = bdf.newNamedList(); chunk.pos.BdfClassSave(chunk_nl.get("pos")); chunk.o.BdfClassSave(chunk_nl.get("chunk")); - bdf_chunks.add(BdfObject.withNamedList(chunk_nl)); + bdf_chunks.add(bdf.newObject().setNamedList(chunk_nl)); } } diff --git a/src/projectzombie/world/layer/layergen/LayerGenBossArena.java b/src/projectzombie/world/layer/layergen/LayerGenBossArena.java index 7da37f0..2beec19 100755 --- a/src/projectzombie/world/layer/layergen/LayerGenBossArena.java +++ b/src/projectzombie/world/layer/layergen/LayerGenBossArena.java @@ -2,7 +2,6 @@ package projectzombie.world.layer.layergen; import java.util.Random; -import gl_engine.MathHelpers; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2i; import gl_engine.vec.Vec3d; @@ -19,7 +18,6 @@ import projectzombie.world.layer.Layer; public class LayerGenBossArena extends LayerGen implements LayerGenRememberPlayerPos { - private final Vec2i center = new Vec2i(0, 0); private final int size = 10; private Vec3d player_pos = new Vec3d(0, 0, 0); private Random rand = new Random(); diff --git a/src/projectzombie/world/layer/layergen/LayerGenCaves.java b/src/projectzombie/world/layer/layergen/LayerGenCaves.java index 5165308..b749816 100755 --- a/src/projectzombie/world/layer/layergen/LayerGenCaves.java +++ b/src/projectzombie/world/layer/layergen/LayerGenCaves.java @@ -15,7 +15,6 @@ import projectzombie.util.math.ColorRange; import projectzombie.util.math.TileState; import projectzombie.util.math.random.NoiseGenerator; import projectzombie.util.math.random.NoiseGeneratorSimplex; -import projectzombie.util.math.random.OpenSimplexNoise; import projectzombie.util.math.random.RandomHelpers; import projectzombie.world.World; import projectzombie.world.chunk.Chunk; diff --git a/src/projectzombie/world/layer/layergen/LayerGenEarth.java b/src/projectzombie/world/layer/layergen/LayerGenEarth.java index 9fff91f..6e810c7 100755 --- a/src/projectzombie/world/layer/layergen/LayerGenEarth.java +++ b/src/projectzombie/world/layer/layergen/LayerGenEarth.java @@ -10,7 +10,6 @@ import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.EntityZombie; import projectzombie.init.Tiles; -import projectzombie.tiles.Tile; import projectzombie.time.GameTimer; import projectzombie.util.math.ColorRange; import projectzombie.util.math.TileState; diff --git a/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java b/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java index 5e3374b..b326de5 100755 --- a/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java +++ b/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java @@ -14,7 +14,6 @@ import projectzombie.util.math.ColorRange; import projectzombie.util.math.TileState; import projectzombie.util.math.random.NoiseGenerator; import projectzombie.util.math.random.NoiseGeneratorSimplex; -import projectzombie.util.math.random.OpenSimplexNoise; import projectzombie.util.math.random.RandomHelpers; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; diff --git a/src/resources/shader/environmentRenderer.fsh b/src/resources/shader/environmentRenderer.fsh index e9a3799..994933d 100644 --- a/src/resources/shader/environmentRenderer.fsh +++ b/src/resources/shader/environmentRenderer.fsh @@ -35,7 +35,7 @@ vec3 color_grass_hot_dry = vec3(1, 0.6, 0); vec3 color_grass_cold_wet = vec3(0.075, 0.533, 0.047); vec3 color_grass_cold_dry = vec3(0.812, 0.761, 0); -float depth_c = 0.001; +float depth_c = 0.0001; float map(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; @@ -81,11 +81,11 @@ void main() vec3 light_day = pSunDepth.z < (texture(depthmap, sunDepthTexPos).r * 2 - 1 + depth_c ) ? lighting_day_high : lighting_day_low; - vec3 light_src = vec3(1, 1, 1) * (scaleLight(max(0, light.g)) - abs(pLightMapPos.y) * 0.1); + vec3 light_src = vec3(1, 1, 1) * (scaleLight(max(0, light.r)) - abs(pLightMapPos.y) * 0.1); vec4 rgb = vec4((pRGB % 64) / 64.0, ((pRGB >> 6) % 64) / 64.0, ((pRGB >> 12) % 64) / 64.0, 1); vec4 color_grass = vec4(interpolate2RGB( - smoothStep(light.b), smoothStep(light.a), + smoothStep(light.g), smoothStep(light.b), color_grass_cold_dry, color_grass_hot_dry, color_grass_cold_wet, color_grass_hot_wet), 1); diff --git a/src/resources/texture/gui/selection_box.png b/src/resources/texture/gui/selection_box.png deleted file mode 100644 index 596591b..0000000 Binary files a/src/resources/texture/gui/selection_box.png and /dev/null differ diff --git a/src/resources/texture/gui/selection_box_big.png b/src/resources/texture/gui/selection_box_big.png new file mode 100644 index 0000000..b88768f Binary files /dev/null and b/src/resources/texture/gui/selection_box_big.png differ diff --git a/src/resources/texture/gui/selection_box_wide.png b/src/resources/texture/gui/selection_box_wide.png new file mode 100644 index 0000000..b053a7b Binary files /dev/null and b/src/resources/texture/gui/selection_box_wide.png differ diff --git a/src/resources/texture/gui/text_box.png b/src/resources/texture/gui/text_box.png new file mode 100644 index 0000000..11d8b30 Binary files /dev/null and b/src/resources/texture/gui/text_box.png differ diff --git a/src/resources/texture/gui/text_cursor.png b/src/resources/texture/gui/text_cursor.png new file mode 100644 index 0000000..0546dcb Binary files /dev/null and b/src/resources/texture/gui/text_cursor.png differ diff --git a/src/resources/texture/list.txt b/src/resources/texture/list.txt index 9783435..e790977 100644 --- a/src/resources/texture/list.txt +++ b/src/resources/texture/list.txt @@ -1,216 +1,232 @@ -./tile/hemp6.png -./tile/hemp7.png -./tile/hemp1.png -./tile/rock.png -./tile/rock_ice.png -./tile/sapling3.png -./tile/ladder.png -./tile/tree_leaves_snow.png -./tile/ice_wall.png -./tile/water.png -./tile/sandstone_wall.png -./tile/ladder_up.png -./tile/cactus4.png -./tile/tall_grass.png -./tile/cactus2.png -./tile/grass_infested.png -./tile/tree_branch_leaves.png -./tile/dirt.png -./tile/wall.png -./tile/tree_base.png -./tile/cactus1.png -./tile/sapling4.png -./tile/hemp3.png -./tile/cactus_top.png -./tile/tunnel_down.png -./tile/stone.png -./tile/snow.png -./tile/boss_portal.png -./tile/hemp4.png -./tile/sand.png -./tile/lantern.png -./tile/ice.png -./tile/sapling1.png -./tile/chest.png -./tile/hemp2.png -./tile/hemp8.png -./tile/cactus3.png -./tile/lava.png -./tile/tree_leaves.png -./tile/hemp5.png -./tile/lava_flow.png -./tile/grass.png -./tile/tree_branch.png -./tile/sandstone.png -./tile/tree_branch_leaves_snow.png -./tile/rock_sandstone.png -./tile/sapling2.png +./text/char_question.png +./text/char_l_a.png +./text/char_u_j.png +./text/char_l_u.png +./text/char_u_s.png +./text/char_l_s.png +./text/char_apostrophe.png +./text/char_plus.png +./text/char_l_e.png +./text/char_7.png +./text/char_minus.png +./text/char_u_r.png +./text/char_u_l.png +./text/char_obracket.png +./text/char_pow.png +./text/char_u_m.png +./text/char_l_t.png +./text/char_percent.png +./text/char_l_y.png +./text/char_0.png +./text/char_4.png +./text/char_l_r.png +./text/char_l_m.png +./text/char_cbracket.png +./text/char_u_g.png +./text/char_u_q.png +./text/char_u_i.png +./text/char_tilde.png +./text/char_l_w.png +./text/char_l_v.png +./text/char_fslash.png +./text/char_u_p.png +./text/char_gthan.png +./text/char_8.png +./text/char_unknown.png +./text/char_and.png +./text/char_osbracket.png +./text/char_u_n.png +./text/char_l_i.png +./text/char_u_y.png +./text/char_l_p.png +./text/char_lthan.png +./text/char_l_g.png +./text/char_bslash.png +./text/char_1.png +./text/char_u_z.png +./text/char_l_f.png +./text/char_u_w.png +./text/char_9.png +./text/char_l_x.png +./text/char_ccbracket.png +./text/char_l_o.png +./text/char_equals.png +./text/char_l_d.png +./text/char_dollar.png +./text/char_hashtag.png +./text/char_l_q.png +./text/char_u_o.png +./text/char_6.png +./text/char_u_d.png +./text/char_u_e.png +./text/char_exclamation.png +./text/char_vertical.png +./text/char_ocbracket.png +./text/char_u_k.png +./text/char_u_c.png +./text/char_l_n.png +./text/char_semicolon.png +./text/char_u_b.png +./text/char_u_f.png +./text/char_l_h.png +./text/char_l_k.png +./text/char_u_t.png +./text/char_3.png +./text/char_u_v.png +./text/char_u_h.png +./text/char_quotation.png +./text/char_u_a.png +./text/char_l_b.png +./text/char_underscore.png +./text/char_u_x.png +./text/char_comma.png +./text/char_csbracket.png +./text/char_l_l.png +./text/char_5.png +./text/char_star.png +./text/char_colon.png +./text/char_l_z.png +./text/char_space.png +./text/char_2.png +./text/char_at.png +./text/char_grave.png +./text/char_l_j.png +./text/char_fullstop.png +./text/char_l_c.png +./text/char_u_u.png ./list.txt -./item/log.png -./item/rock.png -./item/acorn.png -./item/ammo_box.png -./item/plant_fibre.png -./item/hemp_seed.png -./item/shield_upgrade.png -./item/grappling_hook.png -./item/log_snow.png -./item/health_potion.png -./item/snow_pile.png -./item/gun_upgrade.png -./item/sandstone.png -./item/flint.png +./player/player_white_front_moving.png +./player/player_white_back_moving.png +./player/player_black_back_moving.png +./player/player_black_back_still.png ./player/player_white_back_still.png ./player/player_white_front_still.png ./player/player_black_front_moving.png ./player/player_black_front_still.png -./player/player_black_back_moving.png -./player/player_black_back_still.png -./player/player_white_back_moving.png -./player/player_white_front_moving.png -./gui/pixel_white.png -./gui/water.png -./gui/gun.png -./gui/button_delete.png -./gui/button_delete_hover.png -./gui/slot_armor_chest.png -./gui/pixel_black.png -./gui/slot_clothing_shirt.png -./gui/button_play.png -./gui/slot_armor_legs.png -./gui/inventory.png -./gui/selection_box.png -./gui/label.png -./gui/slot_clothing_pants.png -./gui/health_empty.png -./gui/hotbar_selected.png -./gui/health_full.png +./particle/smoke_trail.png +./particle/water.png +./particle/smoke_0.png +./particle/smoke_1.png +./particle/blood.png +./particle/lava.png +./particle/bullet.png +./particle/smoke_2.png +./particle/snow.png +./particle/rain.png +./particle/smoke_4.png +./particle/smoke_3.png +./particle/smoke_5.png ./gui/temperature.png -./gui/button_play_hover.png -./gui/slot_armor_helmet.png -./gui/slot_clothing_boots.png -./gui/hotbar.png -./gui/button_normal.png -./gui/shield.png +./gui/slot_armor_chest.png +./gui/health_empty.png ./gui/button_hover.png -./text/char_bslash.png -./text/char_dollar.png -./text/char_l_w.png -./text/char_u_d.png -./text/char_u_t.png -./text/char_space.png -./text/char_l_x.png -./text/char_l_k.png -./text/char_6.png -./text/char_unknown.png -./text/char_comma.png -./text/char_obracket.png -./text/char_u_w.png -./text/char_7.png -./text/char_l_f.png -./text/char_vertical.png -./text/char_plus.png -./text/char_u_a.png -./text/char_9.png -./text/char_u_k.png -./text/char_u_n.png -./text/char_percent.png -./text/char_u_m.png -./text/char_exclamation.png -./text/char_1.png -./text/char_l_q.png -./text/char_l_z.png -./text/char_l_h.png -./text/char_u_c.png -./text/char_l_g.png -./text/char_l_s.png -./text/char_fullstop.png -./text/char_u_j.png -./text/char_l_m.png -./text/char_l_t.png -./text/char_u_v.png -./text/char_colon.png -./text/char_l_i.png -./text/char_l_y.png -./text/char_u_l.png -./text/char_u_e.png -./text/char_5.png -./text/char_2.png -./text/char_3.png -./text/char_l_p.png -./text/char_fslash.png -./text/char_l_u.png -./text/char_u_f.png -./text/char_u_u.png -./text/char_l_e.png -./text/char_l_l.png -./text/char_u_g.png -./text/char_u_q.png -./text/char_u_b.png -./text/char_l_o.png -./text/char_minus.png -./text/char_l_v.png -./text/char_lthan.png -./text/char_u_s.png -./text/char_equals.png -./text/char_8.png -./text/char_underscore.png -./text/char_u_x.png -./text/char_0.png -./text/char_l_d.png -./text/char_l_c.png -./text/char_l_j.png -./text/char_u_z.png -./text/char_u_h.png -./text/char_hashtag.png -./text/char_gthan.png -./text/char_cbracket.png -./text/char_u_i.png -./text/char_question.png -./text/char_u_o.png -./text/char_u_y.png -./text/char_l_r.png -./text/char_l_b.png -./text/char_l_a.png -./text/char_l_n.png -./text/char_u_p.png -./text/char_u_r.png -./text/char_4.png -./entity/armored_zombie_back_moving.png -./entity/zombie_front_still.png -./entity/tnt.png +./gui/water.png +./gui/slot_armor_legs.png +./gui/selection_box_big.png +./gui/button_normal.png +./gui/label.png +./gui/hotbar.png +./gui/slot_armor_helmet.png +./gui/button_delete.png +./gui/text_cursor.png +./gui/inventory.png +./gui/button_delete_hover.png +./gui/button_play_hover.png +./gui/health_full.png +./gui/hotbar_selected.png +./gui/slot_clothing_shirt.png +./gui/pixel_white.png +./gui/pixel_black.png +./gui/slot_clothing_pants.png +./gui/text_box.png +./gui/shield.png +./gui/slot_clothing_boots.png +./gui/selection_box_wide.png +./gui/gun.png +./gui/button_play.png +./tile/cactus4.png +./tile/hemp1.png +./tile/dirt.png +./tile/lantern.png +./tile/hemp8.png +./tile/wall.png +./tile/cactus_top.png +./tile/cactus2.png +./tile/rock.png +./tile/water.png +./tile/hemp4.png +./tile/stone.png +./tile/tree_leaves.png +./tile/sapling2.png +./tile/ladder_up.png +./tile/sapling3.png +./tile/lava_flow.png +./tile/ice_wall.png +./tile/grass.png +./tile/chest.png +./tile/sapling4.png +./tile/lava.png +./tile/tall_grass.png +./tile/hemp5.png +./tile/sapling1.png +./tile/snow.png +./tile/sandstone_wall.png +./tile/rock_sandstone.png +./tile/hemp6.png +./tile/cactus1.png +./tile/tree_branch_leaves.png +./tile/tunnel_down.png +./tile/tree_branch_leaves_snow.png +./tile/tree_leaves_snow.png +./tile/rock_ice.png +./tile/boss_portal.png +./tile/ladder.png +./tile/hemp7.png +./tile/grass_infested.png +./tile/tree_branch.png +./tile/sand.png +./tile/tree_base.png +./tile/cactus3.png +./tile/sandstone.png +./tile/hemp3.png +./tile/hemp2.png +./tile/ice.png ./entity/flare.png -./entity/boss1/boss_walking.png +./entity/grappling_hook.png +./entity/zombie_back_moving.png +./entity/tnt.png +./entity/armored_zombie_back_moving.png +./entity/armored_zombie_front_moving.png +./entity/player/hair_side.png +./entity/player/head_top.png +./entity/player/head_side.png +./entity/player/head_back.png +./entity/player/head_bottom.png +./entity/player/hair_front.png +./entity/player/head_front.png +./entity/player/hair_back.png +./entity/player/hair_top.png +./entity/dummy.png +./entity/armored_zombie_front_still.png +./entity/armored_zombie_back_still.png +./entity/zombie_front_moving.png +./entity/boss1/boss_walking_firing.png ./entity/boss1/boss_firing.png ./entity/boss1/boss_still.png -./entity/boss1/boss_walking_firing.png -./entity/armored_zombie_back_still.png -./entity/armored_zombie_front_moving.png -./entity/player/head_back.png -./entity/player/hair_top.png -./entity/player/head_front.png -./entity/player/head_top.png -./entity/player/hair_side.png -./entity/player/head_side.png -./entity/player/hair_back.png -./entity/player/hair_front.png -./entity/player/head_bottom.png -./entity/grappling_hook.png +./entity/boss1/boss_walking.png ./entity/zombie_back_still.png -./entity/dummy.png -./entity/zombie_back_moving.png -./entity/armored_zombie_front_still.png -./entity/zombie_front_moving.png -./particle/smoke_1.png -./particle/water.png -./particle/rain.png -./particle/blood.png -./particle/snow.png -./particle/smoke_3.png -./particle/smoke_4.png -./particle/smoke_2.png -./particle/smoke_0.png -./particle/bullet.png -./particle/lava.png -./particle/smoke_trail.png -./particle/smoke_5.png +./entity/zombie_front_still.png +./item/acorn.png +./item/grappling_hook.png +./item/gun_upgrade.png +./item/shield_upgrade.png +./item/rock.png +./item/log.png +./item/log_snow.png +./item/hemp_seed.png +./item/ammo_box.png +./item/plant_fibre.png +./item/health_potion.png +./item/snow_pile.png +./item/flint.png +./item/sandstone.png diff --git a/src/resources/texture/text/char_and.png b/src/resources/texture/text/char_and.png new file mode 100644 index 0000000..06a34e6 Binary files /dev/null and b/src/resources/texture/text/char_and.png differ diff --git a/src/resources/texture/text/char_apostrophe.png b/src/resources/texture/text/char_apostrophe.png new file mode 100644 index 0000000..a626016 Binary files /dev/null and b/src/resources/texture/text/char_apostrophe.png differ diff --git a/src/resources/texture/text/char_at.png b/src/resources/texture/text/char_at.png new file mode 100644 index 0000000..eabb3e5 Binary files /dev/null and b/src/resources/texture/text/char_at.png differ diff --git a/src/resources/texture/text/char_ccbracket.png b/src/resources/texture/text/char_ccbracket.png new file mode 100644 index 0000000..0a360ae Binary files /dev/null and b/src/resources/texture/text/char_ccbracket.png differ diff --git a/src/resources/texture/text/char_csbracket.png b/src/resources/texture/text/char_csbracket.png new file mode 100644 index 0000000..74b1381 Binary files /dev/null and b/src/resources/texture/text/char_csbracket.png differ diff --git a/src/resources/texture/text/char_grave.png b/src/resources/texture/text/char_grave.png new file mode 100644 index 0000000..da039f3 Binary files /dev/null and b/src/resources/texture/text/char_grave.png differ diff --git a/src/resources/texture/text/char_ocbracket.png b/src/resources/texture/text/char_ocbracket.png new file mode 100644 index 0000000..4f6f96a Binary files /dev/null and b/src/resources/texture/text/char_ocbracket.png differ diff --git a/src/resources/texture/text/char_osbracket.png b/src/resources/texture/text/char_osbracket.png new file mode 100644 index 0000000..fc6e1d6 Binary files /dev/null and b/src/resources/texture/text/char_osbracket.png differ diff --git a/src/resources/texture/text/char_pow.png b/src/resources/texture/text/char_pow.png new file mode 100644 index 0000000..80e90d3 Binary files /dev/null and b/src/resources/texture/text/char_pow.png differ diff --git a/src/resources/texture/text/char_quotation.png b/src/resources/texture/text/char_quotation.png new file mode 100644 index 0000000..a5b903b Binary files /dev/null and b/src/resources/texture/text/char_quotation.png differ diff --git a/src/resources/texture/text/char_semicolon.png b/src/resources/texture/text/char_semicolon.png new file mode 100644 index 0000000..c0b1c2c Binary files /dev/null and b/src/resources/texture/text/char_semicolon.png differ diff --git a/src/resources/texture/text/char_star.png b/src/resources/texture/text/char_star.png new file mode 100644 index 0000000..f88a189 Binary files /dev/null and b/src/resources/texture/text/char_star.png differ diff --git a/src/resources/texture/text/char_tilde.png b/src/resources/texture/text/char_tilde.png new file mode 100644 index 0000000..29cb681 Binary files /dev/null and b/src/resources/texture/text/char_tilde.png differ diff --git a/worker.jar b/worker.jar index fbd1490..8e0d676 100644 Binary files a/worker.jar and b/worker.jar differ