Got some gui working

This commit is contained in:
josua 2020-06-16 10:06:55 +10:00
parent b483234d9c
commit eacf39f27b
31 changed files with 300 additions and 219 deletions

View File

@ -27,6 +27,7 @@ import projectzombie.resources.Resource;
public class AudioObject
{
double volume;
int bufferPointer;
Resource resource;
boolean error;
@ -34,10 +35,11 @@ public class AudioObject
int sample_rate;
int output;
public AudioObject(Resource resource)
public AudioObject(Resource resource, double volume)
{
// Store the argument values
this.resource = resource;
this.volume = volume;
this.error = false;
}
@ -93,7 +95,7 @@ public class AudioObject
int source = AudioSources.getSource();
alSourceStop(source);
alSourcei(source, AL_BUFFER, bufferPointer);
alSourcef(source, AL_GAIN, (float)volume);
alSourcef(source, AL_GAIN, (float)(volume * this.volume));
alSource3f(source, AL_POSITION, (float)vec.x, (float)vec.y, (float)vec.z);
alSourcePlay(source);
}

View File

@ -10,7 +10,7 @@ public class AudioRandom extends AudioObject
private static Random rand = new Random();
public AudioRandom(AudioObject ... audioObjects) {
super(null);
super(null, 0);
// Set the specified parameters
this.audioObjects = audioObjects;

View File

@ -21,6 +21,10 @@ public class DisplayRender
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, w, h);
GL33.glEnable(GL33.GL_DEPTH_TEST);
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0);
if(Main.menu.doGameRender)
{
if(ChunkEventHandler.loaded)
@ -49,9 +53,7 @@ public class DisplayRender
if(!Main.player.dead)
{
Model model = player.getModel();
Matrix4 matrix = Matrix4.translate(player.pos.x - 0.5, player.getHeight(), player.pos.y - 0.5);
GL33.glUniformMatrix4fv(Main.window.glsl_model, true, matrix.getArray());
model.bind();
model.setModel(Matrix4.translate(player.pos.x - 0.5, player.getHeight(), player.pos.y - 0.5));
model.render();
}
}

View File

@ -2,11 +2,17 @@ package projectzombie.display;
import org.lwjgl.opengl.GL33;
import gl_engine.MathHelpers;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.init.Models;
import projectzombie.inventory.Inventory;
import projectzombie.model.Model;
import projectzombie.model.ModelGui;
import projectzombie.text.Text;
import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.ItemStack;
public class DisplayRenderUI
{
@ -14,17 +20,83 @@ public class DisplayRenderUI
public static boolean showPos = false;
public static int guiScale = 2;
public static void renderGameGui()
{
{
Matrix4 matrix = Matrix4.translate(-Models.UI_ITEM_SLOTS.getWidth() / 2, -9.5, 0);
Inventory inventory = Main.player.getInventory();
int slot = Main.player.inventory_hand;
double offset = Models.UI_ITEM_SLOTS.getWidth() / 10;
Matrix4 matrix_slot = Matrix4.multiply(matrix, Matrix4.translate(offset * slot, 0, 0));
Models.UI_ITEM_SLOTS.setModel(matrix);
Models.UI_ITEM_SLOTS.render();
Models.UI_ACTIVE_SLOT.setModel(matrix_slot);
Models.UI_ACTIVE_SLOT.render();
for(int i = 0; i < inventory.getSlotCount(); i++)
{
ItemStack stack = inventory.getItem(i);
if(stack.isEmpty()) {
continue;
}
Model model_item = stack.item.getModel(stack.meta).getGuiModel();
double item_offset = (Models.UI_ACTIVE_SLOT.getHeight() - model_item.getHeight()) / 2;
Matrix4 matrix_item = Matrix4.multiply(matrix, Matrix4.translate(i * offset + item_offset, item_offset, 0));
model_item.setModel(matrix_item);
model_item.render();
if(stack.count > 1)
{
matrix_item = Matrix4.multiply(matrix, Matrix4.translate(i * offset + 0.25, 0.28125, 0));
matrix_item = Matrix4.multiply(Matrix4.scale(new Vec3d(0.4, 0.4, 0.4)), matrix_item);
Text.render("" + stack.count, matrix_item);
}
}
}
{
ModelGui model_health_f = Models.UI_HEALTH_FG;
ModelGui model_health_b = Models.UI_HEALTH_BG;
Matrix4 matrix = Matrix4.translate(-model_health_f.getWidth() / 2, -8, 0);
model_health_b.setModel(matrix);
model_health_b.render();
GL33.glUniform2f(Main.window.glsl_tex_cut, 1, (float)MathHelpers.map(
Main.player.getHealth(),
0, Main.player.maxHealth(),
0, model_health_f.getWidth()));
model_health_f.setModel(matrix);
model_health_f.render();
GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0);
}
}
public static void render()
{
Matrix4 matrix = Matrix4.identity();
Matrix4 projection = Matrix4.scale(new Vec3d(1/GlHelpers.getAspectRatio(), 1, 1));
Matrix4 camera = Matrix4.identity();
Matrix4 projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1));
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray());
GL33.glUniformMatrix4fv(Main.window.glsl_camera, true, matrix.getArray());
GL33.glUniformMatrix4fv(Main.window.glsl_model, true, matrix.getArray());
GL33.glUniformMatrix4fv(Main.window.glsl_camera, true, camera.getArray());
Models.UI_ITEM_SLOTS.bind();
Models.UI_ITEM_SLOTS.render();
GL33.glDisable(GL33.GL_DEPTH_TEST);
if(Main.menu.doGameRender && Main.menu.showIngameGUI)
{
renderGameGui();
}
// Render the loaded menu
//Main.menu.render();

View File

@ -33,6 +33,8 @@ public class DisplayWindow implements IMainloopTask
public GraphicsShader environmentRenderer;
public int glsl_color;
public int glsl_tex_cut;
public int glsl_model;
public int glsl_projection;
public int glsl_rotated;
@ -74,7 +76,7 @@ public class DisplayWindow implements IMainloopTask
width = w.get()*4;
height = h.get()*4;
//GLFW.glfwWindowHint(GLFW.GLFW_DOUBLEBUFFER, GLFW.GLFW_FALSE);
GLFW.glfwWindowHint(GLFW.GLFW_DOUBLEBUFFER, GLFW.GLFW_FALSE);
// Create the window
window = GraphicsHelpers.initWindow("Project Zombie", width, height, monitor);
@ -97,9 +99,6 @@ public class DisplayWindow implements IMainloopTask
// Show the window
//GLFW.glfwShowWindow(this.window);
GL33.glEnable(GL33.GL_DEPTH_TEST);
//GL33.glEnable(GL33.GL_BLEND);
environmentRenderer = new GraphicsShader("/resources/shader/environmentRenderer");
environmentRenderer.use();
@ -108,6 +107,8 @@ public class DisplayWindow implements IMainloopTask
glsl_rotated = GL33.glGetUniformLocation(environmentRenderer.program, "rotated");
glsl_projection = GL33.glGetUniformLocation(environmentRenderer.program, "projection");
glsl_time = GL33.glGetUniformLocation(environmentRenderer.program, "time");
glsl_tex_cut = GL33.glGetUniformLocation(environmentRenderer.program, "tex_cut");
glsl_color = GL33.glGetUniformLocation(environmentRenderer.program, "color");
}
public void render()

View File

@ -16,6 +16,7 @@ import projectzombie.entity.particle.ParticleBreak;
import projectzombie.init.Items;
import projectzombie.init.Models;
import projectzombie.inventory.Inventory;
import projectzombie.items.spawner.ItemSpawnZombie;
import projectzombie.menu.MenuDeath;
import projectzombie.model.Model;
import projectzombie.settings.Cheats;
@ -46,16 +47,12 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
private Inventory inventory;
public int inventory_hand = 0;
public int ammo = 1000;
public int defence_level = 0;
public int gun_level = 0;
public double angle;
public double speed;
private static final Vec2d size = new Vec2d(1, 1);
public EntityPlayer(BdfObject bdf) {
super(bdf);
}
@ -69,12 +66,15 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
health = nl.get("health").getDouble();
dead = nl.get("dead").getBoolean();
inventory = new Inventory(nl.get("inventory"));
ammo = nl.get("ammo").getInteger();
defence_level = nl.get("defence_level").getInteger();
gun_level = nl.get("gun_level").getInteger();
angle = nl.get("angle").getDouble();
}
public int getAmmo() {
return inventory.getItemCount(Items.AMMO);
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
@ -84,7 +84,6 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
nl.set("health", BdfObject.withDouble(health));
nl.set("dead", BdfObject.withBoolean(dead));
inventory.BdfClassSave(nl.get("inventory"));
nl.set("ammo", BdfObject.withInteger(ammo));
nl.set("defence_level", BdfObject.withInteger(defence_level));
nl.set("gun_level", BdfObject.withInteger(gun_level));
nl.set("angle", BdfObject.withDouble(angle));
@ -104,10 +103,7 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
speed = 0.1;
// Create the inventory
inventory = new Inventory(6);
inventory.setItem(new ItemStack(Items.LANTERN, 99, (byte)0), 2);
inventory.setItem(new ItemStack(Items.SPAWN_ZOMBIE, 99, (byte)0), 3);
inventory = new Inventory(10);
}
@Override
@ -235,10 +231,10 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
bullet_frequency %= 10;
// Is there enough ammo and are the bullets at the right frequency
if(bullet_frequency == 0 && ammo > 0)
if(bullet_frequency == 0 && getAmmo() > 0)
{
// Remove some ammo
ammo -= 1;
inventory.removeItem(Items.AMMO, 1);
// Summon bullets at this angle relative to the player
int d = (int)(1 + gun_level / 4.0);

View File

@ -13,6 +13,7 @@ import projectzombie.items.ItemHealthPotion;
import projectzombie.items.ItemLantern;
import projectzombie.items.ItemRock;
import projectzombie.items.ItemTnt;
import projectzombie.items.spawner.ItemSpawnDummy;
import projectzombie.items.spawner.ItemSpawnZombie;
public class Items
@ -56,7 +57,7 @@ public class Items
public static final Item GRAPPLING_HOOK = new ItemGrapplingHook();
public static final Item SPAWN_ZOMBIE = new ItemSpawnZombie();
public static final Item SPAWN_DUMMY = new ItemSpawnZombie();
public static final Item SPAWN_DUMMY = new ItemSpawnDummy();
public static final Item ROCK = new ItemRock();
}

View File

@ -53,16 +53,16 @@ public class Models
new ModelVertical(Resources.ATLAS.get("/particle/smoke_4.png")),
new ModelVertical(Resources.ATLAS.get("/particle/smoke_5.png")));
public static final Model BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button.png"));
public static final Model BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/tile/tree.png"));
public static final ModelGui UI_BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button.png"));
public static final ModelGui UI_BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/tile/tree.png"));
public static final Model UI_HEALTH_FG = new ModelGui(Resources.ATLAS.get("/gui/health_full.png"));
public static final Model UI_HEALTH_BG = new ModelGui(Resources.ATLAS.get("/gui/health_empty.png"));
public static final Model UI_ITEM_SLOTS = new ModelGui(Resources.ATLAS.get("/gui/hotbar.png"), new Vec2d(6, 1));
public static final Model UI_ACTIVE_SLOT = new ModelGui(Resources.ATLAS.get("/gui/hotbar_selected.png"));
public static final ModelGui UI_HEALTH_FG = new ModelGui(Resources.ATLAS.get("/gui/health_full.png"), new Vec2d(8, 0.5));
public static final ModelGui UI_HEALTH_BG = new ModelGui(Resources.ATLAS.get("/gui/health_empty.png"), new Vec2d(8, 0.5));
public static final ModelGui UI_ITEM_SLOTS = new ModelGui(Resources.ATLAS.get("/gui/hotbar.png"), new Vec2d(15, 1.5));
public static final ModelGui UI_ACTIVE_SLOT = new ModelGui(Resources.ATLAS.get("/gui/hotbar_selected.png"), new Vec2d(1.5, 1.5));
public static final Model UI_DEFENCE_LEVEL = new ModelGui(Resources.ATLAS.get("/gui/shield.png"));
public static final Model UI_GUN_LEVEL = new ModelGui(Resources.ATLAS.get("/gui/gun.png"));
public static final ModelGui UI_DEFENCE_LEVEL = new ModelGui(Resources.ATLAS.get("/gui/shield.png"));
public static final ModelGui UI_GUN_LEVEL = new ModelGui(Resources.ATLAS.get("/gui/gun.png"));
public static final ModelItem ITEM_EMPTY = ModelItem.createEmpty();
public static final ModelItem ITEM_GRAPPLING_HOOK = new ModelItem(Resources.ATLAS.get("/item/grappling_hook.png"));

View File

@ -25,27 +25,27 @@ public class Sounds
EXPLOSION.init();
}
public static final AudioObject GUN_0 = new AudioObject(Resources.GUN_OGG_0);
public static final AudioObject GUN_1 = new AudioObject(Resources.GUN_OGG_1);
public static final AudioObject GUN_2 = new AudioObject(Resources.GUN_OGG_2);
public static final AudioObject GUN_3 = new AudioObject(Resources.GUN_OGG_3);
public static final AudioObject GUN_4 = new AudioObject(Resources.GUN_OGG_4);
public static final AudioObject GUN_5 = new AudioObject(Resources.GUN_OGG_5);
public static final AudioObject GUN_6 = new AudioObject(Resources.GUN_OGG_6);
public static final AudioObject GUN_7 = new AudioObject(Resources.GUN_OGG_7);
public static final AudioObject GUN_8 = new AudioObject(Resources.GUN_OGG_8);
public static final AudioObject GUN_9 = new AudioObject(Resources.GUN_OGG_9);
public static final AudioObject GUN_0 = new AudioObject(Resources.GUN_OGG_0, 1);
public static final AudioObject GUN_1 = new AudioObject(Resources.GUN_OGG_1, 1);
public static final AudioObject GUN_2 = new AudioObject(Resources.GUN_OGG_2, 1);
public static final AudioObject GUN_3 = new AudioObject(Resources.GUN_OGG_3, 1);
public static final AudioObject GUN_4 = new AudioObject(Resources.GUN_OGG_4, 1);
public static final AudioObject GUN_5 = new AudioObject(Resources.GUN_OGG_5, 1);
public static final AudioObject GUN_6 = new AudioObject(Resources.GUN_OGG_6, 1);
public static final AudioObject GUN_7 = new AudioObject(Resources.GUN_OGG_7, 1);
public static final AudioObject GUN_8 = new AudioObject(Resources.GUN_OGG_8, 1);
public static final AudioObject GUN_9 = new AudioObject(Resources.GUN_OGG_9, 1);
public static final AudioObject GUN = new AudioRandom(
GUN_0,GUN_1,GUN_2,GUN_3,GUN_4,
GUN_5,GUN_6,GUN_7,GUN_8,GUN_9);
public static final AudioObject HIT_0 = new AudioObject(Resources.HIT_OGG_0);
public static final AudioObject HIT_1 = new AudioObject(Resources.HIT_OGG_1);
public static final AudioObject HIT_2 = new AudioObject(Resources.HIT_OGG_2);
public static final AudioObject HIT_0 = new AudioObject(Resources.HIT_OGG_0, 1);
public static final AudioObject HIT_1 = new AudioObject(Resources.HIT_OGG_1, 1);
public static final AudioObject HIT_2 = new AudioObject(Resources.HIT_OGG_2, 1);
public static final AudioObject HIT = new AudioRandom(
HIT_0, HIT_1, HIT_2);
public static final AudioObject EXPLOSION = new AudioObject(Resources.EXPLOSION_OGG);
public static final AudioObject EXPLOSION = new AudioObject(Resources.EXPLOSION_OGG, 10);
}

View File

@ -1,27 +1,7 @@
package projectzombie.input;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_1;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_2;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_3;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_4;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_5;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_6;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
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_Q;
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.backButton_last;
import static projectzombie.input.GameInput.fireGun;
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 static org.lwjgl.glfw.GLFW.*;
import static projectzombie.input.GameInput.*;
import org.lwjgl.glfw.GLFWKeyCallbackI;
@ -80,6 +60,18 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
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(key == GLFW_KEY_E) {
if(pressed) {

View File

@ -67,7 +67,7 @@ public class InputGame implements Input
@Override
public void hotbarShift(boolean state, int amount) {
Main.player.inventory_hand += amount;
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 6);
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, Main.player.getInventory().getSlotCount());
}
@Override

View File

@ -4,6 +4,7 @@ import bdf.classes.IBdfClassManager;
import bdf.types.BdfArray;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.items.Item;
import projectzombie.util.math.ItemStack;
public class Inventory implements IInventory, IBdfClassManager
@ -15,7 +16,7 @@ public class Inventory implements IInventory, IBdfClassManager
items = new ItemStack[size];
for(int i=0;i<size;i++) {
items[i] = ItemStack.EMPTY;
items[i] = ItemStack.getEmpty();
}
}
@ -23,7 +24,7 @@ public class Inventory implements IInventory, IBdfClassManager
public ItemStack getItem(int slot)
{
if(items[slot].isEmpty()) {
return ItemStack.EMPTY;
return ItemStack.getEmpty();
}
else {
@ -44,10 +45,108 @@ public class Inventory implements IInventory, IBdfClassManager
@Override
public ItemStack removeItem(int slot) {
ItemStack stack = items[slot];
items[slot] = ItemStack.EMPTY;
items[slot] = ItemStack.getEmpty();
return stack;
}
public int getItemCount(ItemStack item)
{
int count = 0;
for(ItemStack check : items) {
if(item.stackEquals(check) && !check.isEmpty()) {
count += check.count;
}
}
return count;
}
public int getItemCount(Item item)
{
int count = 0;
for(ItemStack check : items) {
if(item == check.item && !check.isEmpty()) {
count += 1;
}
}
return count;
}
public void addItem(ItemStack stack)
{
if(stack.isEmpty()) {
return;
}
for(ItemStack check : items)
{
if(stack.stackEquals(check) && !check.isEmpty())
{
if(check.count + stack.count > check.item.max) {
stack.count = (check.count + stack.count) - check.item.max;
check.count = check.item.max;
}
else {
check.count += stack.count;
stack.count = 0;
return;
}
}
}
for(ItemStack check : items)
{
if(check.isEmpty()) {
check.item = stack.item;
check.count = stack.count;
check.meta = stack.meta;
stack.count = 0;
return;
}
}
}
public void removeItem(ItemStack stack)
{
for(ItemStack check : items) {
if(stack.stackEquals(check) && !stack.isEmpty())
{
if(check.count < stack.count) {
stack.count -= check.count;
check.count = 0;
}
else {
check.count -= stack.count;
stack.count = 0;
return;
}
}
}
}
public void removeItem(Item item, int count)
{
for(ItemStack check : items) {
if(item == check.item)
{
if(check.count < count) {
count -= check.count;
check.count = 0;
}
else {
check.count -= count;
return;
}
}
}
}
@Override
public void BdfClassLoad(BdfObject bdf)
{

View File

@ -12,6 +12,7 @@ import projectzombie.world.layer.Layer;
public abstract class Item
{
public int id;
public int max = 99;
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
stack.count -= 1;
@ -38,33 +39,8 @@ public abstract class Item
// Get the entities inventory
Inventory entity_i = ((EntityInventory) entity).getInventory();
// Loop over the inventory
for(int i=0;i<entity_i.getSlotCount();i++)
{
// Is this item the same as the picked up item
ItemStack i_stack = entity_i.getItem(i);
if(stack.stackEquals(i_stack))
{
// Move the stack count to the inventory slot
i_stack.count += stack.count;
stack.count = 0;
return;
}
}
// Loop over the inventory
for(int i=0;i<entity_i.getSlotCount();i++)
{
// Is this item stack empty
ItemStack i_stack = entity_i.getItem(i);
if(i_stack.isEmpty())
{
// Send the entity stack to the inventory stack
entity_i.setItem(stack.copy(), i);
stack.count = 0;
return;
}
}
// Add the item to the entities inventory
entity_i.addItem(stack);
}
}
}

View File

@ -16,19 +16,6 @@ public class ItemAmmo extends Item
return Models.ITEM_AMMO_BOX;
}
@Override
public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity)
{
// Is this entity a player
if(entity instanceof EntityPlayer)
{
// Add the ammo to the players inventory
EntityPlayer ep = (EntityPlayer)entity;
ep.ammo += stack.count;
stack.count = 0;
}
}
@Override
public String getName(short meta) {
return "Ammo";

View File

@ -10,6 +10,9 @@ import projectzombie.world.layer.Layer;
public class ItemDefenceUpgrade extends Item
{
public ItemDefenceUpgrade() {
this.max = 1;
}
@Override
public ModelItem getModel(short meta) {

View File

@ -10,6 +10,9 @@ import projectzombie.world.layer.Layer;
public class ItemGunUpgrade extends Item
{
public ItemGunUpgrade() {
this.max = 1;
}
@Override
public ModelItem getModel(short meta) {

View File

@ -8,7 +8,7 @@ public class MainloopEventHandler implements IMainloopEvent, IMainloopTask
{
public static final MainloopEventHandler MAINLOOP_EVENT_HANDLER = new MainloopEventHandler();
private long max_mspf = 1000/60;
private long max_mspf = 1;
public long mspf = max_mspf;
@Override

View File

@ -65,9 +65,9 @@ public class Button implements GUIComponent, GUISelectable
Model model;
boolean mouseHover = InputMode.Controller ? this.selected : this.checkMouseHover(mousePos);
if(mouseHover) {
model = Models.BUTTON_HOVER;
model = Models.UI_BUTTON_HOVER;
} else {
model = Models.BUTTON;
model = Models.UI_BUTTON;
}
Matrix4 matrix = Matrix4.translate(pos.x, pos.y, 0);
@ -80,7 +80,7 @@ public class Button implements GUIComponent, GUISelectable
} else {
//GlHelpers.color3(0.68, 0.68, 0.68);
}
Text.render(text, textSize);
//Text.render(text, textSize);
}
@Override

View File

@ -14,7 +14,9 @@ import static org.lwjgl.opengl.GL30.glGenVertexArrays;
import org.lwjgl.opengl.GL33;
import gl_engine.MathHelpers;
import gl_engine.matrix.Matrix4;
import gl_engine.texture.TextureRef3D;
import projectzombie.Main;
public abstract class Model
{
@ -28,6 +30,8 @@ public abstract class Model
public abstract double getHeight();
public abstract int getSize();
private static Model bound = null;
private void generate()
{
float[] verticies = this.getVerticies();
@ -83,9 +87,16 @@ public abstract class Model
else {
generate();
}
bound = this;
}
public void render() {
public void render()
{
if(bound != this) {
bind();
}
GL33.glDrawArrays(GL33.GL_TRIANGLES, 0, getSize());
}
@ -94,4 +105,8 @@ public abstract class Model
GL33.glDeleteVertexArrays(vao);
GL33.glDeleteBuffers(vbo);
}
public void setModel(Matrix4 model) {
GL33.glUniformMatrix4fv(Main.window.glsl_model, true, model.getArray());
}
}

View File

@ -7,7 +7,7 @@ public class ModelGui extends Model
{
private int animationSize;
private int animationSpeed;
private double height;
private double width, height;
private TextureRef3D ref;
private Vec2d size;
@ -46,6 +46,7 @@ public class ModelGui extends Model
int asi = animationSize;
int asp = animationSpeed;
width = x;
height = y;
return new float[] {
@ -71,4 +72,8 @@ public class ModelGui extends Model
public double getHeight() {
return height;
}
public double getWidth() {
return width;
}
}

View File

@ -10,7 +10,7 @@ public class ModelItem
public ModelItem(TextureRef3D tex, int animationSize, int animationSpeed)
{
this.gui = new ModelGui(tex, animationSize, animationSpeed);
this.gui = new ModelGui(tex, new Vec2d(0.85, 0.85), animationSize, animationSpeed);
this.item = new ModelVertical(tex, new Vec2d(0.5, 0.5), animationSize, animationSpeed);
}

View File

@ -1,5 +1,6 @@
package projectzombie.text;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.init.Resources;
@ -92,22 +93,11 @@ public class Text
public static final Model CHAR_L_THAN = new ModelGui(Resources.ATLAS.get("/text/char_lthan.png"));
public static final Model CHAR_G_THAN = new ModelGui(Resources.ATLAS.get("/text/char_gthan.png"));
public static void renderCenter(String text, Vec2d size) {
int w = Main.window.getWidth();
int h = Main.window.getHeight();
double aspect_ratio = ((double)w) / ((double)h);
//GlHelpers.translate2(0 - (text.length() * size.x / 2 / aspect_ratio), 0);
Text.render(text, size);
}
public static void render(String text, Vec2d size)
public static void render(String text, Matrix4 matrix)
{
// Get the bytes from the string
byte[] text_b = text.getBytes();
double sx = size.x;
double sy = size.y;
// Loop over the bytes
for(int i=0;i<text_b.length;i++)
{
@ -198,7 +188,10 @@ public class Text
case('<'): l = CHAR_L_THAN; break;
}
l.bind();
Matrix4 model = Matrix4.multiply(Matrix4.translate(i, 0, 0), matrix);
l.setModel(model);
l.render();
}
}
}

View File

@ -12,8 +12,6 @@ public class ItemStack implements IBdfClassManager
public Item item;
public int count;
public static final ItemStack EMPTY = new ItemStack(Items.EMPTY, 0, (short)0);
public ItemStack(Item item, int count, short meta) {
this.item = item;
this.count = count;
@ -26,8 +24,8 @@ public class ItemStack implements IBdfClassManager
public boolean isEmpty() {
if(count < 1) return true;
if(this == EMPTY) return true;
if(item == null) return true;
if(item == Items.EMPTY) return true;
return false;
}
@ -56,4 +54,8 @@ public class ItemStack implements IBdfClassManager
public ItemStack(BdfObject bdf) {
BdfClassLoad(bdf);
}
public static ItemStack getEmpty() {
return new ItemStack(Items.EMPTY, 0, (short)0);
}
}

View File

@ -267,10 +267,7 @@ public class Chunk implements IBdfClassManager
}
{
Matrix4 matrix = Matrix4.translate(c_pos.x * 16, 0, c_pos.y * 16);
GL33.glUniformMatrix4fv(Main.window.glsl_model, true, matrix.getArray());
model.bind();
model.setModel(Matrix4.translate(c_pos.x * 16, 0, c_pos.y * 16));
model.render();
}
@ -283,10 +280,7 @@ public class Chunk implements IBdfClassManager
h = ((EntityHeight)e).getHeight();
}
Matrix4 matrix = Matrix4.translate(e.pos.x - 0.5, h, e.pos.y - 0.5);
GL33.glUniformMatrix4fv(Main.window.glsl_model, true, matrix.getArray());
model.bind();
model.setModel(Matrix4.translate(e.pos.x - 0.5, h, e.pos.y - 0.5));
model.render();
}
}

View File

@ -1,15 +1,18 @@
#version 330
in vec3 pPos;
in vec3 pTexture;
out vec4 color;
out vec4 FragColor;
uniform sampler3D tex;
uniform vec2 tex_cut;
uniform vec4 color;
void main()
{
color = texture(tex, pTexture);
FragColor = texture(tex, pTexture) * color;
if(color.a == 0) {
if(FragColor.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5)) {
discard;
}
}

View File

@ -7,6 +7,7 @@ layout (location = 3) in vec3 aTranslate;
layout (location = 4) in vec3 aFlags;
out vec3 pTexture;
out vec3 pPos;
uniform mat4 projection;
uniform mat4 model;
@ -14,9 +15,6 @@ uniform mat4 camera;
uniform mat4 rotated;
uniform int time;
uniform float tex_cut;
uniform int tex_cut_mode;
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;
}
@ -56,7 +54,8 @@ void main()
mat4 no_rotation = mat4(1);
gl_Position = vec4(aPos, 1) * (mod(type, 2) == 1 ? do_rotation : no_rotation) *
(translate(aTranslate) * model) * camera * projection;
translate(aTranslate) * model * camera * projection;
pTexture = vec3(aTex.x, getTexY(), aTex.z);
pPos = aPos;
}

View File

@ -1,10 +0,0 @@
#version 330
in vec3 pTexture;
out vec4 color;
uniform sampler3D tex;
void main() {
color = texture(tex, pTexture);
}

View File

@ -1,54 +0,0 @@
#version 330
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aTex;
layout (location = 2) in vec2 aTexY;
layout (location = 3) in vec3 aTranslate;
layout (location = 4) in vec3 aFlags;
out vec3 pTexture;
uniform mat4 projection;
uniform mat4 model;
uniform mat4 camera;
uniform mat4 rotated;
uniform float time;
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;
}
mat4 translate(vec3 vec)
{
mat4 result = mat4(1);
result[0][3] = vec.x;
result[1][3] = vec.y;
result[2][3] = vec.z;
return result;
}
float getTexY()
{
float animate_count = aFlags.x;
float animate_speed = aFlags.y;
float animate_index = mod(time, animate_count);
float tex_y_size = (aTexY.y - aTexY.x) / animate_count;
float tex_y = map(
aTex.y, aTexY.x, aTexY.y,
aTexY.x + tex_y_size * animate_index,
aTexY.x + tex_y_size * (animate_index + 1));
return tex_y;
}
void main()
{
int type = int(aFlags.z);
gl_Position = vec4(aPos, 1) * (translate(aTranslate) * model);
pTexture = vec3(aTex.x, getTexY(), aTex.z);
}

BIN
src/resources/sound/explosion.ogg Executable file → Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 688 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 598 B