Created an inventory,

more resources (logs, acorns, flint, hemp, sandstone, snow),
optimised items and bullets,
started setting up possibility for shadow mapping and/or reflections,
improved models (trees, cacti, hemp, rocks),
added optimizations for particles,
started working on better player models,
fixed issues with the font.
This commit is contained in:
josua 2020-07-16 00:26:50 +10:00
parent 135d6ef185
commit ff3bb85d7c
289 changed files with 4673 additions and 1564 deletions

View File

@ -16,8 +16,10 @@ import projectzombie.init.Entities;
import projectzombie.init.Items; import projectzombie.init.Items;
import projectzombie.init.LayerGenerators; import projectzombie.init.LayerGenerators;
import projectzombie.init.Layers; import projectzombie.init.Layers;
import projectzombie.init.Models;
import projectzombie.init.Resources; import projectzombie.init.Resources;
import projectzombie.init.Sounds; import projectzombie.init.Sounds;
import projectzombie.init.Tasks;
import projectzombie.init.Tiles; import projectzombie.init.Tiles;
import projectzombie.input.JoystickCallback; import projectzombie.input.JoystickCallback;
import projectzombie.input.KeyCallback; import projectzombie.input.KeyCallback;
@ -73,6 +75,7 @@ public class Main
Items.init(); Items.init();
Entities.init(); Entities.init();
Tasks.init();
Tiles.init(); Tiles.init();
LayerGenerators.init(); LayerGenerators.init();

View File

@ -22,6 +22,7 @@ import org.lwjgl.system.MemoryStack;
import gl_engine.matrix.Matrix4; import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.resources.Resource; import projectzombie.resources.Resource;
@ -88,8 +89,8 @@ public class AudioObject
} }
// Calculate the position relative to the player // Calculate the position relative to the player
Matrix4 matrix = Camera.camera.getMatrix(); Matrix4 matrix = Camera.camera.matrix;
Vec3d vec = Matrix4.multiply(matrix, pos.add(new Vec3d(-0.5, 0, -0.5))); Vec3d vec = Matrix4.multiply(matrix, pos.subtract(Main.player.getPos())).multiply(0.125);
// Play the sound with a new source // Play the sound with a new source
int source = AudioSources.getSource(); int source = AudioSources.getSource();

View File

@ -1,20 +1,22 @@
package projectzombie.display; package projectzombie.display;
import gl_engine.MathHelpers;
import gl_engine.matrix.Matrix4; import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.world.chunk.Chunk;
public class Camera public class Camera
{ {
public double x, y; public double x, y;
public double angle = 45; public double angle = 45;
private Matrix4 matrix;
public Matrix4 matrix;
public Matrix4 projection;
public Matrix4 projection_matrix;
public static Camera camera; public static Camera camera;
public Camera() public Camera(int w, int h)
{ {
Matrix4 identity = Matrix4.identity(); Matrix4 identity = Matrix4.identity();
Vec3d pos = Main.player.getPos(); Vec3d pos = Main.player.getPos();
@ -27,10 +29,9 @@ public class Camera
identity = Matrix4.multiply(identity, Matrix4.rotate(-45, 1, 0, 0)); identity = Matrix4.multiply(identity, Matrix4.rotate(-45, 1, 0, 0));
identity = Matrix4.multiply(identity, Matrix4.translate(0, 0, -16)); identity = Matrix4.multiply(identity, Matrix4.translate(0, 0, -16));
projection_matrix = Matrix4.projection((double)w / (double)h, 45, 0.1, Chunk.RENDER_DISTANCE*16+32);
projection = Matrix4.multiply(identity, projection_matrix);
matrix = identity; matrix = identity;
} }
public Matrix4 getMatrix() {
return matrix;
}
} }

View File

@ -5,10 +5,11 @@ import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.glClear; import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glViewport; import static org.lwjgl.opengl.GL11.glViewport;
import java.nio.ByteBuffer;
import org.lwjgl.opengl.GL33; import org.lwjgl.opengl.GL33;
import gl_engine.matrix.Matrix4; import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
@ -19,6 +20,55 @@ import projectzombie.world.chunk.ChunkEventHandler;
public class DisplayRender public class DisplayRender
{ {
private static int shadow_fbo;
private static int shadow_depth;
private static int generateDepthTexture(int width, int height)
{
int depth = GL33.glGenTextures();
GL33.glBindTexture(GL33.GL_TEXTURE_2D, depth);
GL33.glTexImage2D(
GL33.GL_TEXTURE_2D, 0, GL33.GL_DEPTH_COMPONENT32, width, height,
0, GL33.GL_DEPTH_COMPONENT, GL33.GL_FLOAT, (ByteBuffer) null);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MIN_FILTER, GL33.GL_LINEAR);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MAG_FILTER, GL33.GL_LINEAR);
GL33.glFramebufferTexture(GL33.GL_FRAMEBUFFER, GL33.GL_DEPTH_ATTACHMENT, depth, 0);
return depth;
}
private static int generateColorTexture(int width, int height)
{
int color = GL33.glGenTextures();
GL33.glBindTexture(GL33.GL_TEXTURE_2D, color);
GL33.glTexImage2D(
GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB, width, height,
0, GL33.GL_RGB, GL33.GL_FLOAT, (ByteBuffer) null);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MIN_FILTER, GL33.GL_LINEAR);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MAG_FILTER, GL33.GL_LINEAR);
GL33.glFramebufferTexture(GL33.GL_FRAMEBUFFER, GL33.GL_COLOR_ATTACHMENT0, color, 0);
return color;
}
public static void init()
{
//int size = 1024;
//shadow_fbo = GL33.glGenFramebuffers();
//GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, shadow_fbo);
//GL33.glDrawBuffer(GL33.GL_DEPTH_ATTACHMENT);
//GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, 0);
//shadow_depth = generateDepthTexture(size, size);
}
public static void render(int w, int h) public static void render(int w, int h)
{ {
// Setup GL and clear the colour // Setup GL and clear the colour
@ -39,35 +89,23 @@ public class DisplayRender
if(ChunkEventHandler.loaded) if(ChunkEventHandler.loaded)
{ {
EntityPlayer player = Main.player; EntityPlayer player = Main.player;
Camera camera = new Camera(); Camera camera = new Camera(w, h);
Camera.camera = camera; Camera.camera = camera;
// Create the projection matrix
Matrix4 projection = Matrix4.projection((double)w / (double)h, 45, 0.1, Chunk.RENDER_DISTANCE*16+32);
projection = Matrix4.multiply(camera.getMatrix(), projection);
Matrix4 rotated = Matrix4.rotate(-camera.angle, 0, 1, 0); Matrix4 rotated = Matrix4.rotate(-camera.angle, 0, 1, 0);
Matrix4 billboard = Matrix4.multiply(Matrix4.rotate(-45, 1, 0, 0), rotated); Matrix4 billboard = Matrix4.multiply(Matrix4.rotate(-45, 1, 0, 0), rotated);
Main.window.environmentRenderer.use(); Main.window.environmentRenderer.use();
GL33.glUniformMatrix4fv(Main.window.glsl_billboard, true, billboard.getArray()); GL33.glUniformMatrix4fv(Main.window.glsl_billboard, true, billboard.getArray());
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray()); GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, Camera.camera.projection.getArray());
GL33.glUniformMatrix4fv(Main.window.glsl_rotated, true, rotated.getArray()); GL33.glUniformMatrix4fv(Main.window.glsl_rotated, true, rotated.getArray());
GL33.glUniform1i(Main.window.glsl_time, (int)((System.currentTimeMillis() / 10) % 1000)); GL33.glUniform1i(Main.window.glsl_time, (int)((System.currentTimeMillis() / 10) % 1000));
// Render the world and the player Main.world.markPoolDirty();
Vec3d ppos = Main.player.getPos();
Main.world.render(camera);
player.chunk = Main.world.getLayer().getChunk(player.getPos().xz());
if(!Main.player.dead) Main.world.render(camera);
{
Model model = player.getModel(); player.chunk = Main.world.getLayer().getChunk(player.getPos().xz());
model.setModel(Matrix4.translate(
ppos.x - Camera.camera.x - 0.5, ppos.y,
ppos.z - Camera.camera.y - 0.5));
model.render();
}
} }
} }

View File

@ -1,5 +1,7 @@
package projectzombie.display; package projectzombie.display;
import java.text.DecimalFormat;
import org.lwjgl.opengl.GL33; import org.lwjgl.opengl.GL33;
import gl_engine.MathHelpers; import gl_engine.MathHelpers;
@ -14,11 +16,13 @@ import projectzombie.model.ModelGui;
import projectzombie.text.Text; import projectzombie.text.Text;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.ChunkEventHandler;
import projectzombie.world.layer.Layer;
public class DisplayRenderUI public class DisplayRenderUI
{ {
public static boolean showFPS = false; public static boolean showFPS = false;
public static boolean showPos = false; public static boolean debug = false;
public static int guiScale = 2; public static int guiScale = 2;
public static Matrix4 camera, projection; public static Matrix4 camera, projection;
@ -43,7 +47,7 @@ public class DisplayRenderUI
Models.UI_ACTIVE_SLOT.setModel(matrix_slot); Models.UI_ACTIVE_SLOT.setModel(matrix_slot);
Models.UI_ACTIVE_SLOT.render(); Models.UI_ACTIVE_SLOT.render();
for(int i = 0; i < inventory.getSlotCount(); i++) for(int i = 0; i < 10; i++)
{ {
ItemStack stack = inventory.getItem(i); ItemStack stack = inventory.getItem(i);
@ -115,6 +119,8 @@ public class DisplayRenderUI
public static void render() public static void render()
{ {
DecimalFormat dec = new DecimalFormat("0.####");
camera = Matrix4.identity(); camera = Matrix4.identity();
projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1)); projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1));
@ -134,16 +140,47 @@ public class DisplayRenderUI
matrix = Matrix4.multiply(matrix, Matrix4.translate(-10 * aspect, 9.5, 0)); matrix = Matrix4.multiply(matrix, Matrix4.translate(-10 * aspect, 9.5, 0));
if(showFPS) { if(showFPS) {
float fps = DisplayStatsEventHandler.fps;
if(fps >= 120) {
GL33.glUniform4f(Main.window.glsl_color, 0, 1, 0, 1);
} else if(fps >= 60) {
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 0, 1);
} else {
GL33.glUniform4f(Main.window.glsl_color, 1, 0, 0, 1);
}
Text.render("Fps: " + DisplayStatsEventHandler.fps, matrix); Text.render("Fps: " + DisplayStatsEventHandler.fps, matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0)); matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0));
} }
if(showPos) { if(debug) {
Vec3i pos = Main.player.getPos().toInt(); Layer layer = Main.world.getLayer();
Text.render("x="+pos.x+", y="+pos.y+", z="+pos.z, matrix); Vec3d pos = Main.player.getPos();
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 0, 1);
if(ChunkEventHandler.loaded)
{
Text.render("temperature: " + dec.format(
layer.layergen.getTemperatureStatic(layer, Main.player.getPos().xz())), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
Text.render("humidity: " + dec.format(
layer.layergen.getHumidity(layer, Main.player.getPos().xz())), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0));
Text.render("x: "+dec.format(pos.x), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
Text.render("y: "+dec.format(pos.y), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
Text.render("z: "+dec.format(pos.z), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0));
}
} }
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
// Render the loaded menu // Render the loaded menu
Main.menu.render(); Main.menu.render();
} }

View File

@ -23,8 +23,6 @@ public class DisplayStatsEventHandler implements IMainloopTask
public void MainLoopUpdate() public void MainLoopUpdate()
{ {
// Display the fps // Display the fps
Main.window.setTitle("Project Zombie (" + DisplayWindow.fps + " fps)");
fps = DisplayWindow.fps; fps = DisplayWindow.fps;
DisplayWindow.fps = 0; DisplayWindow.fps = 0;

View File

@ -169,6 +169,8 @@ public class DisplayWindow implements IMainloopTask
glVertexAttribPointer(0, 2, GL_FLOAT, false, Float.BYTES * 2, 0); glVertexAttribPointer(0, 2, GL_FLOAT, false, Float.BYTES * 2, 0);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
DisplayRender.init();
} }
public void render() public void render()
@ -218,8 +220,8 @@ public class DisplayWindow implements IMainloopTask
double player_health = Main.player.getHealth() / Main.player.maxHealth(); double player_health = Main.player.getHealth() / Main.player.maxHealth();
if(player_health < 0.5) { if(player_health < 0.25) {
GL33.glUniform1f(glsl_effect_red, (float)(0.5 - player_health)); GL33.glUniform1f(glsl_effect_red, (float)Math.min(2 * (0.25 - player_health), 0.5));
GL33.glUniform1i(glsl_effect_red_freq, 20); GL33.glUniform1i(glsl_effect_red_freq, 20);
} else { } else {
GL33.glUniform1f(glsl_effect_red, 0); GL33.glUniform1f(glsl_effect_red, 0);

View File

@ -12,14 +12,12 @@ import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i; import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import mainloop.task.IMainloopTask;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.init.Entities; import projectzombie.init.Entities;
import projectzombie.model.IModel; import projectzombie.model.IModel;
import projectzombie.tiles.Tile; import projectzombie.tiles.Tile;
import projectzombie.util.math.TileState; import projectzombie.util.math.TileState;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.chunk.ChunkEventHandler;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
public abstract class Entity implements IBdfClassManager public abstract class Entity implements IBdfClassManager
@ -27,8 +25,8 @@ public abstract class Entity implements IBdfClassManager
public double hitbox = 1; public double hitbox = 1;
public boolean isSolid = false; public boolean isSolid = false;
public Chunk chunk; public Chunk chunk;
private TileState tile_front; protected TileState tile_front;
private TileState tile_back; protected TileState tile_back;
protected static final Random rand = new Random(); protected static final Random rand = new Random();
public boolean emitsLight = false; public boolean emitsLight = false;
private boolean isDead = false; private boolean isDead = false;
@ -74,8 +72,8 @@ public abstract class Entity implements IBdfClassManager
} }
public int getID() { public int getID() {
for(int i=0;i<Entities.entities.size();i++) { for(int i=0;i<Entities.ENTITIES.size();i++) {
Class<? extends Entity> ec = Entities.entities.get(i); Class<? extends Entity> ec = Entities.ENTITIES.get(i);
if(ec == this.getClass()) { if(ec == this.getClass()) {
return i; return i;
} }
@ -92,13 +90,13 @@ public abstract class Entity implements IBdfClassManager
int id = nl.get("id").getInteger(); int id = nl.get("id").getInteger();
// Send back null if the id is out of range // Send back null if the id is out of range
if(id < 0 || id >= Entities.entities.size()) { if(id < 0 || id >= Entities.ENTITIES.size()) {
System.out.println("Warning: Invalid ID detected: " + id); System.out.println("Warning: Invalid ID detected: " + id);
return null; return null;
} }
// Get the class and the constructor // Get the class and the constructor
Class<? extends Entity> ecl = Entities.entities.get(id); Class<? extends Entity> ecl = Entities.ENTITIES.get(id);
Constructor<? extends Entity> econ = ecl.getConstructor(BdfObject.class); Constructor<? extends Entity> econ = ecl.getConstructor(BdfObject.class);
// Send back the new entity // Send back the new entity
@ -171,46 +169,63 @@ public abstract class Entity implements IBdfClassManager
{ {
//speed = 1; //speed = 1;
//angle = MathHelpers.mod(angle, 360); //angle = MathHelpers.mod(angle, 360);
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
if(chunk == null) chunk = layer.getChunk(pos.xz()); if(chunk == null) chunk = layer.getChunk(pos.xz());
this.chunk = chunk; this.chunk = chunk;
Vec2i tpos = pos.xz().toInt();
tile_back = chunk.getBackTile(tpos); tile_back = chunk.getBackTile(tpos);
tile_front = chunk.getFrontTile(tpos); tile_front = chunk.getFrontTile(tpos);
Vec3d new_pos = pos.add(velocity); if(velocity.x != 0 || velocity.y != 0 || velocity.z != 0)
{
if(isSolid) { Vec3d new_pos = pos.add(velocity);
if(moveIsLegal(new Vec2d(new_pos.x, pos.z))) {
pos.x = new_pos.x; double slipperiness = Math.max(
tile_back.tile.getSlipperiness(tile_back),
tile_front.tile.getSlipperiness(tile_front));
if(isSolid) {
if(moveIsLegal(new Vec2d(new_pos.x, pos.z))) {
pos.x = new_pos.x;
} else {
velocity.x *= -0.25;
}
if(moveIsLegal(new Vec2d(pos.x, new_pos.z))) {
pos.z = new_pos.z;
} else {
velocity.z *= -0.25;
}
} else { } else {
velocity.x *= 0.5; pos.x = new_pos.x;
pos.z = new_pos.z;
} }
if(moveIsLegal(new Vec2d(pos.x, new_pos.z))) { if(new_pos.y > 0) {
pos.z = new_pos.z; pos.y = new_pos.y;
} else { } else {
velocity.z *= 0.5; velocity.y *= -0.25;
velocity.x *= slipperiness;
velocity.z *= slipperiness;
pos.y = 0;
} }
} else {
pos.x = new_pos.x;
pos.z = new_pos.z;
}
if(new_pos.y > 0) {
pos.y = new_pos.y;
} else {
velocity.y = 0;
velocity.x *= 0.75;
velocity.z *= 0.75;
pos.y = 0;
} }
if(hasGravity) { if(hasGravity) {
velocity.y -= MathHelpers.FallSpeed; velocity.y -= MathHelpers.FallSpeed;
} }
if(isSolid) { if(isSolid)
{
moveAwayFromSolidEntities(layer); moveAwayFromSolidEntities(layer);
if(pos.y <= 0) {
tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back);
tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front);
}
} }
} }
@ -233,8 +248,31 @@ public abstract class Entity implements IBdfClassManager
} }
} }
public void push(Vec3d vec) { public void push(Vec3d vec)
velocity = velocity.add(vec); {
if(pos.y <= 0)
{
Layer layer = Main.world.getLayer();
Vec2i tpos = pos.xz().toInt();
tile_back = layer.getBackTile(tpos);
tile_front = layer.getFrontTile(tpos);
double slipperiness = Math.max(
tile_back.tile.getSlipperiness(tile_back),
tile_front.tile.getSlipperiness(tile_front));
double resistance = Math.max(
tile_back.tile.getResistance(tile_back),
tile_front.tile.getResistance(tile_front));
velocity = velocity.add(vec.multiply((1 - slipperiness) * (1 - resistance)));
}
else
{
velocity = velocity.add(vec);
}
} }
public void kill() { public void kill() {
@ -285,7 +323,8 @@ public abstract class Entity implements IBdfClassManager
if(t.tileSolid) if(t.tileSolid)
{ {
// Is the entity in the tiles hitbox // Is the entity in the tiles hitbox
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox) Vec2d check = pos.subtract(new Vec2d(tpos.x + 0.5, tpos.y + 0.5));
if(Math.max(Math.abs(check.x), Math.abs(check.y)) <= t.tileHitbox)
{ {
// Send back false // Send back false
return false; return false;
@ -301,7 +340,8 @@ public abstract class Entity implements IBdfClassManager
if(t.tileSolid) if(t.tileSolid)
{ {
// Is the entity in the tiles hitbox // Is the entity in the tiles hitbox
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox) Vec2d check = pos.subtract(new Vec2d(tpos.x + 0.5, tpos.y + 0.5));
if(Math.max(Math.abs(check.x), Math.abs(check.y)) <= t.tileHitbox)
{ {
// Send back false // Send back false
return false; return false;

View File

@ -5,7 +5,6 @@ import projectzombie.world.layer.Layer;
public interface EntityAlive public interface EntityAlive
{ {
public void addHealth(double amount); public void addHealth(double amount);
public void removeHealth(double amount);
public double getHealth(); public double getHealth();
public void resetHealth(); public void resetHealth();
public void clearHealth(); public void clearHealth();
@ -13,6 +12,10 @@ public interface EntityAlive
public void setHealth(double health); public void setHealth(double health);
public int bloodParticles(); public int bloodParticles();
public void addDamage(double amount);
public void addFireDamage(double amount);
public void addBlastDamage(double amount);
public default void onDeath(Layer layer) { public default void onDeath(Layer layer) {
} }
} }

View File

@ -115,11 +115,9 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic
Vec2d zombie_pos = new Vec2d( Vec2d zombie_pos = new Vec2d(
RandomHelpers.randrange(rand, -r*m, r*m)/(double)m, RandomHelpers.randrange(rand, -r*m, r*m)/(double)m,
RandomHelpers.randrange(rand, -r*m, r*m)/(double)m); RandomHelpers.randrange(rand, -r*m, r*m)/(double)m);
Vec2i zombie_tpos = new Vec2i( Vec2i zombie_tpos = zombie_pos.toInt();
MathHelpers.floor(zombie_pos.x),
MathHelpers.floor(zombie_pos.y));
if( if(
layer.getBackTile(zombie_tpos).tile == layer.layergen.getTileDestroyed().tile && layer.getBackTile(zombie_tpos).tile == layer.layergen.getTileDestroyed(layer, zombie_tpos).tile &&
layer.getFrontTile(zombie_tpos).tile == Tiles.VOID) { layer.getFrontTile(zombie_tpos).tile == Tiles.VOID) {
layer.spawnEntity(new EntityZombie(bpos.add(zombie_pos.xny()), getVelocity())); layer.spawnEntity(new EntityZombie(bpos.add(zombie_pos.xny()), getVelocity()));
} }
@ -165,9 +163,19 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic
} }
@Override @Override
public void removeHealth(double amount) { public void addDamage(double amount) {
this.health -= amount; this.health -= amount;
} }
@Override
public void addFireDamage(double amount) {
}
@Override
public void addBlastDamage(double amount) {
addDamage(amount);
}
@Override @Override
public double getHealth() { public double getHealth() {
@ -210,7 +218,7 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic
} }
public void moveTowards(double angle) { public void moveTowards(double angle) {
this.push(MathHelpers.moveTowards2(0.01, Math.toRadians(angle)).xny()); this.push(MathHelpers.moveTowards2(0.04, Math.toRadians(angle)).xny());
} }
@Override @Override
@ -221,16 +229,7 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic
Drop some powerful loot Drop some powerful loot
*/ */
// Pick level 5 defence or level 5 gun upgrade
ItemStack stack;
if(rand.nextBoolean()) {
stack = new ItemStack(Items.DEFENCE_UPGRADE, 1, (byte)6);
} else {
stack = new ItemStack(Items.GUN_UPGRADE, 1, (byte)6);
}
// Spawn the loot // Spawn the loot
layer.spawnEntity(new EntityItem(getPos(), getVelocity(), stack));
layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack( layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack(
Items.HEALTH_POTION, RandomHelpers.randrange(rand, 20), (byte)50))); Items.HEALTH_POTION, RandomHelpers.randrange(rand, 20), (byte)50)));
layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack( layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack(

View File

@ -2,12 +2,13 @@ package projectzombie.entity;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.MathHelpers; import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i; import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.entity.particle.ParticleBlood; import projectzombie.entity.particle.ParticleBlood;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.init.Resources;
import projectzombie.init.Sounds; import projectzombie.init.Sounds;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.tiles.Tile; import projectzombie.tiles.Tile;
@ -18,6 +19,8 @@ import projectzombie.world.layer.Layer;
public class EntityBullet extends EntityParticle public class EntityBullet extends EntityParticle
{ {
private static final TextureRef3D BULLET = Resources.ATLAS.get("/particle/bullet.png");
private int time = 0; private int time = 0;
private Entity parent; private Entity parent;
@ -111,9 +114,7 @@ public class EntityBullet extends EntityParticle
EntityAlive ea = (EntityAlive)e; EntityAlive ea = (EntityAlive)e;
// Spawn some blood particles // Spawn some blood particles
if(!EntityParticle.DISABLED) { chunk.spawnEntity(new ParticleBlood(getPos(), e.getVelocity().add(getVelocity()).divide(8)));
chunk.spawnEntity(new ParticleBlood(getPos(), e.getVelocity().add(getVelocity()).divide(8)));
}
// Knock the entity back abit // Knock the entity back abit
e.push(getVelocity()); e.push(getVelocity());
@ -124,7 +125,7 @@ public class EntityBullet extends EntityParticle
Sounds.HIT.play(new Vec3d(pos.x, pos.y, pos.z), 1); Sounds.HIT.play(new Vec3d(pos.x, pos.y, pos.z), 1);
// Harm the entity // Harm the entity
ea.removeHealth(damage); ea.addDamage(damage);
// Kill the bullet // Kill the bullet
chunk.killEntity(this); chunk.killEntity(this);
@ -139,9 +140,19 @@ public class EntityBullet extends EntityParticle
chunk.killEntity(this); chunk.killEntity(this);
} }
} }
@Override
public int getParticleCount() {
return 1;
}
@Override @Override
public Model getModel() { public boolean shouldKillParticle() {
return Models.PARTICLE_BULLET; return false;
}
@Override
public EntityParticlePart getParticleAt(int id) {
return new EntityParticlePart(BULLET, getPos(), 0.1, 0b1000);
} }
} }

View File

@ -3,7 +3,6 @@ package projectzombie.entity;
import bdf.types.BdfArray; import bdf.types.BdfArray;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.Model; import projectzombie.model.Model;

View File

@ -1,7 +1,6 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.Model; import projectzombie.model.Model;
@ -24,11 +23,25 @@ public class EntityDummy extends Entity implements EntityAlive
} }
@Override @Override
public void removeHealth(double amount) { public void addDamage(double amount) {
int l = 4; int l = 4;
amount = amount / (l / 2.5 + 1); amount = amount / (l / 2.5 + 1);
System.out.println("Dummy Damage Aount: "+amount); System.out.println("Dummy Damage Aount: "+amount);
} }
@Override
public void addFireDamage(double amount) {
int l = 4;
amount = amount / (l / 2.5 + 1);
System.out.println("Dummy Fire Damage Aount: "+amount);
}
@Override
public void addBlastDamage(double amount) {
int l = 4;
amount = amount / (l / 2.5 + 1);
System.out.println("Dummy Blast Damage Aount: "+amount);
}
@Override @Override
public double getHealth() { public double getHealth() {

View File

@ -55,7 +55,7 @@ public class EntityExplosion extends Entity
super.tick(chunk, layer); super.tick(chunk, layer);
boolean killed_entities = false; boolean killed_entities = false;
Vec2d pos = getPos().xy(); Vec2d pos = getPos().xz();
// Kill all the nearby entities // Kill all the nearby entities
for(Entity e : layer.getNearbyEntities(pos, radius)) for(Entity e : layer.getNearbyEntities(pos, radius))
@ -70,11 +70,11 @@ public class EntityExplosion extends Entity
double distance = e.getPos().distance(getPos()); double distance = e.getPos().distance(getPos());
if(distance == 0) { if(distance == 0) {
ea.removeHealth(damage); ea.addBlastDamage(damage);
} }
else { else {
ea.removeHealth(damage / distance); ea.addBlastDamage(damage / distance);
} }
} }
} }
@ -106,7 +106,7 @@ public class EntityExplosion extends Entity
TileState fts = l.getFrontTile(tpos); TileState fts = l.getFrontTile(tpos);
// Is this tile the same as the "empty" tile // Is this tile the same as the "empty" tile
TileState ets = l.layergen.getTileDestroyed(); TileState ets = l.layergen.getTileDestroyed(layer, tpos);
// Set the tiles // Set the tiles
if(!bts.tile.unbreakable) { if(!bts.tile.unbreakable) {
@ -125,12 +125,21 @@ public class EntityExplosion extends Entity
continue; continue;
} }
Vec3d spos = new Vec3d(px, 0, py);
Vec3d svel;
if(distance == 0) {
svel = MathHelpers.moveTowards2(0.01, Math.random() * MathHelpers.TWO_PI).xny();
} else {
svel = spos.xz().subtract(pos).divide(distance * 100).xny();
}
// Spawn some blood if entities were killed // Spawn some blood if entities were killed
if(killed_entities) if(killed_entities)
entities[upto + 1] = new ParticleBlood(new Vec3d(px, 0, py), new Vec3d(0, 0, 0)); entities[upto + 1] = new ParticleBlood(new Vec3d(px, 0, py), new Vec3d(0, 0, 0), 1);
// Spawn some smoke // Spawn some smoke
entities[upto] = new ParticleSmoke(new Vec3d(px, 0, py), new Vec3d(0, 0, 0)); entities[upto] = new ParticleSmoke(spos, svel);
upto += multiplier; upto += multiplier;
} }
@ -140,7 +149,7 @@ public class EntityExplosion extends Entity
layer.spawnEntity(new EntityContainer(getPos(), getVelocity(), entities)); layer.spawnEntity(new EntityContainer(getPos(), getVelocity(), entities));
// Play the explosion sound // Play the explosion sound
Sounds.EXPLOSION.play(new Vec3d(pos.x, pos.y, 0), 1); Sounds.EXPLOSION.play(new Vec3d(pos.x, 0, pos.y), 1);
// Kill the explosion entity // Kill the explosion entity
kill(); kill();

View File

@ -1,7 +1,6 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.Model; import projectzombie.model.Model;
@ -25,20 +24,7 @@ public class EntityFlare extends EntityTnt
} }
@Override @Override
public double getLightLevel() public double getLightLevel() {
{
if(this.explode_time > 1950) {
return 0;
}
if(this.explode_time > 1900) {
return (1950 - this.explode_time) / 50.0;
}
if(this.explode_time < 200) {
return this.explode_time / 200.0;
}
return 1; return 1;
} }

View File

@ -2,7 +2,6 @@ package projectzombie.entity;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;

View File

@ -0,0 +1,8 @@
package projectzombie.entity;
import projectzombie.inventory.IInventoryArmor;
import projectzombie.inventory.InventoryArmor;
public interface EntityHasArmor {
public IInventoryArmor getInventoryArmor();
}

View File

@ -0,0 +1,9 @@
package projectzombie.entity;
import projectzombie.inventory.IInventoryClothing;
import projectzombie.inventory.InventoryArmor;
import projectzombie.inventory.InventoryClothing;
public interface EntityHasClothing {
public IInventoryClothing getInventoryClothing();
}

View File

@ -0,0 +1,9 @@
package projectzombie.entity;
import projectzombie.inventory.IInventory;
import projectzombie.inventory.Inventory;
public interface EntityHasInventory
{
public IInventory getInventory();
}

View File

@ -0,0 +1,8 @@
package projectzombie.entity;
import projectzombie.task.Task;
public interface EntityHasTasks
{
public void addTask(Task task);
}

View File

@ -1,8 +0,0 @@
package projectzombie.entity;
import projectzombie.inventory.Inventory;
public interface EntityInventory
{
public Inventory getInventory();
}

View File

@ -3,15 +3,14 @@ package projectzombie.entity;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.MathHelpers; import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.model.ModelItem;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
import projectzombie.util.math.random.RandomHelpers;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
public class EntityItem extends Entity public class EntityItem extends EntityParticle
{ {
private ItemStack stack; private ItemStack stack;
private int pickup_time = 200; private int pickup_time = 200;
@ -51,7 +50,7 @@ public class EntityItem extends Entity
this.emitsLight = true; this.emitsLight = true;
this.stack = stack; this.stack = stack;
push(new Vec3d(MathHelpers.moveTowards2(0.025, angle), 0.025)); push(MathHelpers.moveTowards2(0.05, angle).xny().add(new Vec3d(0, 0.1, 0)));
} }
public EntityItem(Vec3d pos, Vec3d velocity, ItemStack stack) { public EntityItem(Vec3d pos, Vec3d velocity, ItemStack stack) {
@ -69,9 +68,10 @@ public class EntityItem extends Entity
super.tick(chunk, layer); super.tick(chunk, layer);
age += 1; age += 1;
pickup_time -= 1;
// Merge nearby stacks // Merge nearby stacks
for(Entity e : layer.getNearbyEntities(getPos().xz(), 1)) for(Entity e : layer.getNearbyEntities(getPos().xz(), 2))
{ {
if(e instanceof EntityItem && e != this) { if(e instanceof EntityItem && e != this) {
EntityItem ei = (EntityItem) e; EntityItem ei = (EntityItem) e;
@ -79,25 +79,29 @@ public class EntityItem extends Entity
if( if(
ei.stack.meta == this.stack.meta && ei.stack.meta == this.stack.meta &&
ei.stack.item == this.stack.item && ei.stack.item == this.stack.item &&
ei.stack.count + this.stack.count <= this.stack.item.max &&
ei.age > this.age ei.age > this.age
) { ) {
this.pickup_time = 200; if(ei.getPos().squareDistance(getPos()) < 0.1) {
this.stack.count += ei.stack.count; this.pickup_time = 200;
setPos(ei.getPos().divide(2).add(getPos().divide(2))); this.stack.count += ei.stack.count;
setVelocity(ei.getVelocity().divide(2).add(getVelocity().divide(2))); setPos(ei.getPos().divide(2).add(getPos().divide(2)));
ei.kill(); setVelocity(ei.getVelocity().divide(2).add(getVelocity().divide(2)));
ei.kill();
}
else {
push(ei.getPos().subtract(getPos()).normalize().multiply(0.001));
}
} }
} }
}
if(pickup_time <= 0 && e instanceof EntityHasInventory)
if(pickup_time == 0)
{
for(Entity e : layer.getNearbyEntities(getPos().xz(), 1))
{ {
if(e instanceof EntityInventory) if(e.getPos().squareDistance(getPos()) < 0.5) {
{
// Pick the stack up if its an inventory
stack.item.onPickedUp(stack, layer, chunk, e); stack.item.onPickedUp(stack, layer, chunk, e);
} else {
push(e.getPos().subtract(getPos()).normalize().multiply(0.05));
} }
} }
} }
@ -108,10 +112,24 @@ public class EntityItem extends Entity
return; return;
} }
} }
@Override
public boolean shouldKillParticle() {
return false;
}
@Override @Override
public Model getModel() { public EntityParticlePart getParticleAt(int id) {
return stack.item.getModel(stack.meta).getItemModel(); ModelItem model = stack.item.getModel(stack.meta);
EntityParticlePart particle = new EntityParticlePart(model.tex, getPos().add(new Vec3d(0, 0.25, 0)), 0.5, 0b1000);
particle.animationSize = model.animationSize;
particle.animationSpeed = model.animationSpeed;
return particle;
}
@Override
public int getParticleCount() {
return 1;
} }

View File

@ -1,17 +1,16 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.model.IModel;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
public abstract class EntityParticle extends Entity public abstract class EntityParticle extends Entity
{ {
public static boolean DISABLED = false; public abstract int getParticleCount();
protected TextureRef3D tex; public abstract EntityParticlePart getParticleAt(int id);
public EntityParticle(BdfObject bdf) { public EntityParticle(BdfObject bdf) {
super(bdf); super(bdf);
@ -26,6 +25,15 @@ public abstract class EntityParticle extends Entity
super.tick(chunk, layer); super.tick(chunk, layer);
// Kill the particle if the player can't see it to reduce lag // Kill the particle if the player can't see it to reduce lag
if(Main.player.getPos().squareDistance(getPos()) > Chunk.RENDER_DISTANCE * 16) this.kill(); if(shouldKillParticle()) this.kill();
}
public boolean shouldKillParticle() {
return Main.player.getPos().squareDistance(getPos()) > Chunk.RENDER_DISTANCE * 16;
}
@Override
public IModel getModel() {
return null;
} }
} }

View File

@ -0,0 +1,29 @@
package projectzombie.entity;
import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec3d;
public class EntityParticlePart
{
public int animationSize = 1;
public int animationSpeed = 1;
public TextureRef3D tex;
public double size;
public Vec3d pos;
public int flags;
public double getFade() {
return 1;
}
public boolean isFlat() {
return false;
}
public EntityParticlePart(TextureRef3D tex, Vec3d pos, double size, int flags) {
this.tex = tex;
this.pos = pos;
this.size = size;
this.flags = flags;
}
}

View File

@ -27,7 +27,7 @@ public class EntityTnt extends Entity implements EntityHoldsEntities
public EntityTnt(BdfObject bdf) { public EntityTnt(BdfObject bdf) {
super(bdf); super(bdf);
this.smoke_particles = new ParticleSmokeTrail(this, 1); this.smoke_particles = new ParticleSmokeTrail(this);
} }
@Override @Override
@ -53,13 +53,13 @@ public class EntityTnt extends Entity implements EntityHoldsEntities
} }
public EntityTnt(Vec3d pos, Vec3d velocity, double angle, int explode_radius, double explode_damage) { public EntityTnt(Vec3d pos, Vec3d velocity, double angle, int explode_radius, double explode_damage) {
super(pos, velocity); super(pos, velocity.add(new Vec3d(0, 0.1, 0)));
Vec2d v = MathHelpers.moveTowards2(0.05, Math.toRadians(angle)); Vec2d v = MathHelpers.moveTowards2(0.05, Math.toRadians(angle));
velocity = velocity.add(new Vec3d(v.x, v.y, 0.01)); velocity = velocity.add(new Vec3d(v.x, v.y, 0.01));
this.explode_radius = explode_radius; this.explode_radius = explode_radius;
this.explode_damage = explode_damage; this.explode_damage = explode_damage;
this.smoke_particles = new ParticleSmokeTrail(this, 1); this.smoke_particles = new ParticleSmokeTrail(this);
// Set to 2.5 seconds // Set to 2.5 seconds
this.explode_time = 250; this.explode_time = 250;
@ -78,8 +78,6 @@ public class EntityTnt extends Entity implements EntityHoldsEntities
if(!active) if(!active)
{ {
smoke_particles.stopParticles();
if(smoke_particles.noMoreParticles()) { if(smoke_particles.noMoreParticles()) {
kill(); kill();
} }
@ -90,6 +88,7 @@ public class EntityTnt extends Entity implements EntityHoldsEntities
// Explode if it is time for the tnt to blow up // Explode if it is time for the tnt to blow up
explode_time -= 1; explode_time -= 1;
if(explode_time < 0) { if(explode_time < 0) {
smoke_particles.stopParticles();
active = false; active = false;
explode(layer); explode(layer);
} }

View File

@ -4,8 +4,6 @@ import java.util.Random;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i; import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main; import projectzombie.Main;
@ -137,11 +135,7 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP
// Walk towards the player // Walk towards the player
if(walk_to != null) if(walk_to != null)
{ {
push(walk_to.subtract(getPos()).normalize().multiply(0.016)); push(walk_to.subtract(getPos()).normalize().multiply(0.064));
if(Double.isNaN(walk_to.x + walk_to.y + walk_to.z + getPos().x + getPos().y + getPos().z + getVelocity().x + getVelocity().y + getVelocity().z)) {
Double.isFinite(0);
}
walking_for += 1; walking_for += 1;
} }
@ -157,7 +151,7 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP
int d = (int)(1 + gun_level / 5.0); int d = (int)(1 + gun_level / 5.0);
Vec3d bullet_velocity = getVelocity().add(Main.player.getPos().subtract(getPos())).normalize().multiply(0.2); Vec3d bullet_velocity = getVelocity().add(Main.player.getPos().subtract(getPos())).normalize().multiply(0.2);
Vec3d bullet_pos = getPos().add(new Vec3d(0, 0.4, 0)); Vec3d bullet_pos = getPos().add(new Vec3d(0, 0.4, 0));
//Main.world.getLayer().spawnEntity(new EntityBullet(bullet_pos, bullet_velocity, this, 20*d*d, 60)); Main.world.getLayer().spawnEntity(new EntityBullet(bullet_pos, bullet_velocity, this, 20*d*d, 60));
} }
} }
} }
@ -177,9 +171,19 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP
} }
@Override @Override
public void removeHealth(double amount) { public void addDamage(double amount) {
health -= amount; health -= amount;
} }
@Override
public void addBlastDamage(double amount) {
addDamage(amount);
}
@Override
public void addFireDamage(double amount) {
addDamage(amount);
}
@Override @Override
public double getHealth() { public double getHealth() {

View File

@ -1,7 +1,6 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.Model; import projectzombie.model.Model;

View File

@ -1,6 +1,5 @@
package projectzombie.entity.particle; package projectzombie.entity.particle;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.init.Models; import projectzombie.init.Models;
@ -11,12 +10,12 @@ public class ParticleBlood extends ParticleBreak
} }
public ParticleBlood(Vec3d pos, Vec3d velocity) { public ParticleBlood(Vec3d pos, Vec3d velocity) {
this(pos, velocity, 400); this(pos, velocity, 100);
} }
@Override @Override
public Vec2d getParticleSize() { public double getParticleSize() {
return new Vec2d(0.05, 0.05); return 0.05;
} }
} }

View File

@ -1,49 +1,59 @@
package projectzombie.entity.particle; package projectzombie.entity.particle;
import static org.lwjgl.opengl.GL15.glBindBuffer;
import static org.lwjgl.opengl.GL15.glBufferData;
import static org.lwjgl.opengl.GL15.glGenBuffers;
import java.util.Random; import java.util.Random;
import org.lwjgl.opengl.GL33;
import gl_engine.MathHelpers; import gl_engine.MathHelpers;
import gl_engine.matrix.Matrix4;
import gl_engine.texture.TextureRef3D; import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.init.Models; import projectzombie.entity.EntityParticlePart;
import projectzombie.model.IModel; import projectzombie.model.IModel;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.model.ModelVertical;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
public class ParticleBreak extends EntityParticle implements IModel public class ParticleBreak extends EntityParticle
{ {
protected static final Random rand = new Random(); protected static final Random rand = new Random();
protected class Break { protected class Break extends EntityParticlePart
TextureRef3D ref; {
Vec3d velocity; public Vec3d velocity;
Vec3d pos; public boolean moving;
boolean moving;
int time, flags; public Break(TextureRef3D tex, Vec3d pos, Vec3d velocity, boolean moving, double size, int flags) {
super(tex, pos, size, flags);
this.velocity = velocity;
this.moving = moving;
}
@Override
public boolean isFlat() {
return isStill(this);
}
@Override
public double getFade() {
return getParticleFade();
}
} }
protected Break[] particles; protected Break[] particles;
private int ibo, vbo, vao; protected int still, time;
private boolean generated;
protected int dead, still, time;
protected double still_ypos; protected double still_ypos;
protected boolean do_gravity;
public Vec2d getParticleSize() { protected double getParticleFade() {
return new Vec2d(0.1, 0.1); return time / 1000.0;
}
public double getParticleSize() {
return 0.1;
}
protected double getParticleSpeed() {
return 0.01;
} }
public ParticleBreak(Vec3d pos, Vec3d velocity, IModel model) { public ParticleBreak(Vec3d pos, Vec3d velocity, IModel model) {
@ -54,24 +64,6 @@ public class ParticleBreak extends EntityParticle implements IModel
this(pos, velocity, model, count, 0.05); this(pos, velocity, model, count, 0.05);
} }
protected Break createParticle(
IModel model, TextureRef3D ref, int tex_id,
Vec3d pos, Vec3d velocity, float[] verticies,
double velocity_up_multiplier, double model_height, int i)
{
Break particle = new Break();
particle.pos = pos.add(new Vec3d(0, rand.nextDouble() * model_height, 0));
particle.velocity = velocity.multiply(rand.nextDouble()).add(
MathHelpers.moveTowards2(0.01, rand.nextDouble() * MathHelpers.TWO_PI).xny().add(
new Vec3d(0, rand.nextDouble() * velocity_up_multiplier, 0)));
particle.ref = ref;
particle.moving = true;
particle.flags = ((int)verticies[tex_id * Model.SIZE + Model.SIZE - 1] & 0b0110) | 0b1000;
return particle;
}
protected ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count, double velocity_up_multiplier) { protected ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count, double velocity_up_multiplier) {
super(new Vec3d(pos.x, 0, pos.z), new Vec3d(0, 0, 0)); super(new Vec3d(pos.x, 0, pos.z), new Vec3d(0, 0, 0));
@ -81,66 +73,61 @@ public class ParticleBreak extends EntityParticle implements IModel
this.hasGravity = false; this.hasGravity = false;
double model_height = model.getHeight(); double model_height = getHeight(model);
TextureRef3D[] textures = model.getTextures();
float[] verticies = model.getVerticies(); float[] verticies = model.getVerticies();
count *= model_height; if(model_height > 1) {
count *= model_height;
}
if(model.getSize() == 0) {
count = 0;
}
particles = new Break[count]; particles = new Break[count];
for(int i=0;i<particles.length;i++) for(int i=0;i<particles.length;i++)
{ {
int tex_id = (int)(rand.nextDouble() * textures.length); int[] tex_id = {0};
TextureRef3D texture = textures[tex_id]; TextureRef3D ref = model.getRandomChunk(tex_id);
TextureRef3D ref = new TextureRef3D();
float dx = texture.ex - texture.sx; Break particle = new Break(ref,
float dy = texture.ey - texture.sy; pos.add(new Vec3d(0, rand.nextDouble() * model_height, 0)),
float w = (float)model.getWidth(); velocity.multiply(rand.nextDouble()).add(
float h = (float)model.getHeight(); MathHelpers.moveTowards2(getParticleSpeed(), rand.nextDouble() * MathHelpers.TWO_PI).xny().add(
new Vec3d(0, rand.nextDouble() * velocity_up_multiplier, 0))), true, getParticleSize(),
ref.sx = (float)MathHelpers.map((int)(rand.nextDouble()*16*w), 0, 16*w, texture.sx, texture.ex - dx/(16*w)); ((int)verticies[tex_id[0] * Model.SIZE + Model.SIZE - 1] & 0b0110) | 0b1000);
ref.sy = (float)MathHelpers.map((int)(rand.nextDouble()*16*h), 0, 16*h, texture.sy, texture.ey - dy/(16*h));
ref.ex = ref.sx + dx/(16*w);
ref.ey = ref.sy + dy/(16*h);
ref.texmap = texture.texmap;
ref.z = texture.z;
Break particle = createParticle(
model, ref, tex_id, pos, velocity,
verticies, velocity_up_multiplier,
model_height, i);
particles[i] = particle; particles[i] = particle;
} }
still_ypos = 0.0125;
time = 1000; time = 1000;
generated = false;
do_gravity = true;
still = 0; still = 0;
dead = 0; }
protected double getHeight(IModel model) {
return model.getHeight();
} }
protected void onAllStill() { protected void onAllStill() {
if(time < 0 && rand.nextDouble() > 0.75) { if(time < 0) {
dead += 1; onAllDead();
} }
} }
protected void onAllDead() { protected void onAllDead() {
if(getPos().squareDistance(Main.player.getPos()) > 32) { kill();
kill();
}
} }
protected boolean isStill(Break particle) { protected boolean isStill(Break particle) {
return particle.pos.y < 0; return particle.pos.y <= still_ypos;
} }
protected void onStill(Break particle) { protected void onStill(Break particle) {
particle.moving = false; particle.moving = false;
particle.pos.y = still_ypos; particle.pos.y = still_ypos;
particle.flags &= 0b0110;
still += 1; still += 1;
} }
@ -154,17 +141,12 @@ public class ParticleBreak extends EntityParticle implements IModel
time -= 1; time -= 1;
if(dead == particles.length - 1) {
onAllDead();
return;
}
if(still == particles.length) { if(still == particles.length) {
onAllStill(); onAllStill();
return; return;
} }
for(int i=0;i<(particles.length - dead);i++) for(int i=0;i<particles.length;i++)
{ {
Break particle = particles[i]; Break particle = particles[i];
@ -177,204 +159,24 @@ public class ParticleBreak extends EntityParticle implements IModel
continue; continue;
} }
if(do_gravity) { particle.velocity.y -= MathHelpers.FallSpeed;
particle.velocity.y -= MathHelpers.FallSpeed;
}
particle.pos = particle.pos.add(particle.velocity); particle.pos = particle.pos.add(particle.velocity);
} }
} }
@Override @Override
public void kill() { public IModel getModel() {
this.free(); return null;
super.kill();
} }
@Override @Override
public IModel getModel() public int getParticleCount() {
{ return particles.length;
if(isDead()) {
return Models.EMPTY;
}
return this;
} }
@Override @Override
public int[] getIndicies() public EntityParticlePart getParticleAt(int id) {
{ return particles[id];
int[] indicies = new int[getIndexSize()];
int upto = 0;
for(int i=0;i<indicies.length;i+=6)
{
indicies[i+0] = upto+0;
indicies[i+1] = upto+1;
indicies[i+2] = upto+2;
indicies[i+3] = upto+2;
indicies[i+4] = upto+3;
indicies[i+5] = upto+0;
upto += 4;
}
return indicies;
}
@Override
public float[] getVerticies()
{
float[] verticies = new float[getSize() * Model.SIZE];
Vec3d ppos = getPos();
int upto = 0;
float k = Model.OFFSET;
float x = (float)getParticleSize().x/2;
float y = (float)getParticleSize().y;
for(int i=0;i<(particles.length - dead);i++)
{
Break particle = particles[i];
TextureRef3D ref = particle.ref;
float f = particle.flags;
float px = (float)(particle.pos.x - ppos.x);
float py = (float)(particle.pos.y - ppos.y);
float pz = (float)(particle.pos.z - ppos.z);
float a = y, b = 0, c = 0;
if(!particle.moving) {
f = particle.flags & 0b0110;
a = 0.001f;
b = y / 2;
c = a;
}
float[] p = {
-x, c,-b, ref.sx+k, ref.sy+k, ref.z, ref.sy, ref.ey, px, py, pz, 1, 1, f,
x, c,-b, ref.ex-k, ref.sy+k, ref.z, ref.sy, ref.ey, px, py, pz, 1, 1, f,
x, a, b, ref.ex-k, ref.ey-k, ref.z, ref.sy, ref.ey, px, py, pz, 1, 1, f,
-x, a, b, ref.sx+k, ref.ey-k, ref.z, ref.sy, ref.ey, px, py, pz, 1, 1, f,
};
for(int j=0;j<p.length;j++) {
verticies[upto+j] = p[j];
}
upto += 4*Model.SIZE;
}
return verticies;
}
@Override
public TextureRef3D[] getTextures()
{
TextureRef3D[] textures = new TextureRef3D[getSize()];
int upto = 0;
for(int i=0;i<particles.length;i++) {
textures[upto+0] = particles[i].ref;
textures[upto+1] = particles[i].ref;
textures[upto+2] = particles[i].ref;
textures[upto+3] = particles[i].ref;
upto += 4;
}
return textures;
}
@Override
public double getHeight() {
return 1;
}
@Override
public int getIndexSize() {
return 6 * (particles.length - dead);
}
@Override
public int getSize() {
return 4 * (particles.length - dead);
}
@Override
public void bind()
{
if(isDead()) {
return;
}
if(!generated)
{
int[] indicies = this.getIndicies();
vao = GL33.glGenVertexArrays();
GL33.glBindVertexArray(vao);
vbo = GL33.glGenBuffers();
GL33.glBindBuffer(GL33.GL_ARRAY_BUFFER, vbo);
GL33.glBufferData(GL33.GL_ARRAY_BUFFER, getVerticies(), GL33.GL_DYNAMIC_DRAW);
Model.setGLArrayAttributes();
ibo = glGenBuffers();
glBindBuffer(GL33.GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL33.GL_ELEMENT_ARRAY_BUFFER, indicies, GL33.GL_STATIC_DRAW);
}
else {
GL33.glBindVertexArray(vao);
}
generated = true;
Model.bound = this;
}
@Override
public void render()
{
if(isDead()) {
return;
}
if(Model.bound != this) {
bind();
}
if(still != particles.length) {
GL33.glBindBuffer(GL33.GL_ARRAY_BUFFER, vbo);
GL33.glBufferSubData(GL33.GL_ARRAY_BUFFER, 0, getVerticies());
}
GL33.glDrawElements(GL33.GL_TRIANGLES, getIndexSize(), GL33.GL_UNSIGNED_INT, 0);
}
@Override
public void free()
{
if(generated)
{
GL33.glDeleteBuffers(ibo);
GL33.glDeleteBuffers(vbo);
GL33.glDeleteVertexArrays(vao);
generated = false;
}
}
public void setModel(Matrix4 model) {
GL33.glUniformMatrix4fv(Main.window.glsl_model, true, model.getArray());
}
@Override
public boolean isLoaded() {
return generated;
}
@Override
public double getWidth() {
return 1;
} }

View File

@ -1,38 +1,24 @@
package projectzombie.entity.particle; package projectzombie.entity.particle;
import java.util.Random;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.entity.EntityParticle;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.IModel;
import projectzombie.model.Model;
import projectzombie.util.math.random.RandomHelpers;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ParticleLava extends ParticleBreak public class ParticleLava extends ParticleBreak
{ {
public ParticleLava(Vec3d pos, Vec3d velocity) { public ParticleLava(Vec3d pos, Vec3d velocity) {
this(pos, velocity, 100); this(pos, velocity, 100);
this.still_ypos = -1;
} }
public ParticleLava(Vec3d pos, Vec3d velocity, int count) { public ParticleLava(Vec3d pos, Vec3d velocity, int count) {
super(pos, velocity, Models.TILE_LAVA, count, 0.1); super(pos, velocity, Models.TILE_LAVA, count, 0.1);
this.still_ypos = -1;
} }
@Override @Override
protected boolean isStill(Break particle) { protected boolean isStill(Break particle) {
return particle.pos.y <= -1; return particle.pos.y <= -1;
} }
@Override
protected void onAllStill() {
super.onAllStill();
dead = particles.length - 1;
}
} }

View File

@ -1,9 +1,8 @@
package projectzombie.entity.particle; package projectzombie.entity.particle;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.entity.EntityParticlePart;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.random.RandomHelpers;
@ -12,19 +11,15 @@ import projectzombie.world.layer.Layer;
public class ParticleSmoke extends EntityParticle public class ParticleSmoke extends EntityParticle
{ {
double opacity = 1;
double disappear_speed;
private Model model; private Model model;
public ParticleSmoke(Vec3d pos, Vec3d velocity) { public ParticleSmoke(Vec3d pos, Vec3d velocity) {
super(pos.add(new Vec3d( super(pos.add(new Vec3d(
RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5 + pos.x, 0, RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5, 0,
RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5 + pos.y)), RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5)),
velocity.add(new Vec3d(0, (rand.nextDouble() + 0.5) / 250, 0))); velocity.add(new Vec3d(0, (rand.nextDouble() + 0.5) / 100, 0)));
hasGravity = false; hasGravity = false;
disappear_speed = (rand.nextDouble() + 0.5) / 1000;
model = Models.PARTICLE_SMOKE_RANDOM.getModel(); model = Models.PARTICLE_SMOKE_RANDOM.getModel();
} }
@ -32,20 +27,17 @@ public class ParticleSmoke extends EntityParticle
public void tick(Chunk chunk, Layer layer) { public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer); super.tick(chunk, layer);
if(getPos().squareDistance(Main.player.getPos()) > 32 || opacity <= 0 || getPos().y > 16) { setVelocity(getVelocity().multiply(new Vec3d(0.995, 1, 0.995)));
kill();
}
opacity -= disappear_speed;
if(DISABLED) {
kill();
}
} }
@Override @Override
public Model getModel() { public int getParticleCount() {
return model; return 1;
}
@Override
public EntityParticlePart getParticleAt(int id) {
return new EntityParticlePart(model.getTextures()[0], getPos(), 1, 0b1000);
} }
} }

View File

@ -1,6 +1,6 @@
package projectzombie.entity.particle; package projectzombie.entity.particle;
import java.util.Random; import java.util.Arrays;
import gl_engine.MathHelpers; import gl_engine.MathHelpers;
import gl_engine.texture.TextureRef3D; import gl_engine.texture.TextureRef3D;
@ -8,89 +8,109 @@ import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.entity.Entity; import projectzombie.entity.Entity;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.entity.EntityParticlePart;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.IModel; import projectzombie.util.math.comparator.Comparators;
import projectzombie.model.Model;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
public class ParticleSmokeTrail extends ParticleBreak public class ParticleSmokeTrail extends EntityParticle
{ {
protected class SmokeTrail extends EntityParticlePart
{
Vec3d velocity;
int time;
SmokeTrail(TextureRef3D tex, Vec3d pos, Vec3d velocity) {
super(tex, pos.add(new Vec3d(0, 0.5, 0)), 0, 0b1000);
time = 500;
this.velocity = velocity;
}
boolean isDead() {
return time <= 0;
}
void update()
{
if(time <= 0) {
return;
}
time -= 1;
pos = pos.add(velocity);
size = time / 10000.0;
}
@Override
public double getFade() {
return 0.5;
}
}
private Entity parent; private Entity parent;
private double offset; private int dead;
private boolean generating_particles = true; private boolean generating_particles = true;
private SmokeTrail[] particles;
public ParticleSmokeTrail(Entity parent, double offset, int count) { public ParticleSmokeTrail(Entity parent) {
super(parent.getPos(), parent.getVelocity(), Models.PARTICLE_SMOKE_TRAIL, count); this(parent, 1000);
}
private ParticleSmokeTrail(Entity parent, int size) {
super(parent.getPos(), new Vec3d(0, 0, 0));
time = count; dead = size;
do_gravity = false; particles = new SmokeTrail[size];
this.offset = offset;
this.parent = parent; this.parent = parent;
} }
@Override
public Vec2d getParticleSize() {
return new Vec2d(0.04, 0.04);
}
public ParticleSmokeTrail(Entity parent, double offset) {
this(parent, offset, 2000);
}
@Override
protected Break createParticle(
IModel model, TextureRef3D ref, int tex_id, Vec3d pos, Vec3d velocity,
float[] verticies, double velocity_up_multiplier, double model_height, int i)
{
Break particle = new Break();
particle.moving = false;
particle.pos = pos.copy();
particle.velocity = new Vec3d(0, 0, 0);
particle.flags = ((int)verticies[tex_id * Model.SIZE + Model.SIZE - 1] & 0b0110) | 0b1000;
particle.ref = ref;
return particle;
}
@Override @Override
public void tick(Chunk chunk, Layer layer) { public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer); super.tick(chunk, layer);
for(int i=0;i<particles.length;i++) { setPos(parent.getPos());
particles[i].time -= 1;
}
int count = 0;
Vec3d wind = layer.layergen.getWind(layer, getPos().xz()); Vec3d wind = layer.layergen.getWind(layer, getPos().xz());
if(generating_particles) for(int i=0;i<particles.length;i++)
{ {
for(int i=0;i<particles.length&&count<10;i++) if(particles[i] == null) {
{ continue;
if(!particles[i].moving || particles[i].time <= 0) {
particles[i].pos = parent.getPos().add(new Vec3d(0, offset, 0));
particles[i].velocity = parent.getVelocity()
.multiply(0.5).add(
MathHelpers.moveTowards3(
MathHelpers.map(rand.nextDouble(), 0, 1, 0.004, 0.008), new Vec2d(
rand.nextDouble() * MathHelpers.TWO_PI,
rand.nextDouble() * MathHelpers.PI - MathHelpers.HALF_PI))).add(wind);
particles[i].moving = true;
particles[i].time = 200;
count += 1;
}
} }
if(particles[i].isDead()) {
particles[i] = null;
dead += 1;
continue;
}
particles[i].update();
} }
else { if(!generating_particles) {
dead -= 1; return;
if(dead >= particles.length) { }
dead = particles.length - 1;
kill(); for(int i=0;i<particles.length;i++) {
if(particles[i] == null)
{
int[] tex_id = {0};
TextureRef3D tex = Models.PARTICLE_SMOKE_TRAIL.getRandomChunk(tex_id);
particles[i] = new SmokeTrail(tex, parent.getPos().copy(),
parent.getVelocity().add(MathHelpers.moveTowards3(0.01, new Vec2d(
rand.nextDouble() * MathHelpers.TWO_PI,
rand.nextDouble() * MathHelpers.PI - MathHelpers.HALF_PI)))
.add(wind).multiply(0.5));
dead -= 1;
break;
} }
} }
} }
@ -100,7 +120,17 @@ public class ParticleSmokeTrail extends ParticleBreak
} }
public boolean noMoreParticles() { public boolean noMoreParticles() {
return dead == particles.length - 1; return dead == particles.length;
}
@Override
public int getParticleCount() {
return particles.length;
}
@Override
public EntityParticlePart getParticleAt(int id) {
return particles[id];
} }
} }

View File

@ -1,25 +1,40 @@
package projectzombie.entity.particle; package projectzombie.entity.particle;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.entity.Entity; import projectzombie.entity.particle.ParticleBreak.Break;
import projectzombie.entity.EntityContainer;
import projectzombie.entity.EntityParticle;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.IModel; import projectzombie.model.IModel;
import projectzombie.model.Model;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ParticleWater extends ParticleBreak public class ParticleWater extends ParticleBreak
{ {
public ParticleWater(Vec3d pos, Vec3d velocity) { public ParticleWater(Vec3d pos, Vec3d velocity) {
this(pos, velocity, 50); this(pos, velocity, 1);
} }
public ParticleWater(Vec3d pos, Vec3d velocity, int count) { public ParticleWater(Vec3d pos, Vec3d velocity, int count) {
super(pos, velocity, Models.TILE_WATER, count, 0.01); super(pos, velocity, Models.PARTICLE_WATER, count, 0.04);
still_ypos = -1;
} }
@Override
public boolean isDead() {
return still == particles.length;
}
@Override
protected double getHeight(IModel model) {
return 0.5;
}
@Override
protected double getParticleSpeed() {
return 0.05;
}
@Override
protected double getParticleFade() {
return 0.5;
}
} }

View File

@ -1,5 +1,7 @@
package projectzombie.entity.player; package projectzombie.entity.player;
import java.util.ArrayList;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.MathHelpers; import gl_engine.MathHelpers;
@ -12,44 +14,58 @@ import projectzombie.display.DisplayLighting;
import projectzombie.entity.Entity; import projectzombie.entity.Entity;
import projectzombie.entity.EntityAlive; import projectzombie.entity.EntityAlive;
import projectzombie.entity.EntityBullet; import projectzombie.entity.EntityBullet;
import projectzombie.entity.EntityInventory; import projectzombie.entity.EntityHasArmor;
import projectzombie.entity.EntityHasClothing;
import projectzombie.entity.EntityHasTasks;
import projectzombie.entity.EntityHasInventory;
import projectzombie.entity.EntityItem; import projectzombie.entity.EntityItem;
import projectzombie.entity.particle.ParticleBreak; import projectzombie.entity.particle.ParticleBreak;
import projectzombie.init.Items; import projectzombie.init.Items;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.init.Tasks;
import projectzombie.init.Tiles;
import projectzombie.inventory.Inventory; import projectzombie.inventory.Inventory;
import projectzombie.inventory.InventoryArmor;
import projectzombie.inventory.InventoryClothing;
import projectzombie.items.ItemTool;
import projectzombie.menu.MenuDeath; import projectzombie.menu.MenuDeath;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.model.ModelPlayer;
import projectzombie.settings.Cheats; import projectzombie.settings.Cheats;
import projectzombie.task.Task;
import projectzombie.task.TaskDeathScreen;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
import projectzombie.util.math.TileState;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
public class EntityPlayer extends Entity implements EntityAlive, EntityInventory public class EntityPlayer extends Entity implements
EntityAlive, EntityHasInventory, EntityHasArmor, EntityHasClothing, EntityHasTasks
{ {
public boolean MOVE_FORWARD = false; public boolean MOVE_FORWARD = false;
public boolean MOVE_BACKWARD = false; public boolean MOVE_BACKWARD = false;
public boolean MOVE_LEFT = false; public boolean MOVE_LEFT = false;
public boolean MOVE_RIGHT = false; public boolean MOVE_RIGHT = false;
public boolean GUN = false;
public boolean moving = false; public boolean moving = false;
public Model PLAYER_MOVING = Models.ENTITY_PLAYER_B_W_MOVING; public ModelPlayer MODEL = Models.ENTITY_PLAYER_W;
public Model PLAYER_STILL = Models.ENTITY_PLAYER_B_W_STILL;
private int bullet_frequency = 0;
private double health_max = 1000; private double health_max = 1000;
private double health = health_max; private double health = health_max;
private double temperature = 0.5; private double temperature = 0.5;
private double hydration = 1; private double hydration = 1;
private int break_progress = 0;
private Vec2i break_pos = new Vec2i(0, 0);
public boolean dead = false; public boolean dead = false;
public boolean in_animation = false; public boolean in_animation = false;
private ArrayList<Task> tasks;
private Inventory inventory; private Inventory inventory;
public int inventory_hand = 0; private InventoryArmor armor;
private InventoryClothing clothing;
public int defence_level = 0; public int inventory_hand = 0;
public int gun_level = 0;
public double angle; public double angle;
@ -57,21 +73,29 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
public EntityPlayer(BdfObject bdf) { public EntityPlayer(BdfObject bdf) {
super(bdf); super(bdf);
tasks = new ArrayList<Task>();
} }
@Override @Override
public void BdfClassLoad(BdfObject bdf) { public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf); super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList(); BdfNamedList nl = bdf.getNamedList();
bullet_frequency = nl.get("bullet_frequency").getInteger();
health = nl.get("health").getDouble(); health = nl.get("health").getDouble();
dead = nl.get("dead").getBoolean(); dead = nl.get("dead").getBoolean();
inventory = new Inventory(nl.get("inventory")); inventory = new Inventory(nl.get("inventory"));
defence_level = nl.get("defence_level").getInteger(); armor = new InventoryArmor(nl.get("armor"));
gun_level = nl.get("gun_level").getInteger(); clothing = new InventoryClothing(nl.get("clothing"));
angle = nl.get("angle").getDouble(); angle = nl.get("angle").getDouble();
temperature = nl.get("temperature").getDouble(); temperature = nl.get("temperature").getDouble();
hydration = nl.get("hydration").getDouble(); hydration = nl.get("hydration").getDouble();
tasks = new ArrayList<Task>();
Task[] tasks = Task.loadTasks(this, nl.get("tasks"));
for(int i=0;i<tasks.length;i++) {
this.tasks.add(tasks[i]);
}
} }
public int getAmmo() { public int getAmmo() {
@ -82,19 +106,19 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
public void BdfClassSave(BdfObject bdf) { public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf); super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList(); BdfNamedList nl = bdf.getNamedList();
nl.set("bullet_frequency", BdfObject.withInteger(bullet_frequency));
nl.set("health", BdfObject.withDouble(health)); nl.set("health", BdfObject.withDouble(health));
nl.set("dead", BdfObject.withBoolean(dead)); nl.set("dead", BdfObject.withBoolean(dead));
inventory.BdfClassSave(nl.get("inventory")); inventory.BdfClassSave(nl.get("inventory"));
nl.set("defence_level", BdfObject.withInteger(defence_level)); armor.BdfClassSave(nl.get("armor"));
nl.set("gun_level", BdfObject.withInteger(gun_level)); clothing.BdfClassSave(nl.get("clothing"));
nl.set("angle", BdfObject.withDouble(angle)); nl.set("angle", BdfObject.withDouble(angle));
nl.set("temperature", BdfObject.withDouble(temperature)); nl.set("temperature", BdfObject.withDouble(temperature));
nl.set("hydration", BdfObject.withDouble(hydration)); nl.set("hydration", BdfObject.withDouble(hydration));
nl.set("tasks", Task.saveTasks(tasks.toArray(new Task[0])));
} }
public EntityPlayer() { public EntityPlayer() {
super(new Vec3d(Math.pow(2, 30), 0, -Math.pow(2, 30)), new Vec3d(0, 0, 0)); super(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0));
this.angle = 45; this.angle = 45;
@ -103,14 +127,12 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
isSolid = true; isSolid = true;
emitsLight = true; emitsLight = true;
// Create the inventory tasks = new ArrayList<Task>();
inventory = new Inventory(10);
inventory.addItem(new ItemStack(Items.AMMO, 999, (short)0)); // Create the inventory
inventory.addItem(new ItemStack(Items.SPAWN_DUMMY, 999, (short)0)); inventory = new Inventory(42);
inventory.addItem(new ItemStack(Items.SPAWN_ZOMBIE, 999, (short)0)); armor = new InventoryArmor();
inventory.addItem(new ItemStack(Items.LANTERN, 999, (short)0)); clothing = new InventoryClothing();
inventory.addItem(new ItemStack(Items.FLARE, 999, (short)0));
} }
@Override @Override
@ -136,19 +158,13 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
{ {
chunk = layer.getChunk(getPos().xz()); chunk = layer.getChunk(getPos().xz());
temperature = 0.5;
health = health_max;
hydration = 1;
if(chunk != null && chunk.c_pos != null && (last_chunk == null || !chunk.c_pos.equal(last_chunk))) { if(chunk != null && chunk.c_pos != null && (last_chunk == null || !chunk.c_pos.equal(last_chunk))) {
last_chunk = chunk.c_pos; last_chunk = chunk.c_pos;
DisplayLighting.setDirty(); DisplayLighting.setDirty();
} }
if(dead) return;
// Handle player deaths // Handle player deaths
if(health <= 0) if(health <= 0 && !dead)
{ {
chunk.spawnEntity(new ParticleBreak(getPos(), getVelocity(), getModel())); chunk.spawnEntity(new ParticleBreak(getPos(), getVelocity(), getModel()));
@ -159,27 +175,18 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
else { else {
dead = true; dead = true;
health = 0; health = 0;
addTask(new TaskDeathScreen(this));
Main.mainloop.register(new IMainloopTask() { }
}
@Override
public void MainLoopUpdate() { for(int i=0;i<tasks.size();i++) {
Main.menu = new MenuDeath(); Task task = tasks.get(i);
} if(task.isDone()) {
tasks.remove(i);
@Override i -= 1;
public boolean MainLoopRepeat() { } else {
return false; task.update();
}
@Override
public boolean MainLoopDelay(long millis) {
return millis > 2500;
}
});
} }
return;
} }
// Is the player dead or in an animation // Is the player dead or in an animation
@ -193,14 +200,14 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature; chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature;
temperature += temp_diff / 1000; temperature += temp_diff / 1000;
hydration -= MathHelpers.smoothStep(Math.abs(temperature - 0.4) + 0.1) / 20000; hydration -= MathHelpers.smoothStep(Math.abs(temperature - 0.4) * 0.75 + 0.1) / 4000;
if(temperature < 0.3) { if(temperature < 0.3) {
health -= 0.3 - temperature; health -= 2 * (0.3 - temperature);
} }
if(temperature > 0.7) { if(temperature > 0.7) {
health -= temperature - 0.7; health -= 4 * (temperature - 0.7);
} }
if(hydration <= 0) { if(hydration <= 0) {
@ -229,11 +236,6 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
if(MOVE_BACKWARD) { if(MOVE_BACKWARD) {
this.moveTowards(this.angle + 180); this.moveTowards(this.angle + 180);
} }
// Use the gun
if(GUN) {
this.fireBullet(0);
}
} }
@Override @Override
@ -255,37 +257,76 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
} }
public void moveTowards(double angle) { public void moveTowards(double angle) {
this.moveTowards(angle, 0.02); this.moveTowards(angle, 0.08);
} }
public void fireBullet(double angle) public void leftClick() {
{
if(dead || in_animation) return; if(dead || in_animation) return;
bullet_frequency += 1; Layer layer = Main.world.getLayer();
bullet_frequency %= 10; ItemStack is = inventory.getItem(inventory_hand);
// Is there enough ammo and are the bullets at the right frequency if(is.isEmpty() || !is.item.onPlayerLeftClick(is, Main.world.getLayer(), chunk, this))
if(bullet_frequency == 0 && getAmmo() > 0)
{ {
// Remove some ammo ItemTool tool = (is.item instanceof ItemTool) ? (ItemTool) is.item : null;
inventory.removeItem(Items.AMMO, 1);
// Summon bullets at this angle relative to the player Vec2i pos = getPos().xz().add(MathHelpers.moveTowards2(0.5, Math.toRadians(angle))).toInt();
int d = (int)(1 + gun_level / 4.0);
Vec3d bullet_velocity = getVelocity().add(MathHelpers.moveTowards2(0.2, Math.toRadians(angle + this.angle)).xny()); for(int ti=0;ti<2;ti++)
Vec3d bullet_pos = getPos().add(new Vec3d(0, 0.4, 0)); {
Main.world.getLayer().spawnEntity(new EntityBullet(bullet_pos, bullet_velocity, this, 20*d*d, 60)); TileState ts;
if(ti == 0) {
ts = layer.getFrontTile(pos);
} else {
ts = layer.getBackTile(pos);
}
if(ts.tile.canTileBreak(tile_front, is, tool))
{
break_progress += 1;
if(!pos.equal(break_pos)) {
break_progress = 0;
break_pos = pos;
}
if(break_progress > ts.tile.hardness)
{
ItemStack[] stacks = ts.tile.getTileDrops(tile_front);
for(ItemStack stack : stacks) {
layer.spawnEntity(new EntityItem(
pos.toDouble().add(new Vec2d(0.5, 0.5)).xny(),
new Vec3d(0, 0, 0), stack));
}
if(ti == 0) {
layer.breakFrontTile(pos);
} else {
layer.breakBackTile(pos);
}
break_progress = 0;
if(tool != null) {
tool.toolOnUse(is);
}
}
break;
}
}
} }
} }
public void activateItem() { public void rightClick() {
if(dead || in_animation) return; if(dead || in_animation) return;
ItemStack is = inventory.getItem(inventory_hand); ItemStack is = inventory.getItem(inventory_hand);
if(!is.isEmpty()) { if(is.isEmpty() || !is.item.onPlayerRightClick(is, Main.world.getLayer(), chunk, this)) {
is.item.onPlayerAction(is, Main.world.getLayer(), chunk, this); activateTile();
} }
} }
@ -296,10 +337,20 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
} }
@Override @Override
public void removeHealth(double amount) { public void addDamage(double amount) {
amount = amount / (defence_level / 2.5 + 1); //amount = amount / (defence_level / 2.5 + 1);
health -= amount; health -= amount;
} }
@Override
public void addFireDamage(double amount) {
addDamage(amount);
}
@Override
public void addBlastDamage(double amount) {
addDamage(amount);
}
@Override @Override
public double getHealth() { public double getHealth() {
@ -350,7 +401,7 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
@Override @Override
public Model getModel() { public Model getModel() {
return moving ? PLAYER_MOVING : PLAYER_STILL; return moving ? MODEL.model_back_moving : MODEL.model_back_still;
} }
public double getTemperature() { public double getTemperature() {
@ -360,4 +411,31 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
public double getHydration() { public double getHydration() {
return hydration; return hydration;
} }
public void setInAnimation(boolean status)
{
in_animation = status;
hasGravity = !status;
isSolid = !status;
moving = status;
}
@Override
public void addTask(Task task) {
tasks.add(task);
}
public void rehydrate() {
hydration += 0.001;
}
@Override
public InventoryClothing getInventoryClothing() {
return clothing;
}
@Override
public InventoryArmor getInventoryArmor() {
return armor;
}
} }

View File

@ -19,7 +19,7 @@ import projectzombie.entity.player.EntityPlayer;
public class Entities public class Entities
{ {
public static final ArrayList<Class<? extends Entity>> entities = new ArrayList<>(); public static final ArrayList<Class<? extends Entity>> ENTITIES = new ArrayList<>();
private static void register(Class<? extends Entity> e) private static void register(Class<? extends Entity> e)
{ {
@ -30,7 +30,7 @@ public class Entities
System.exit(1); System.exit(1);
} }
entities.add(e); ENTITIES.add(e);
} }
public static void init() public static void init()

View File

@ -3,14 +3,18 @@ package projectzombie.init;
import java.util.ArrayList; import java.util.ArrayList;
import projectzombie.items.Item; import projectzombie.items.Item;
import projectzombie.items.ItemAcorn;
import projectzombie.items.ItemAmmo; import projectzombie.items.ItemAmmo;
import projectzombie.items.ItemDefenceUpgrade;
import projectzombie.items.ItemEmpty; import projectzombie.items.ItemEmpty;
import projectzombie.items.ItemFlare; import projectzombie.items.ItemFlare;
import projectzombie.items.ItemFlint;
import projectzombie.items.ItemGrapplingHook; import projectzombie.items.ItemGrapplingHook;
import projectzombie.items.ItemGunUpgrade;
import projectzombie.items.ItemHealthPotion; import projectzombie.items.ItemHealthPotion;
import projectzombie.items.ItemHempSeed;
import projectzombie.items.ItemInfestation;
import projectzombie.items.ItemLantern; import projectzombie.items.ItemLantern;
import projectzombie.items.ItemLog;
import projectzombie.items.ItemPlantFibre;
import projectzombie.items.ItemRock; import projectzombie.items.ItemRock;
import projectzombie.items.ItemTnt; import projectzombie.items.ItemTnt;
import projectzombie.items.spawner.ItemSpawnDummy; import projectzombie.items.spawner.ItemSpawnDummy;
@ -30,8 +34,6 @@ public class Items
register(EMPTY); register(EMPTY);
register(AMMO); register(AMMO);
register(DEFENCE_UPGRADE);
register(GUN_UPGRADE);
register(HEALTH_POTION); register(HEALTH_POTION);
register(TNT); register(TNT);
register(LANTERN); register(LANTERN);
@ -42,13 +44,18 @@ public class Items
register(SPAWN_DUMMY); register(SPAWN_DUMMY);
register(ROCK); register(ROCK);
register(FLINT);
register(LOG);
register(ACORN);
register(PLANT_FIBRE);
register(HEMP_SEED);
register(AMMO); register(AMMO);
register(INFESTATION);
} }
public static final Item AMMO = new ItemAmmo(); public static final Item AMMO = new ItemAmmo();
public static final Item DEFENCE_UPGRADE = new ItemDefenceUpgrade();
public static final Item GUN_UPGRADE = new ItemGunUpgrade();
public static final Item HEALTH_POTION = new ItemHealthPotion(); public static final Item HEALTH_POTION = new ItemHealthPotion();
public static final Item EMPTY = new ItemEmpty(); public static final Item EMPTY = new ItemEmpty();
public static final Item TNT = new ItemTnt(); public static final Item TNT = new ItemTnt();
@ -60,4 +67,11 @@ public class Items
public static final Item SPAWN_DUMMY = new ItemSpawnDummy(); public static final Item SPAWN_DUMMY = new ItemSpawnDummy();
public static final Item ROCK = new ItemRock(); public static final Item ROCK = new ItemRock();
public static final Item FLINT = new ItemFlint();
public static final Item LOG = new ItemLog();
public static final Item ACORN = new ItemAcorn();
public static final Item HEMP_SEED = new ItemHempSeed();
public static final Item PLANT_FIBRE = new ItemPlantFibre();
public static final Item INFESTATION = new ItemInfestation();
} }

View File

@ -5,6 +5,7 @@ import java.util.Random;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.world.World; import projectzombie.world.World;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
import projectzombie.world.layer.layergen.LayerGenBossArena;
public class Layers public class Layers
{ {

View File

@ -2,34 +2,65 @@ package projectzombie.init;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.model.ModelBox;
import projectzombie.model.ModelCactus;
import projectzombie.model.ModelCross;
import projectzombie.model.ModelEmpty; import projectzombie.model.ModelEmpty;
import projectzombie.model.ModelGrass; import projectzombie.model.ModelGrass;
import projectzombie.model.ModelGui; import projectzombie.model.ModelGui;
import projectzombie.model.ModelItem; import projectzombie.model.ModelItem;
import projectzombie.model.ModelPlayer;
import projectzombie.model.ModelRandom; import projectzombie.model.ModelRandom;
import projectzombie.model.ModelRock;
import projectzombie.model.ModelTallGrass;
import projectzombie.model.ModelTile; import projectzombie.model.ModelTile;
import projectzombie.model.ModelTree; import projectzombie.model.ModelTree;
import projectzombie.model.ModelTreeSnow;
import projectzombie.model.ModelVertical; import projectzombie.model.ModelVertical;
import projectzombie.model.player.ModelPlayerHead;
public class Models public class Models
{ {
public static final Model EMPTY = new ModelEmpty(); public static final Model EMPTY = new ModelEmpty();
public static final Model TILE_GRASS = new ModelGrass(); public static final Model TILE_TALL_GRASS = new ModelTallGrass();
public static final Model TILE_TREE = new ModelTree(); public static final Model TILE_GRASS = new ModelGrass();
public static final Model TILE_TREE = new ModelTree();
public static final Model TILE_TREE_SNOW = new ModelTreeSnow();
public static final Model TILE_CACTUS_1 = new ModelVertical(Resources.ATLAS.get("/tile/cactus1.png"), new Vec2d(1, 4)); public static final Model TILE_SAPLING_1 = new ModelCross(Resources.ATLAS.get("/tile/sapling1.png"));
public static final Model TILE_CACTUS_2 = new ModelVertical(Resources.ATLAS.get("/tile/cactus2.png"), new Vec2d(1, 4)); public static final Model TILE_SAPLING_2 = new ModelCross(Resources.ATLAS.get("/tile/sapling2.png"));
public static final Model TILE_CACTUS_3 = new ModelVertical(Resources.ATLAS.get("/tile/cactus3.png"), new Vec2d(1, 4)); public static final Model TILE_SAPLING_3 = new ModelCross(Resources.ATLAS.get("/tile/sapling3.png"));
public static final Model TILE_CACTUS_4 = new ModelVertical(Resources.ATLAS.get("/tile/cactus4.png"), new Vec2d(1, 4)); public static final Model TILE_SAPLING_4 = new ModelCross(Resources.ATLAS.get("/tile/sapling4.png"));
public static final Model TILE_CACTUS_1 = new ModelCactus(Resources.ATLAS.get("/tile/cactus1.png"), 0.5);
public static final Model TILE_CACTUS_2 = new ModelCactus(Resources.ATLAS.get("/tile/cactus2.png"), 1.0);
public static final Model TILE_CACTUS_3 = new ModelCactus(Resources.ATLAS.get("/tile/cactus3.png"), 1.5);
public static final Model TILE_CACTUS_4 = new ModelCactus(Resources.ATLAS.get("/tile/cactus4.png"), 2.0);
public static final Model[] TILE_HEMP = new Model[] {
new ModelBox(Resources.ATLAS.get("/tile/hemp1.png")),
new ModelBox(Resources.ATLAS.get("/tile/hemp2.png")),
new ModelBox(Resources.ATLAS.get("/tile/hemp3.png")),
new ModelBox(Resources.ATLAS.get("/tile/hemp4.png")),
new ModelBox(Resources.ATLAS.get("/tile/hemp5.png"), new Vec2d(1, 2)),
new ModelBox(Resources.ATLAS.get("/tile/hemp6.png"), new Vec2d(1, 2)),
new ModelBox(Resources.ATLAS.get("/tile/hemp7.png"), new Vec2d(1, 2)),
new ModelBox(Resources.ATLAS.get("/tile/hemp8.png"), new Vec2d(1, 2)),
};
public static final Model TILE_SNOW = new ModelTile(Resources.ATLAS.get("/tile/snow.png")); public static final Model TILE_SNOW = new ModelTile(Resources.ATLAS.get("/tile/snow.png"));
public static final Model TILE_ICE = new ModelTile(Resources.ATLAS.get("/tile/ice.png"));
public static final Model TILE_ICE_WALL = new ModelTile(Resources.ATLAS.get("/tile/ice_wall.png"));
public static final Model TILE_SANDSTONE = new ModelTile(Resources.ATLAS.get("/tile/sandstone.png"));
public static final Model TILE_SANDSTONE_WALL = new ModelTile(Resources.ATLAS.get("/tile/sandstone_wall.png"));
public static final Model TILE_GRASS_INFESTED = new ModelTile(Resources.ATLAS.get("/tile/grass_infested.png"));
public static final Model TILE_SAND = new ModelTile(Resources.ATLAS.get("/tile/sand.png")); public static final Model TILE_SAND = new ModelTile(Resources.ATLAS.get("/tile/sand.png"));
public static final Model TILE_STONE = new ModelTile(Resources.ATLAS.get("/tile/stone.png")); public static final Model TILE_STONE = new ModelTile(Resources.ATLAS.get("/tile/stone.png"));
public static final Model TILE_DIRT = new ModelTile(Resources.ATLAS.get("/tile/dirt.png")); public static final Model TILE_DIRT = new ModelTile(Resources.ATLAS.get("/tile/dirt.png"));
public static final Model TILE_ROCK = new ModelVertical(Resources.ATLAS.get("/tile/rock.png")); public static final Model TILE_ROCK = new ModelPlayerHead();//new ModelRock(Resources.ATLAS.get("/tile/rock.png"));
public static final Model TILE_SNOW_PILE = new ModelVertical(Resources.ATLAS.get("/tile/snow_pile.png")); public static final Model TILE_ROCK_ICE = new ModelRock(Resources.ATLAS.get("/tile/rock_ice.png"));
public static final Model TILE_ROCK_SANDSTONE = new ModelVertical(Resources.ATLAS.get("/tile/rock_sandstone.png")); public static final Model TILE_ROCK_SANDSTONE = new ModelRock(Resources.ATLAS.get("/tile/rock_sandstone.png"));
public static final Model TILE_LADDER = new ModelVertical(Resources.ATLAS.get("/tile/ladder.png")); public static final Model TILE_LADDER = new ModelVertical(Resources.ATLAS.get("/tile/ladder.png"));
public static final Model TILE_PORTAL = new ModelTile(Resources.ATLAS.get("/tile/tunnel_down.png")); public static final Model TILE_PORTAL = new ModelTile(Resources.ATLAS.get("/tile/tunnel_down.png"));
public static final Model TILE_WALL = new ModelTile(Resources.ATLAS.get("/tile/wall.png")); public static final Model TILE_WALL = new ModelTile(Resources.ATLAS.get("/tile/wall.png"));
@ -45,14 +76,15 @@ public class Models
public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 50); public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 50);
public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 50); public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 50);
public static final Model ENTITY_BOSS_WALKING_AND_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking_firing.png"), new Vec2d(4, 4), 4, 50); public static final Model ENTITY_BOSS_WALKING_AND_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking_firing.png"), new Vec2d(4, 4), 4, 50);
public static final Model ENTITY_TNT = new ModelVertical(Resources.ATLAS.get("/entity/tnt.png")); public static final Model ENTITY_TNT = new ModelVertical(Resources.ATLAS.get("/entity/tnt.png"), new Vec2d(0.5, 0.5));
public static final Model ENTITY_FLARE = new ModelVertical(Resources.ATLAS.get("/entity/flare.png")); public static final Model ENTITY_FLARE = new ModelVertical(Resources.ATLAS.get("/entity/flare.png"), new Vec2d(0.5, 0.5));
public static final Model ENTITY_DUMMY = new ModelVertical(Resources.ATLAS.get("/entity/dummy.png")); public static final Model ENTITY_DUMMY = new ModelVertical(Resources.ATLAS.get("/entity/dummy.png"));
public static final Model ENTITY_GRAPPLING_HOOK = new ModelVertical(Resources.ATLAS.get("/entity/grappling_hook.png")); public static final Model ENTITY_GRAPPLING_HOOK = new ModelVertical(Resources.ATLAS.get("/entity/grappling_hook.png"));
public static final Model PARTICLE_BLOOD = new ModelVertical(Resources.ATLAS.get("/particle/blood.png"), new Vec2d(1, 1)); public static final Model PARTICLE_BLOOD = new ModelVertical(Resources.ATLAS.get("/particle/blood.png"), new Vec2d(1, 1));
public static final Model PARTICLE_WATER = new ModelVertical(Resources.ATLAS.get("/particle/water.png"), new Vec2d(1, 1));
public static final Model PARTICLE_SMOKE_TRAIL = new ModelVertical(Resources.ATLAS.get("/particle/smoke_trail.png"), new Vec2d(1, 1)); public static final Model PARTICLE_SMOKE_TRAIL = new ModelVertical(Resources.ATLAS.get("/particle/smoke_trail.png"), new Vec2d(1, 1));
public static final Model PARTICLE_BULLET = new ModelVertical(Resources.ATLAS.get("/particle/bullet.png"), new Vec2d(0.1, 0.1));
public static final ModelRandom PARTICLE_SMOKE_RANDOM = new ModelRandom( public static final ModelRandom PARTICLE_SMOKE_RANDOM = new ModelRandom(
new ModelVertical(Resources.ATLAS.get("/particle/smoke_0.png")), new ModelVertical(Resources.ATLAS.get("/particle/smoke_0.png")),
@ -69,34 +101,53 @@ public class Models
public static final ModelGui UI_HEALTH_BG = new ModelGui(Resources.ATLAS.get("/gui/health_empty.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));
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_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 ModelGui UI_ACTIVE_SLOT = new ModelGui(Resources.ATLAS.get("/gui/hotbar_selected.png"), new Vec2d(1.5, 1.5));
public static final ModelGui UI_INVENTORY = new ModelGui(Resources.ATLAS.get("/gui/inventory.png"), new Vec2d(12, 12));
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 ModelGui UI_TEMPERATURE = new ModelGui(Resources.ATLAS.get("/gui/temperature.png"), new Vec2d(0.75, 0.75)); public static final ModelGui UI_TEMPERATURE = new ModelGui(Resources.ATLAS.get("/gui/temperature.png"), new Vec2d(0.75, 0.75));
public static final ModelGui UI_WATER = new ModelGui(Resources.ATLAS.get("/gui/water.png"), new Vec2d(0.75, 0.75)); public static final ModelGui UI_WATER = new ModelGui(Resources.ATLAS.get("/gui/water.png"), new Vec2d(0.75, 0.75));
public static final ModelGui UI_ITEM_HOVER = new ModelGui(Resources.ATLAS.get("/gui/pixel_black.png")).setOpacity(0.25);
public static final ModelItem UI_SLOT_ARMOR_HELMET = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_helmet.png"));
public static final ModelItem UI_SLOT_ARMOR_CHEST = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_chest.png"));
public static final ModelItem UI_SLOT_ARMOR_LEGS = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_legs.png"));
public static final ModelItem UI_SLOT_CLOTHING_SHIRT = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_shirt.png"));
public static final ModelItem UI_SLOT_CLOTHING_PANTS = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_pants.png"));
public static final ModelItem UI_SLOT_CLOTHING_BOOTS = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_boots.png"));
public static final ModelItem ITEM_EMPTY = ModelItem.createEmpty(); public static final ModelItem ITEM_EMPTY = ModelItem.createEmpty();
public static final ModelItem ITEM_GRAPPLING_HOOK = new ModelItem(Resources.ATLAS.get("/item/grappling_hook.png")); public static final ModelItem ITEM_GRAPPLING_HOOK = new ModelItem(Resources.ATLAS.get("/item/grappling_hook.png"));
public static final ModelItem ITEM_HEALTH_POTION = new ModelItem(Resources.ATLAS.get("/item/health_potion.png")); public static final ModelItem ITEM_HEALTH_POTION = new ModelItem(Resources.ATLAS.get("/item/health_potion.png"));
public static final ModelItem ITEM_AMMO_BOX = new ModelItem(Resources.ATLAS.get("/item/ammo_box.png")); public static final ModelItem ITEM_AMMO_BOX = new ModelItem(Resources.ATLAS.get("/item/ammo_box.png"));
public static final ModelItem ITEM_GUN_UPGRADE = new ModelItem(Resources.ATLAS.get("/item/gun_upgrade.png"));
public static final ModelItem ITEM_DEFENCE_UPGRADE = new ModelItem(Resources.ATLAS.get("/item/shield_upgrade.png"));
public static final ModelItem ITEM_ROCK = new ModelItem(Resources.ATLAS.get("/tile/rock.png"));
public static final ModelItem ITEM_TNT = new ModelItem(Resources.ATLAS.get("/entity/tnt.png")); public static final ModelItem ITEM_TNT = new ModelItem(Resources.ATLAS.get("/entity/tnt.png"));
public static final ModelItem ITEM_FLARE = new ModelItem(Resources.ATLAS.get("/entity/flare.png")); public static final ModelItem ITEM_FLARE = new ModelItem(Resources.ATLAS.get("/entity/flare.png"));
public static final ModelItem ITEM_LANTERN = new ModelItem(Resources.ATLAS.get("/tile/lantern.png"), 4, 5); public static final ModelItem ITEM_LANTERN = new ModelItem(Resources.ATLAS.get("/tile/lantern.png"), 4, 5);
public static final ModelItem ITEM_SPAWN_ZOMBIE = new ModelItem(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10); public static final ModelItem ITEM_SPAWN_ZOMBIE = new ModelItem(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10);
public static final ModelItem ITEM_SPAWN_DUMMY = new ModelItem(Resources.ATLAS.get("/entity/dummy.png")); public static final ModelItem ITEM_SPAWN_DUMMY = new ModelItem(Resources.ATLAS.get("/entity/dummy.png"));
// Player Back White Varient public static final ModelItem ITEM_ROCK = new ModelItem(Resources.ATLAS.get("/item/rock.png"));
public static final Model ENTITY_PLAYER_B_W_STILL = new ModelVertical(Resources.ATLAS.get("/player/player_white_back_still.png")); public static final ModelItem ITEM_SNOW_PILE = new ModelItem(Resources.ATLAS.get("/item/snow_pile.png"));
public static final Model ENTITY_PLAYER_B_W_MOVING = new ModelVertical(Resources.ATLAS.get("/player/player_white_back_moving.png"), 4, 10); public static final ModelItem ITEM_SANDSTONE = new ModelItem(Resources.ATLAS.get("/item/sandstone.png"));
public static final Model ENTITY_PLAYER_F_W_STILL = new ModelVertical(Resources.ATLAS.get("/player/player_white_front_still.png")); public static final ModelItem ITEM_FLINT = new ModelItem(Resources.ATLAS.get("/item/flint.png"));
public static final Model ENTITY_PLAYER_F_W_MOVING = new ModelVertical(Resources.ATLAS.get("/player/player_white_front_moving.png"), 4, 10);
public static final Model ENTITY_PLAYER_B_B_STILL = new ModelVertical(Resources.ATLAS.get("/player/player_black_back_still.png")); public static final ModelItem ITEM_PLANT_FIBRE = new ModelItem(Resources.ATLAS.get("/item/plant_fibre.png"));
public static final Model ENTITY_PLAYER_B_B_MOVING = new ModelVertical(Resources.ATLAS.get("/player/player_black_back_moving.png"), 4, 10); public static final ModelItem ITEM_HEMP_SEED = new ModelItem(Resources.ATLAS.get("/item/hemp_seed.png"));
public static final Model ENTITY_PLAYER_F_B_STILL = new ModelVertical(Resources.ATLAS.get("/player/player_black_front_still.png")); public static final ModelItem ITEM_ACORN = new ModelItem(Resources.ATLAS.get("/item/acorn.png"));
public static final Model ENTITY_PLAYER_F_B_MOVING = new ModelVertical(Resources.ATLAS.get("/player/player_blacl_front_moving.png"), 4, 10); public static final ModelItem ITEM_LOG = new ModelItem(Resources.ATLAS.get("/item/log.png"));
public static final ModelItem ITEM_LOG_SNOW = new ModelItem(Resources.ATLAS.get("/item/log_snow.png"));
// Player varients
public static final ModelPlayer ENTITY_PLAYER_W = new ModelPlayer(
Resources.ATLAS.get("/player/player_white_back_still.png"),
Resources.ATLAS.get("/player/player_white_back_moving.png"),
Resources.ATLAS.get("/player/player_white_front_still.png"),
Resources.ATLAS.get("/player/player_white_front_moving.png"));
public static final ModelPlayer ENTITY_PLAYER_B = new ModelPlayer(
Resources.ATLAS.get("/player/player_black_back_still.png"),
Resources.ATLAS.get("/player/player_black_back_moving.png"),
Resources.ATLAS.get("/player/player_black_front_still.png"),
Resources.ATLAS.get("/player/player_black_front_moving.png"));
public static final Model ENTITY_ZOMBIE_B = new ModelVertical(Resources.ATLAS.get("/entity/zombie_back_moving.png"), 4, 10); public static final Model ENTITY_ZOMBIE_B = new ModelVertical(Resources.ATLAS.get("/entity/zombie_back_moving.png"), 4, 10);
public static final Model ENTITY_ZOMBIE_F = new ModelVertical(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10); public static final Model ENTITY_ZOMBIE_F = new ModelVertical(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10);

View File

@ -1,6 +1,7 @@
package projectzombie.init; package projectzombie.init;
import gl_engine.texture.TextureAtlas3D; import gl_engine.texture.TextureAtlas3D;
import gl_engine.texture.TextureRef3D;
import projectzombie.resources.Resource; import projectzombie.resources.Resource;
public class Resources public class Resources
@ -10,6 +11,8 @@ public class Resources
ATLAS = TextureAtlas3D.loadAll("/resources/texture/list.txt"); ATLAS = TextureAtlas3D.loadAll("/resources/texture/list.txt");
ATLAS.generate(); ATLAS.generate();
TEX_EMPTY = ATLAS.get("");
GUN_OGG_0.load(); GUN_OGG_0.load();
GUN_OGG_1.load(); GUN_OGG_1.load();
GUN_OGG_2.load(); GUN_OGG_2.load();
@ -29,6 +32,7 @@ public class Resources
} }
public static TextureAtlas3D ATLAS; public static TextureAtlas3D ATLAS;
public static TextureRef3D TEX_EMPTY;
public static final Resource GUN_OGG_0 = new Resource("/sound/gun0.ogg"); public static final Resource GUN_OGG_0 = new Resource("/sound/gun0.ogg");
public static final Resource GUN_OGG_1 = new Resource("/sound/gun1.ogg"); public static final Resource GUN_OGG_1 = new Resource("/sound/gun1.ogg");

View File

@ -0,0 +1,34 @@
package projectzombie.init;
import java.util.ArrayList;
import bdf.types.BdfObject;
import projectzombie.entity.Entity;
import projectzombie.task.Task;
import projectzombie.task.TaskDeathScreen;
import projectzombie.task.TaskLadderDown;
import projectzombie.task.TaskLadderUp;
public class Tasks
{
public static final ArrayList<Class<? extends Task>> TASKS = new ArrayList<>();
private static void register(Class<? extends Task> t)
{
try {
t.getConstructor(Entity.class, BdfObject.class);
} catch (NoSuchMethodException | SecurityException err) {
err.printStackTrace();
System.exit(1);
}
TASKS.add(t);
}
public static void init()
{
register(TaskLadderDown.class);
register(TaskLadderUp.class);
register(TaskDeathScreen.class);
}
}

View File

@ -8,6 +8,10 @@ import projectzombie.tiles.TileCactus;
import projectzombie.tiles.TileChest; import projectzombie.tiles.TileChest;
import projectzombie.tiles.TileDirt; import projectzombie.tiles.TileDirt;
import projectzombie.tiles.TileGrass; import projectzombie.tiles.TileGrass;
import projectzombie.tiles.TileGrassInfested;
import projectzombie.tiles.TileHemp;
import projectzombie.tiles.TileIce;
import projectzombie.tiles.TileIceWall;
import projectzombie.tiles.TileLadder; import projectzombie.tiles.TileLadder;
import projectzombie.tiles.TileLadderUp; import projectzombie.tiles.TileLadderUp;
import projectzombie.tiles.TileLantern; import projectzombie.tiles.TileLantern;
@ -16,12 +20,15 @@ import projectzombie.tiles.TileLavaFlow;
import projectzombie.tiles.TilePortalDown; import projectzombie.tiles.TilePortalDown;
import projectzombie.tiles.TileRock; import projectzombie.tiles.TileRock;
import projectzombie.tiles.TileSand; import projectzombie.tiles.TileSand;
import projectzombie.tiles.TileSandstone;
import projectzombie.tiles.TileSandstoneWall;
import projectzombie.tiles.TileSapling;
import projectzombie.tiles.TileSnow; import projectzombie.tiles.TileSnow;
import projectzombie.tiles.TileStone; import projectzombie.tiles.TileStone;
import projectzombie.tiles.TileTallGrass;
import projectzombie.tiles.TileTree; import projectzombie.tiles.TileTree;
import projectzombie.tiles.TileVoid; import projectzombie.tiles.TileVoid;
import projectzombie.tiles.TileWall; import projectzombie.tiles.TileWall;
import projectzombie.tiles.TileWallUnbreakable;
import projectzombie.tiles.TileWater; import projectzombie.tiles.TileWater;
public class Tiles public class Tiles
@ -59,8 +66,14 @@ public class Tiles
register(LADDER_UP); register(LADDER_UP);
register(CHEST); register(CHEST);
register(LANTERN); register(LANTERN);
register(WALL_UNBREAKABLE);
register(BOSS_PORTAL); register(BOSS_PORTAL);
register(ICE);
register(ICE_WALL);
register(SANDSTONE);
register(SANDSTONE_WALL);
register(GRASS_INFESTED);
register(TALL_GRASS);
register(SAPLING);
} }
public static final Tile GRASS = new TileGrass(); public static final Tile GRASS = new TileGrass();
@ -81,6 +94,13 @@ public class Tiles
public static final Tile LADDER_UP = new TileLadderUp(); public static final Tile LADDER_UP = new TileLadderUp();
public static final Tile CHEST = new TileChest(); public static final Tile CHEST = new TileChest();
public static final Tile LANTERN = new TileLantern(); public static final Tile LANTERN = new TileLantern();
public static final Tile WALL_UNBREAKABLE = new TileWallUnbreakable();
public static final Tile BOSS_PORTAL = new TileBossPortal(); public static final Tile BOSS_PORTAL = new TileBossPortal();
public static final Tile ICE = new TileIce();
public static final Tile ICE_WALL = new TileIceWall();
public static final Tile SANDSTONE = new TileSandstone();
public static final Tile SANDSTONE_WALL = new TileSandstoneWall();
public static final Tile GRASS_INFESTED = new TileGrassInfested();
public static final Tile TALL_GRASS = new TileTallGrass();
public static final Tile SAPLING = new TileSapling();
public static final Tile HEMP = new TileHemp();
} }

View File

@ -5,9 +5,12 @@ import org.lwjgl.glfw.GLFWCursorPosCallbackI;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.util.gl.GlHelpers;
public class CursorPosCallback implements GLFWCursorPosCallbackI public class CursorPosCallback implements GLFWCursorPosCallbackI
{ {
public static double mx, my;
@Override @Override
public void invoke(long window, double x, double y) public void invoke(long window, double x, double y)
{ {
@ -16,13 +19,16 @@ public class CursorPosCallback implements GLFWCursorPosCallbackI
Main.window.setMouseVisibility(!Main.menu.keepMouse); Main.window.setMouseVisibility(!Main.menu.keepMouse);
InputMode.Controller = false; InputMode.Controller = false;
int wx = Main.window.getWidth();
int wy = Main.window.getHeight();
mx = (x / Main.window.getWidth() * 20 - 10) * GlHelpers.getAspectRatio();
my = -y / Main.window.getHeight() * 20 + 10;
if(!Main.menu.keepMouse) { if(!Main.menu.keepMouse) {
return; return;
} }
int wx = Main.window.getWidth();
int wy = Main.window.getHeight();
x = (x / wx - 0.5); x = (x / wx - 0.5);
y = (y / wy - 0.5); y = (y / wy - 0.5);

View File

@ -18,5 +18,7 @@ class GameInput
static boolean moveRight = false; static boolean moveRight = false;
static boolean moveUp = false; static boolean moveUp = false;
static boolean moveDown = false; static boolean moveDown = false;
static boolean fireGun = false;
static boolean buttonL = false;
static boolean buttonR = false;
} }

View File

@ -1,17 +1,6 @@
package projectzombie.input; package projectzombie.input;
import static projectzombie.input.GameInput.activateItem_last; import static projectzombie.input.GameInput.*;
import static projectzombie.input.GameInput.activateTile_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.fireGun;
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.ByteBuffer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
@ -179,7 +168,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
} }
// Gun trigger // Gun trigger
if(right_trigger > 0.3 && !fireGun) { if(right_trigger > 0.3) {
input.fire(true); input.fire(true);
InputMode.Controller = true; InputMode.Controller = true;
Main.window.setMouseVisibility(false); Main.window.setMouseVisibility(false);
@ -189,11 +178,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
if(left_trigger > 0.3) { if(left_trigger > 0.3) {
InputMode.Controller = true; InputMode.Controller = true;
Main.window.setMouseVisibility(false); Main.window.setMouseVisibility(false);
if(!activateItem_last) input.itemAction(true);
{
activateItem_last = true;
input.itemAction(true);
}
} }
else { else {
@ -226,20 +211,6 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
hotbar_r = false; hotbar_r = false;
} }
// Activate tile
if(button_x) {
InputMode.Controller = true;
Main.window.setMouseVisibility(false);
if(!activateTile_last) {
input.activateTile(true);
activateTile_last = true;
}
}
else if(activateTile_last) {
activateTile_last = false;
}
// Activate button (A Button) // Activate button (A Button)
if(button_a) { if(button_a) {
InputMode.Controller = true; InputMode.Controller = true;
@ -252,6 +223,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
else if(activate_last) { else if(activate_last) {
activate_last = false; activate_last = false;
input.activate(false);
} }
// Drop item // Drop item

View File

@ -19,13 +19,7 @@ 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_S;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W; import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE; import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
import static projectzombie.input.GameInput.backButton_last; import static projectzombie.input.GameInput.*;
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 org.lwjgl.glfw.GLFWKeyCallbackI; import org.lwjgl.glfw.GLFWKeyCallbackI;
@ -33,14 +27,16 @@ import gl_engine.vec.Vec2d;
import mainloop.task.IMainloopTask; import mainloop.task.IMainloopTask;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.input.types.Input; import projectzombie.input.types.Input;
import projectzombie.menu.MenuInventory;
public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
{ {
private boolean itemDrop_last = false; private boolean itemDrop_last = false;
private boolean esc_last = false; private boolean esc_last = false;
private boolean action_last = false;
private boolean fullscreen_last = false; private boolean fullscreen_last = false;
private boolean fireGun_last = false; private boolean buttonL_last = false;
private boolean buttonR_last = false;
private boolean inventory_last = false;
@Override @Override
public void invoke(long window, int key, int scancode, int action, int mods) public void invoke(long window, int key, int scancode, int action, int mods)
@ -97,18 +93,6 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
input.hotbarGoto(true, 9); input.hotbarGoto(true, 9);
} }
if(key == GLFW_KEY_E) {
if(pressed) {
if(!action_last) {
action_last = true;
input.activateTile(true);
}
}
else if(action_last) {
action_last = false;
}
}
if(key == GLFW_KEY_Q) { if(key == GLFW_KEY_Q) {
if(pressed) { if(pressed) {
if(!itemDrop_last) { if(!itemDrop_last) {
@ -121,6 +105,18 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
} }
} }
if(key == GLFW_KEY_E) {
if(pressed) {
if(!inventory_last) {
inventory_last = true;
}
}
else if(inventory_last) {
inventory_last = false;
input.openInventory();
}
}
if(key == GLFW_KEY_ESCAPE) { if(key == GLFW_KEY_ESCAPE) {
if(pressed) { if(pressed) {
if(!esc_last) { if(!esc_last) {
@ -194,15 +190,25 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
input.move(true, angle); input.move(true, angle);
} }
if(fireGun) { if(buttonL) {
fireGun_last = true; buttonL_last = true;
input.fire(true); input.fire(true);
} }
else if(fireGun_last) { else if(buttonL_last) {
fireGun_last = false; buttonL_last = false;
input.fire(false); input.fire(false);
} }
if(buttonR) {
buttonR_last = true;
input.itemAction(true);
}
else if(buttonR_last) {
buttonR_last = false;
input.itemAction(false);
}
} }
} }

View File

@ -14,12 +14,11 @@ public class MouseButtonCallback implements GLFWMouseButtonCallbackI
InputMode.Controller = false; InputMode.Controller = false;
if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
GameInput.fireGun = action == 1; GameInput.buttonL = action == 1;
} }
if(button == GLFW.GLFW_MOUSE_BUTTON_RIGHT && action == 1) { if(button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) {
GameInput.activateItem_last = true; GameInput.buttonR = action == 1;
Main.menu.input.itemAction(true);
} }
} }

View File

@ -6,7 +6,6 @@ public interface Input
{ {
public void move(boolean state, double angle); public void move(boolean state, double angle);
public void fire(boolean state); public void fire(boolean state);
public void activateTile(boolean state);
public void camera(boolean state, double amount); public void camera(boolean state, double amount);
public void itemAction(boolean state); public void itemAction(boolean state);
public void itemDrop(boolean state); public void itemDrop(boolean state);
@ -16,4 +15,5 @@ public interface Input
public void mousePos(Vec2d pos); public void mousePos(Vec2d pos);
public void back(boolean state); public void back(boolean state);
public void activate(boolean state); public void activate(boolean state);
public void openInventory();
} }

View File

@ -1,17 +1,20 @@
package projectzombie.input.types; package projectzombie.input.types;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.util.gl.GlHelpers;
public class InputGUI implements Input public class InputGUI implements Input
{ {
private GUI gui; private GUI gui;
private boolean gunStateLast = false; private boolean gunStateLast = false;
private boolean actionStateLast = false;
public InputGUI(GUI gui) { public InputGUI(GUI gui) {
this.gui = gui; this.gui = gui;
} }
@Override @Override
public void move(boolean state, double angle) { public void move(boolean state, double angle) {
this.gui.onMove(state, angle); this.gui.onMove(state, angle);
@ -29,14 +32,20 @@ public class InputGUI implements Input
} }
} }
@Override
public void activateTile(boolean state) {}
@Override @Override
public void camera(boolean state, double amount) {} public void camera(boolean state, double amount) {}
@Override @Override
public void itemAction(boolean state) {} public void itemAction(boolean state) {
if(state) {
actionStateLast = true;
}
else if(actionStateLast) {
actionStateLast = false;
gui.onRightClick();
}
}
@Override @Override
public void itemDrop(boolean state) {} public void itemDrop(boolean state) {}
@ -51,8 +60,12 @@ public class InputGUI implements Input
public void hotbarShift(boolean state, int amount) {} public void hotbarShift(boolean state, int amount) {}
@Override @Override
public void mousePos(Vec2d pos) { public void mousePos(Vec2d pos)
this.gui.updateMousePos(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 @Override
@ -64,5 +77,9 @@ public class InputGUI implements Input
public void activate(boolean state) { public void activate(boolean state) {
gui.onActivate(); gui.onActivate();
} }
@Override
public void openInventory() {
}
} }

View File

@ -4,6 +4,7 @@ import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.menu.MenuGamePause; import projectzombie.menu.MenuGamePause;
import projectzombie.menu.MenuInventory;
import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.chunk.ChunkEventHandler;
public class InputGame implements Input public class InputGame implements Input
@ -30,12 +31,7 @@ public class InputGame implements Input
@Override @Override
public void fire(boolean state) { public void fire(boolean state) {
Main.player.fireBullet(0); Main.player.leftClick();
}
@Override
public void activateTile(boolean state) {
Main.player.activateTile();
} }
@Override @Override
@ -45,7 +41,7 @@ public class InputGame implements Input
@Override @Override
public void itemAction(boolean state) { public void itemAction(boolean state) {
Main.player.activateItem(); Main.player.rightClick();
} }
@Override @Override
@ -67,7 +63,7 @@ public class InputGame implements Input
@Override @Override
public void hotbarShift(boolean state, int amount) { public void hotbarShift(boolean state, int amount) {
Main.player.inventory_hand += amount; Main.player.inventory_hand += amount;
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, Main.player.getInventory().getSlotCount()); Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 10);
} }
@Override @Override
@ -81,5 +77,10 @@ public class InputGame implements Input
@Override @Override
public void activate(boolean state) { public void activate(boolean state) {
} }
@Override
public void openInventory() {
Main.menu = new MenuInventory(Main.menu);
}
} }

View File

@ -1,11 +1,17 @@
package projectzombie.inventory; package projectzombie.inventory;
import projectzombie.items.Item;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
public interface IInventory public interface IInventory
{ {
public ItemStack getItem(int slot);
public int getSlotCount(); public int getSlotCount();
public ItemStack getItem(int slot);
public void addItem(ItemStack stack);
public void setItem(ItemStack stack, int slot); public void setItem(ItemStack stack, int slot);
public ItemStack removeItem(int slot); public ItemStack removeItem(int slot);
public void removeItem(ItemStack stack);
public void removeItem(Item item, int count);
} }

View File

@ -0,0 +1,14 @@
package projectzombie.inventory;
import projectzombie.util.math.ItemStack;
public interface IInventoryArmor
{
public ItemStack getHelmet();
public ItemStack getChest();
public ItemStack getLeggings();
public void setHelmet(ItemStack stack);
public void setChest(ItemStack stack);
public void setLeggings(ItemStack stack);
}

View File

@ -0,0 +1,14 @@
package projectzombie.inventory;
import projectzombie.util.math.ItemStack;
public interface IInventoryClothing
{
public ItemStack getShirt();
public ItemStack getPants();
public ItemStack getBoots();
public void setShirt(ItemStack stack);
public void setPants(ItemStack stack);
public void setBoots(ItemStack stack);
}

View File

@ -21,15 +21,8 @@ public class Inventory implements IInventory, IBdfClassManager
} }
@Override @Override
public ItemStack getItem(int slot) public ItemStack getItem(int slot) {
{ return items[slot];
if(items[slot].isEmpty()) {
return ItemStack.getEmpty();
}
else {
return items[slot];
}
} }
@Override @Override

View File

@ -0,0 +1,69 @@
package projectzombie.inventory;
import bdf.classes.IBdfClassManager;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.util.math.ItemStack;
public class InventoryArmor implements IBdfClassManager, IInventoryArmor
{
private ItemStack helmet, chest, leggings;
public InventoryArmor() {
helmet = ItemStack.getEmpty();
chest = ItemStack.getEmpty();
leggings = ItemStack.getEmpty();
}
public InventoryArmor(BdfObject bdf) {
BdfClassLoad(bdf);
}
@Override
public ItemStack getHelmet() {
return helmet;
}
@Override
public ItemStack getChest() {
return chest;
}
@Override
public ItemStack getLeggings() {
return leggings;
}
@Override
public void setHelmet(ItemStack stack) {
helmet = stack;
}
@Override
public void setChest(ItemStack stack) {
chest = stack;
}
@Override
public void setLeggings(ItemStack stack) {
leggings = stack;
}
@Override
public void BdfClassLoad(BdfObject bdf) {
BdfNamedList nl = bdf.getNamedList();
helmet = new ItemStack(nl.get("helmet"));
chest = new ItemStack(nl.get("chest"));
leggings = new ItemStack(nl.get("leggings"));
}
@Override
public void BdfClassSave(BdfObject bdf) {
BdfNamedList nl = new BdfNamedList();
helmet.BdfClassSave(nl.get("helmet"));
chest.BdfClassSave(nl.get("chest"));
leggings.BdfClassSave(nl.get("leggings"));
bdf.setNamedList(nl);
}
}

View File

@ -0,0 +1,68 @@
package projectzombie.inventory;
import bdf.classes.IBdfClassManager;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.util.math.ItemStack;
public class InventoryClothing implements IBdfClassManager, IInventoryClothing
{
private ItemStack shirt, pants, boots;
public InventoryClothing() {
shirt = ItemStack.getEmpty();
pants = ItemStack.getEmpty();
boots = ItemStack.getEmpty();
}
public InventoryClothing(BdfObject bdf) {
BdfClassLoad(bdf);
}
@Override
public ItemStack getShirt() {
return shirt;
}
@Override
public ItemStack getPants() {
return pants;
}
@Override
public ItemStack getBoots() {
return boots;
}
@Override
public void setShirt(ItemStack stack) {
shirt = stack;
}
@Override
public void setPants(ItemStack stack) {
pants = stack;
}
@Override
public void setBoots(ItemStack stack) {
boots = stack;
}
@Override
public void BdfClassLoad(BdfObject bdf) {
BdfNamedList nl = bdf.getNamedList();
shirt = new ItemStack(nl.get("shirt"));
pants = new ItemStack(nl.get("pants"));
boots = new ItemStack(nl.get("boots"));
}
@Override
public void BdfClassSave(BdfObject bdf) {
BdfNamedList nl = new BdfNamedList();
shirt.BdfClassSave(nl.get("shirt"));
pants.BdfClassSave(nl.get("pants"));
boots.BdfClassSave(nl.get("boots"));
bdf.setNamedList(nl);
}
}

View File

@ -1,8 +1,9 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.entity.Entity; import projectzombie.entity.Entity;
import projectzombie.entity.EntityInventory; import projectzombie.entity.EntityHasInventory;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.inventory.IInventory;
import projectzombie.inventory.Inventory; import projectzombie.inventory.Inventory;
import projectzombie.model.ModelItem; import projectzombie.model.ModelItem;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
@ -14,8 +15,12 @@ public abstract class Item
public int id; public int id;
public int max = 99; public int max = 99;
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { public boolean onPlayerLeftClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
stack.count -= 1; return false;
}
public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
return false;
} }
public String getName(short meta) { public String getName(short meta) {
@ -34,10 +39,10 @@ public abstract class Item
if(stack.isEmpty()) return; if(stack.isEmpty()) return;
// Does the entity have an inventory // Does the entity have an inventory
if(entity instanceof EntityInventory) if(entity instanceof EntityHasInventory)
{ {
// Get the entities inventory // Get the entities inventory
Inventory entity_i = ((EntityInventory) entity).getInventory(); IInventory entity_i = ((EntityHasInventory) entity).getInventory();
// Add the item to the entities inventory // Add the item to the entities inventory
entity_i.addItem(stack); entity_i.addItem(stack);

View File

@ -0,0 +1,41 @@
package projectzombie.items;
import gl_engine.vec.Vec2i;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Models;
import projectzombie.init.Tiles;
import projectzombie.model.ModelItem;
import projectzombie.tiles.Tile;
import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ItemAcorn extends Item
{
@Override
public ModelItem getModel(short meta) {
return Models.ITEM_ACORN;
}
@Override
public String getName(short meta) {
return "Acorn";
}
@Override
public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
Vec2i tpos = player.getPos().xz().toInt();
Tile bt = chunk.getBackTile(tpos).tile;
if((bt == Tiles.GRASS || bt == Tiles.SNOW) && chunk.getFrontTile(tpos).tile == Tiles.VOID) {
chunk.setFrontTile(Tiles.SAPLING.getDefaultState(), tpos);
stack.count -= 1;
return true;
}
return false;
}
}

View File

@ -1,7 +1,11 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.ModelItem; import projectzombie.model.ModelItem;
import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ItemAmmo extends Item public class ItemAmmo extends Item
{ {

View File

@ -0,0 +1,10 @@
package projectzombie.items;
import projectzombie.util.math.ItemStack;
public interface ItemArmor
{
public boolean isHelmet(ItemStack stack);
public boolean isChestplate(ItemStack stack);
public boolean isLeggings(ItemStack stack);
}

View File

@ -0,0 +1,10 @@
package projectzombie.items;
import projectzombie.util.math.ItemStack;
public interface ItemClothing
{
public boolean isShirt(ItemStack stack);
public boolean isPants(ItemStack stack);
public boolean isBoots(ItemStack stack);
}

View File

@ -1,36 +0,0 @@
package projectzombie.items;
import projectzombie.Main;
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 ItemDefenceUpgrade extends Item
{
public ItemDefenceUpgrade() {
this.max = 1;
}
@Override
public ModelItem getModel(short meta) {
return Models.ITEM_DEFENCE_UPGRADE;
}
@Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player)
{
if(Main.player.defence_level < stack.meta) {
super.onPlayerAction(stack, layer, chunk, player);
Main.player.defence_level = stack.meta;
}
}
@Override
public String getName(short meta) {
return "Defence Upgrade level "+meta;
}
}

View File

@ -14,10 +14,6 @@ public class ItemEmpty extends Item
public ItemEmpty() { public ItemEmpty() {
} }
@Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
}
@Override @Override
public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity) { public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity) {
} }

View File

@ -17,9 +17,10 @@ public class ItemFlare extends Item
} }
@Override @Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
super.onPlayerAction(stack, layer, chunk, player);
layer.spawnEntity(new EntityFlare(player.getPos(), player.getVelocity(), player.angle)); layer.spawnEntity(new EntityFlare(player.getPos(), player.getVelocity(), player.angle));
stack.count -= 1;
return true;
} }
@Override @Override

View File

@ -0,0 +1,20 @@
package projectzombie.items;
import projectzombie.init.Models;
import projectzombie.model.ModelItem;
import projectzombie.util.math.ItemStack;
public class ItemFlint extends Item
{
@Override
public ModelItem getModel(short meta) {
return Models.ITEM_FLINT;
}
@Override
public String getName(short meta) {
return "Flint";
}
}

View File

@ -1,8 +1,5 @@
package projectzombie.items; package projectzombie.items;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d;
import projectzombie.entity.EntityGrapplingHook; import projectzombie.entity.EntityGrapplingHook;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Models; import projectzombie.init.Models;
@ -25,10 +22,10 @@ public class ItemGrapplingHook extends Item
} }
@Override @Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
super.onPlayerAction(stack, layer, chunk, player);
layer.spawnEntity(new EntityGrapplingHook(player.getPos(), stack.meta, player)); layer.spawnEntity(new EntityGrapplingHook(player.getPos(), stack.meta, player));
stack.count -= 1;
return true;
} }
} }

View File

@ -1,36 +0,0 @@
package projectzombie.items;
import projectzombie.Main;
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 ItemGunUpgrade extends Item
{
public ItemGunUpgrade() {
this.max = 1;
}
@Override
public ModelItem getModel(short meta) {
return Models.ITEM_GUN_UPGRADE;
}
@Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player)
{
if(Main.player.gun_level < stack.meta) {
super.onPlayerAction(stack, layer, chunk, player);
Main.player.gun_level = stack.meta;
}
}
@Override
public String getName(short meta) {
return "Gun Upgrade level "+meta;
}
}

View File

@ -21,10 +21,9 @@ public class ItemHealthPotion extends Item
} }
@Override @Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
super.onPlayerAction(stack, layer, chunk, player);
// Heal the player
player.addHealth(stack.meta); player.addHealth(stack.meta);
stack.count -= 1;
return true;
} }
} }

View File

@ -0,0 +1,39 @@
package projectzombie.items;
import gl_engine.vec.Vec2i;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Models;
import projectzombie.init.Tiles;
import projectzombie.model.ModelItem;
import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ItemHempSeed extends Item
{
@Override
public ModelItem getModel(short meta) {
return Models.ITEM_HEMP_SEED;
}
@Override
public String getName(short meta) {
return "Hemp Seed";
}
@Override
public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
Vec2i tpos = player.getPos().xz().toInt();
if(chunk.getBackTile(tpos).tile == Tiles.GRASS && chunk.getFrontTile(tpos).tile == Tiles.VOID) {
chunk.setFrontTile(Tiles.HEMP.getDefaultState(), tpos);
stack.count -= 1;
return true;
}
return false;
}
}

View File

@ -0,0 +1,26 @@
package projectzombie.items;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Models;
import projectzombie.init.Tiles;
import projectzombie.model.ModelItem;
import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ItemInfestation extends Item
{
@Override
public ModelItem getModel(short meta) {
return Models.ITEM_ROCK;
}
@Override
public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
chunk.setBackTile(Tiles.GRASS_INFESTED.getDefaultState(), player.getPos().xz().toInt());
stack.count -= 1;
return true;
}
}

View File

@ -24,13 +24,16 @@ public class ItemLantern extends Item
} }
@Override @Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player)
{ {
Vec2i tpos = new Vec2i(MathHelpers.floor(player.getPos().x), MathHelpers.floor(player.getPos().z)); Vec2i tpos = new Vec2i(MathHelpers.floor(player.getPos().x), MathHelpers.floor(player.getPos().z));
if(layer.getFrontTile(tpos).tile == Tiles.VOID) { if(layer.getFrontTile(tpos).tile == Tiles.VOID) {
layer.setFrontTile(Tiles.LANTERN.getDefaultState(), tpos); layer.setFrontTile(Tiles.LANTERN.getDefaultState(), tpos);
super.onPlayerAction(stack, layer, chunk, player); stack.count -= 1;
return true;
} }
return false;
} }
@Override @Override

View File

@ -0,0 +1,24 @@
package projectzombie.items;
import projectzombie.init.Models;
import projectzombie.model.ModelItem;
public class ItemLog extends Item
{
@Override
public ModelItem getModel(short meta)
{
switch(meta)
{
case 1: return Models.ITEM_LOG_SNOW;
default: return Models.ITEM_LOG;
}
}
@Override
public String getName(short meta) {
return "Log";
}
}

View File

@ -0,0 +1,17 @@
package projectzombie.items;
import projectzombie.init.Models;
import projectzombie.model.ModelItem;
public class ItemPlantFibre extends Item
{
@Override
public ModelItem getModel(short meta) {
return Models.ITEM_PLANT_FIBRE;
}
@Override
public String getName(short meta) {
return "Plant Fibre";
}
}

View File

@ -7,12 +7,17 @@ import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
public class ItemRock extends Item public class ItemRock extends Item implements ItemTool
{ {
@Override @Override
public ModelItem getModel(short meta) { public ModelItem getModel(short meta)
return Models.ITEM_ROCK; {
switch(meta) {
case 1: return Models.ITEM_SNOW_PILE;
case 2: return Models.ITEM_SANDSTONE;
default: return Models.ITEM_ROCK;
}
} }
@Override @Override
@ -21,8 +26,40 @@ public class ItemRock extends Item
} }
@Override @Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { public void toolOnUse(ItemStack stack) {
//super.onAction(stack, layer, chunk, entity);
if(stack.meta == 1) {
return;
}
stack.count -= 1;
} }
@Override
public int toolPowerAxe(ItemStack stack)
{
if(stack.meta == 1) {
return 0;
}
return 1;
}
@Override
public int toolPowerPickaxe(ItemStack stack) {
return 0;
}
@Override
public int toolPowerShovel(ItemStack stack) {
return 0;
}
@Override
public int toolSpeed(ItemStack stack) {
return 1;
}
} }

View File

@ -1,6 +1,5 @@
package projectzombie.items; package projectzombie.items;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
@ -10,10 +9,10 @@ import projectzombie.world.layer.Layer;
public abstract class ItemSpawn extends Item public abstract class ItemSpawn extends Item
{ {
@Override @Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
super.onPlayerAction(stack, layer, chunk, player);
this.spawnEntity(layer, chunk, player.getPos(), player.getVelocity()); this.spawnEntity(layer, chunk, player.getPos(), player.getVelocity());
stack.count -= 1;
return true;
} }
public void spawnEntity(Layer layer, Chunk chunk, Vec3d pos, Vec3d velocity) { public void spawnEntity(Layer layer, Chunk chunk, Vec3d pos, Vec3d velocity) {

View File

@ -21,10 +21,10 @@ public class ItemTnt extends Item
} }
@Override @Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
super.onPlayerAction(stack, layer, chunk, player);
layer.spawnEntity(new EntityTnt(player.getPos(), player.getVelocity(), player.angle, stack.meta, 5000)); layer.spawnEntity(new EntityTnt(player.getPos(), player.getVelocity(), player.angle, stack.meta, 5000));
stack.count -= 1;
return true;
} }
} }

View File

@ -0,0 +1,12 @@
package projectzombie.items;
import projectzombie.util.math.ItemStack;
public interface ItemTool
{
public int toolPowerAxe(ItemStack stack);
public int toolPowerPickaxe(ItemStack stack);
public int toolPowerShovel(ItemStack stack);
public int toolSpeed(ItemStack stack);
public void toolOnUse(ItemStack stack);
}

View File

@ -1,6 +1,5 @@
package projectzombie.items.spawner; package projectzombie.items.spawner;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.entity.EntityDummy; import projectzombie.entity.EntityDummy;
import projectzombie.init.Models; import projectzombie.init.Models;

View File

@ -1,6 +1,5 @@
package projectzombie.items.spawner; package projectzombie.items.spawner;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.entity.EntityZombie; import projectzombie.entity.EntityZombie;
import projectzombie.init.Models; import projectzombie.init.Models;

View File

@ -2,7 +2,7 @@ package projectzombie.menu;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.input.types.InputGUI; import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.ButtonGroup; import projectzombie.menu.gui.GUIButtonGroup;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonBasic;
import projectzombie.menu.gui.components.ButtonGroupPause; import projectzombie.menu.gui.components.ButtonGroupPause;
@ -22,7 +22,7 @@ public class MenuDeath extends Menu
gui.add(new OverlayBackground()); gui.add(new OverlayBackground());
ButtonGroup group = new ButtonGroupPause(); GUIButtonGroup group = new ButtonGroupPause();
group.add(new ButtonBasic("Quit", button -> { group.add(new ButtonBasic("Quit", button -> {
Main.menu = new MenuMain(); Main.menu = new MenuMain();

View File

@ -6,7 +6,7 @@ import java.util.zip.DeflaterOutputStream;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.input.types.InputGUI; import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.ButtonGroup; import projectzombie.menu.gui.GUIButtonGroup;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonBasic;
import projectzombie.menu.gui.components.ButtonGroupPause; import projectzombie.menu.gui.components.ButtonGroupPause;
@ -29,7 +29,7 @@ public class MenuGamePause extends Menu
gui.add(new OverlayBackground()); gui.add(new OverlayBackground());
gui.add(new LabelPause("Game Paused")); gui.add(new LabelPause("Game Paused"));
ButtonGroup group = new ButtonGroupPause(); GUIButtonGroup group = new ButtonGroupPause();
group.add(new ButtonBasic("Save And Exit", button -> { group.add(new ButtonBasic("Save And Exit", button -> {
saveAndQuit(); saveAndQuit();

View File

@ -0,0 +1,244 @@
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;
import projectzombie.inventory.Inventory;
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.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.components.GUIBackToMenu;
import projectzombie.model.Model;
import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.ItemStack;
public class MenuInventory extends Menu
{
private Menu parent;
private GUI gui;
private GUIItemSlot[] item_slots;
private GUIItemSlot[] armor_slots;
public MenuInventory(Menu parent)
{
this.parent = parent;
doGameloop = parent.doGameloop;
doGameRender = parent.doGameRender;
playerEmitsLight = parent.playerEmitsLight;
showIngameGUI = parent.showIngameGUI;
keepMouse = false;
gui = new GUIBackToMenu(parent);
input = new InputGUI(gui);
Inventory inventory = Main.player.getInventory();
GUIItemHolder itemHolder = new GUIItemHolder();
item_slots = new GUIItemSlot[42];
armor_slots = new GUIItemSlot[6];
{
double offset = Models.UI_ITEM_SLOTS.getWidth() / 10;
double inv_w = Models.UI_INVENTORY.getWidth();
double inv_h = Models.UI_INVENTORY.getHeight();
for(int i=0;i<10;i++)
{
GUIItemSlot slot = new GUIItemSlot(itemHolder, 1, false, new GUIItemSlotGetterStorage(inventory, i));
slot.setPos(new Vec2d((i - 5) * offset + 0.325, 0.65 / 2 - 9.5));
gui.add(slot);
item_slots[i] = slot;
}
for(int i=10;i<42;i++)
{
int row = (i - 10) / 4;
int col = (i - 10) % 4;
GUIItemSlot slot = new GUIItemSlot(itemHolder, 1.5, true, new GUIItemSlotGetterStorage(inventory, i));
slot.setPos(new Vec2d(col * offset - inv_w + 0.325, -row * offset + inv_h / 2 - 1.175));
gui.add(slot);
item_slots[i] = slot;
}
InventoryArmor armor = Main.player.getInventoryArmor();
InventoryClothing clothing = Main.player.getInventoryClothing();
double[] positions = new double[] {
156, 76,
156, 42,
156, 8,
196, 76,
196, 42,
196, 8,
};
ItemStack[] armor_item_slots = new ItemStack[] {
armor.getHelmet(), armor.getChest(), armor.getLeggings(),
clothing.getShirt(), clothing.getPants(), clothing.getBoots(),
};
for(int i=0;i<6;i++)
{
int[] id = {i};
GUIItemSlot slot = new GUIItemSlot(itemHolder, 1.5, true, new GUIItemSlotGetter() {
@Override
public void setItemStack(ItemStack stack) {
armor_item_slots[id[0]] = stack;
}
@Override
public boolean isAllowed(ItemStack stack)
{
if(id[0] < 3)
{
if(stack.item instanceof ItemArmor)
{
ItemArmor ia = (ItemArmor) stack.item;
switch(id[0])
{
case 0: return ia.isHelmet(stack);
case 1: return ia.isChestplate(stack);
case 2: return ia.isLeggings(stack);
}
}
}
else
{
if(stack.item instanceof ItemClothing)
{
ItemClothing ic = (ItemClothing) stack.item;
switch(id[0])
{
case 3: return ic.isShirt(stack);
case 4: return ic.isPants(stack);
case 5: return ic.isBoots(stack);
}
}
}
return false;
}
@Override
public ItemStack getItemStack() {
return armor_item_slots[id[0]];
}
});
switch(i)
{
case 0:
slot.setModelEmpty(Models.UI_SLOT_ARMOR_HELMET);
break;
case 1:
slot.setModelEmpty(Models.UI_SLOT_ARMOR_CHEST);
break;
case 2:
slot.setModelEmpty(Models.UI_SLOT_ARMOR_LEGS);
break;
case 3:
slot.setModelEmpty(Models.UI_SLOT_CLOTHING_SHIRT);
break;
case 4:
slot.setModelEmpty(Models.UI_SLOT_CLOTHING_PANTS);
break;
case 5:
slot.setModelEmpty(Models.UI_SLOT_CLOTHING_BOOTS);
break;
}
slot.setPos(new Vec2d(
inv_w * (positions[i*2] / 256) - inv_w + 0.325,
inv_h * (positions[i*2+1] / 256) - inv_h / 2 + 0.325));
//slot.setItemStack(new ItemStack(Items.ACORN, 3, (short)0));
armor_slots[i] = slot;
gui.add(slot);
}
}
gui.add(itemHolder);
}
@Override
public void render()
{
parent.render();
double width = Models.UI_INVENTORY.getWidth();
double height = Models.UI_INVENTORY.getHeight();
Matrix4 matrix = Matrix4.translate(-width, -height / 2, 0);
// Render the inventory gui
Models.UI_INVENTORY.setModel(matrix);
Models.UI_INVENTORY.render();
{
// Render the player in the gui
Model player_model = Main.player.MODEL.model_gui;
double px = width * (160 / 256.0);
double py = height * (128 / 256.0);
Matrix4 player_matrix = Matrix4.multiply(matrix, Matrix4.translate(px, py, 0));
player_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(3, 3, 3)), player_matrix);
player_model.setModel(player_matrix);
player_model.render();
}
/*// Get the angles between the player character and the mouse
double ax = Math.toDegrees(MathHelpers.atan2(-CursorPosCallback.mx - px / 20, 3.2));
double ay = Math.toDegrees(MathHelpers.atan2(-CursorPosCallback.my - py / 20, 3.2));
player_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(6, 6, 6)), player_matrix);
player_matrix = Matrix4.multiply(Matrix4.projection(1, 90, 1, 50), player_matrix);
player_matrix = Matrix4.multiply(Matrix4.translate(0, 0, -2), player_matrix);
player_matrix = Matrix4.multiply(Matrix4.rotate(ax, 0, 1, 0), player_matrix);
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();
}
@Override
public void update() {
super.update();
gui.update(new Vec2d(CursorPosCallback.mx, CursorPosCallback.my));
}
}

View File

@ -3,7 +3,7 @@ package projectzombie.menu;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.input.types.InputGUI; import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.ButtonGroup; import projectzombie.menu.gui.GUIButtonGroup;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonBasic;
import projectzombie.menu.gui.components.LabelMain; import projectzombie.menu.gui.components.LabelMain;
@ -24,7 +24,7 @@ public class MenuMain extends Menu
gui.add(new LabelMain()); gui.add(new LabelMain());
ButtonGroup group = new ButtonGroup(); GUIButtonGroup group = new GUIButtonGroup();
group.add(new ButtonBasic("Play", button -> { group.add(new ButtonBasic("Play", button -> {
Main.respawn(); Main.respawn();

View File

@ -5,11 +5,11 @@ import projectzombie.Main;
import projectzombie.display.DisplayRenderUI; import projectzombie.display.DisplayRenderUI;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.input.types.InputGUI; import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.Button; import projectzombie.menu.gui.GUIButton;
import projectzombie.menu.gui.ButtonGroup; import projectzombie.menu.gui.GUIButtonGroup;
import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.GUISelectableDirection; import projectzombie.menu.gui.GUISelectableDirection;
import projectzombie.menu.gui.Label; import projectzombie.menu.gui.GUILabel;
import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonBasic;
import projectzombie.menu.gui.components.ButtonSetting; import projectzombie.menu.gui.components.ButtonSetting;
import projectzombie.menu.gui.components.GUIBackToMenu; import projectzombie.menu.gui.components.GUIBackToMenu;
@ -22,10 +22,6 @@ public class MenuSettings extends Menu
private GUI gui; private GUI gui;
private Menu menuOld; private Menu menuOld;
private String qualitySettingToString(boolean status) {
return status ? "On" : "Off";
}
public MenuSettings(Menu menuOld) { public MenuSettings(Menu menuOld) {
this.menuOld = menuOld; this.menuOld = menuOld;
@ -36,7 +32,7 @@ public class MenuSettings extends Menu
playerEmitsLight = menuOld.playerEmitsLight; playerEmitsLight = menuOld.playerEmitsLight;
keepMouse = false; keepMouse = false;
ButtonGroup group = new ButtonGroup(); GUIButtonGroup group = new GUIButtonGroup();
group.setPos(new Vec2d(-1, 4)); group.setPos(new Vec2d(-1, 4));
group.add(new ButtonSetting("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off"), button -> { group.add(new ButtonSetting("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off"), button -> {
@ -45,27 +41,20 @@ public class MenuSettings extends Menu
Settings.update(); Settings.update();
})); }));
group.add(new ButtonSetting("Pos Indicator: " + (DisplayRenderUI.showPos ? "On" : "Off"), group.add(new ButtonSetting("Debug mode: " + (DisplayRenderUI.debug ? "On" : "Off"),
button -> button ->
{ {
DisplayRenderUI.showPos = !DisplayRenderUI.showPos; DisplayRenderUI.debug = !DisplayRenderUI.debug;
button.setText("Pos Indicator: " + (DisplayRenderUI.showPos ? "On" : "Off")); button.setText("Debug mode: " + (DisplayRenderUI.debug ? "On" : "Off"));
Settings.update(); Settings.update();
})); }));
group.add(new ButtonSetting("Render Distance: "+Chunk.RENDER_DISTANCE, button -> { group.add(new ButtonSetting("Render distance: "+Chunk.RENDER_DISTANCE, button -> {
Chunk.RENDER_DISTANCE += 1; Chunk.RENDER_DISTANCE += 1;
if(Chunk.RENDER_DISTANCE > 8) { if(Chunk.RENDER_DISTANCE > 8) {
Chunk.RENDER_DISTANCE = 2; Chunk.RENDER_DISTANCE = 2;
} }
button.setText("Render Distance: "+Chunk.RENDER_DISTANCE); button.setText("Render distance: "+Chunk.RENDER_DISTANCE);
Settings.update();
}));
group.add(new ButtonSetting("Particles: " + qualitySettingToString(!EntityParticle.DISABLED), button ->
{
EntityParticle.DISABLED = !EntityParticle.DISABLED;
button.setText("Particles: " + qualitySettingToString(!EntityParticle.DISABLED));
Settings.update(); Settings.update();
})); }));
@ -91,13 +80,13 @@ public class MenuSettings extends Menu
gui.add(group); gui.add(group);
Label labelSettings = new Label(); GUILabel labelSettings = new GUILabel();
labelSettings.setText("Settings"); labelSettings.setText("Settings");
labelSettings.setSize(new Vec2d(1, 1)); labelSettings.setSize(new Vec2d(1, 1));
labelSettings.setPos(new Vec2d(0, 6.8)); labelSettings.setPos(new Vec2d(0, 6.8));
gui.add(labelSettings); gui.add(labelSettings);
Button buttonBack = new ButtonBasic("Back", new Vec2d(0, -8), button -> { GUIButton buttonBack = new ButtonBasic("Back", new Vec2d(0, -8), button -> {
Main.menu = menuOld; Main.menu = menuOld;
}); });

View File

@ -103,10 +103,23 @@ public class GUI implements GUIContainer
} }
} }
@Override
public void onRightClick(Vec2d pos) {
for(GUIComponent c : components) {
if(c.checkMouseHover(mousePos)) {
c.onRightClick(mousePos);
}
}
}
public void onMouseClick() { public void onMouseClick() {
this.onMouseClick(mousePos); this.onMouseClick(mousePos);
} }
public void onRightClick() {
this.onRightClick(mousePos);
}
@Override @Override
public void onBack() { public void onBack() {
for(GUIComponent c : components) { for(GUIComponent c : components) {
@ -120,5 +133,12 @@ public class GUI implements GUIContainer
c.onActivate(); c.onActivate();
} }
} }
@Override
public void update(Vec2d mousePos) {
for(GUIComponent c : components) {
c.update(mousePos);
}
}
} }

View File

@ -1,5 +1,5 @@
package projectzombie.menu.gui; package projectzombie.menu.gui;
public enum Alignment { public enum GUIAlignment {
LEFT, CENTRE, RIGHT LEFT, CENTRE, RIGHT
} }

View File

@ -10,11 +10,11 @@ import projectzombie.model.ModelGui;
import projectzombie.text.Text; import projectzombie.text.Text;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
public class Button implements GUIComponent, GUISelectable public class GUIButton implements GUIComponent, GUISelectable
{ {
private Vec2d pos = new Vec2d(0, 0); private Vec2d pos = new Vec2d(0, 0);
private String text = ""; private String text = "";
private Alignment alignment = Alignment.CENTRE; private GUIAlignment alignment = GUIAlignment.CENTRE;
private Matrix4 matrix, matrix_text; private Matrix4 matrix, matrix_text;
private boolean selected = false; private boolean selected = false;
@ -46,10 +46,10 @@ public class Button implements GUIComponent, GUISelectable
matrix_text = Matrix4.multiply(Matrix4.scale(new Vec3d(0.5, 0.5, 0.5)), matrix_text); matrix_text = Matrix4.multiply(Matrix4.scale(new Vec3d(0.5, 0.5, 0.5)), matrix_text);
} }
public Button() public GUIButton()
{ {
this.text = ""; this.text = "";
this.alignment = Alignment.CENTRE; this.alignment = GUIAlignment.CENTRE;
this.dirty = true; this.dirty = true;
} }
@ -63,7 +63,7 @@ public class Button implements GUIComponent, GUISelectable
this.dirty = true; this.dirty = true;
} }
public void setAlign(Alignment alignment) { public void setAlign(GUIAlignment alignment) {
this.alignment = alignment; this.alignment = alignment;
this.dirty = true; this.dirty = true;
} }
@ -100,13 +100,10 @@ public class Button implements GUIComponent, GUISelectable
double offset = getOffset(); double offset = getOffset();
double mx = (pos.x / Main.window.getWidth() * 20 - 10) * GlHelpers.getAspectRatio();
double my = -pos.y / Main.window.getHeight() * 20 + 10;
ModelGui model = Models.UI_BUTTON; ModelGui model = Models.UI_BUTTON;
return (mx > this.pos.x - offset && mx < this.pos.x + model.getWidth() - offset && return (pos.x > this.pos.x - offset && pos.x < this.pos.x + model.getWidth() - offset &&
my > this.pos.y && my < this.pos.y + model.getHeight()); pos.y > this.pos.y && pos.y < this.pos.y + model.getHeight());
} }
@Override @Override
@ -167,4 +164,13 @@ public class Button implements GUIComponent, GUISelectable
this.onMouseClick(new Vec2d(0, 0)); this.onMouseClick(new Vec2d(0, 0));
} }
} }
@Override
public void update(Vec2d mousePos) {
}
@Override
public void onRightClick(Vec2d pos) {
}
} }

View File

@ -4,16 +4,16 @@ import java.util.ArrayList;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
public class ButtonGroup implements GUIContainer public class GUIButtonGroup implements GUIContainer
{ {
private ArrayList<Button> buttons = new ArrayList<Button>(); private ArrayList<GUIButton> buttons = new ArrayList<GUIButton>();
private Vec2d pos = new Vec2d(0, 0); private Vec2d pos = new Vec2d(0, 0);
public void setPos(Vec2d pos) { public void setPos(Vec2d pos) {
this.pos = pos; this.pos = pos;
for(int i=0;i<buttons.size();i++) { for(int i=0;i<buttons.size();i++) {
Button b = buttons.get(i); GUIButton b = buttons.get(i);
b.setPos(new Vec2d(pos.x, pos.y + 0.5 * -i * 3.6)); b.setPos(new Vec2d(pos.x, pos.y + 0.5 * -i * 3.6));
if(i > 0) { if(i > 0) {
@ -28,8 +28,8 @@ public class ButtonGroup implements GUIContainer
@Override @Override
public void add(GUIComponent c) { public void add(GUIComponent c) {
if(c instanceof Button) { if(c instanceof GUIButton) {
Button b = (Button) c; GUIButton b = (GUIButton) c;
buttons.add(b); buttons.add(b);
setPos(pos); setPos(pos);
} }
@ -37,14 +37,14 @@ public class ButtonGroup implements GUIContainer
@Override @Override
public void render(Vec2d mousePos) { public void render(Vec2d mousePos) {
for(Button b : buttons) { for(GUIButton b : buttons) {
b.render(mousePos); b.render(mousePos);
} }
} }
@Override @Override
public boolean checkMouseHover(Vec2d pos) { public boolean checkMouseHover(Vec2d pos) {
for(Button b : buttons) { for(GUIButton b : buttons) {
if(b.checkMouseHover(pos)) { if(b.checkMouseHover(pos)) {
return true; return true;
} }
@ -54,7 +54,7 @@ public class ButtonGroup implements GUIContainer
@Override @Override
public void onMouseClick(Vec2d pos) { public void onMouseClick(Vec2d pos) {
for(Button b : buttons) { for(GUIButton b : buttons) {
if(b.checkMouseHover(pos)) { if(b.checkMouseHover(pos)) {
b.onMouseClick(pos); b.onMouseClick(pos);
} }
@ -63,12 +63,12 @@ public class ButtonGroup implements GUIContainer
@Override @Override
public void onBack() { public void onBack() {
for(Button b : buttons) { for(GUIButton b : buttons) {
b.onBack(); b.onBack();
} }
} }
public Button get(int n) { public GUIButton get(int n) {
return buttons.get(n); return buttons.get(n);
} }
@ -78,9 +78,23 @@ public class ButtonGroup implements GUIContainer
@Override @Override
public void onActivate() { public void onActivate() {
for(Button b : buttons) { for(GUIButton b : buttons) {
b.onActivate(); b.onActivate();
} }
} }
@Override
public void update(Vec2d mousePos) {
for(GUIButton b : buttons) {
b.update(mousePos);
}
}
@Override
public void onRightClick(Vec2d pos) {
for(GUIButton b : buttons) {
b.onRightClick(pos);
}
}
} }

View File

@ -5,9 +5,11 @@ import gl_engine.vec.Vec2d;
public interface GUIComponent public interface GUIComponent
{ {
public void render(Vec2d mousePos); public void render(Vec2d mousePos);
public void update(Vec2d mousePos);
public boolean checkMouseHover(Vec2d pos); public boolean checkMouseHover(Vec2d pos);
public void onRightClick(Vec2d pos);
public void onMouseClick(Vec2d pos); public void onMouseClick(Vec2d pos);
public void onActivate(); public void onActivate();
public void onBack(); public void onBack();

View File

@ -0,0 +1,191 @@
package projectzombie.menu.gui;
import gl_engine.MathHelpers;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d;
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;
public class GUIItemHolder implements GUIComponent
{
private GUIItemSlot hover = null;
private ItemStack holding = ItemStack.getEmpty();
public void setHover(GUIItemSlot slot) {
this.hover = slot;
}
@Override
public void render(Vec2d mousePos)
{
if(!holding.isEmpty())
{
Model model = holding.item.getModel(holding.meta).getGuiModel();
Matrix4 matrix = Matrix4.translate(mousePos.x - 0.425, mousePos.y - 0.425, 0);
model.setModel(matrix);
model.render();
if(holding.count > 1)
{
Matrix4 text_matrix = Matrix4.multiply(matrix, Matrix4.translate(-0.75 / 4, -0.75 / 4, 0));
text_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(0.4, 0.4, 0.4)), text_matrix);
Text.render("" + holding.count, text_matrix);
}
}
hover = null;
}
@Override
public void update(Vec2d mousePos) {
// TODO Auto-generated method stub
}
@Override
public boolean checkMouseHover(Vec2d pos) {
return true;
}
@Override
public void onRightClick(Vec2d pos)
{
// Drop part of the holding item if the hover item doesn't exist
if(hover == null)
{
if(!holding.isEmpty())
{
Layer layer = Main.world.getLayer();
layer.spawnEntity(new EntityItem(
Main.player.getPos(), Main.player.getVelocity(),
new ItemStack(holding.item, 1, holding.meta),
Math.toRadians(Main.player.angle)));
holding.count -= 1;
}
return;
}
ItemStack hover = this.hover.getItemStack();
// Split the hovered slot in half if the holding slot is empty
if(holding.isEmpty())
{
holding.item = hover.item;
holding.meta = hover.meta;
holding.count = (int)Math.ceil(hover.count / 2.0);
hover.count = (int)Math.floor(hover.count / 2.0);
this.hover.setItemStack(hover);
}
// Put 1 item into the slot if the hovered slot is empty or equal to the holding slot
else if((hover.isEmpty() && this.hover.isItemAllowed(holding)) || hover.stackEquals(holding))
{
hover.count += 1;
holding.count -= 1;
hover.item = holding.item;
hover.meta = holding.meta;
this.hover.setItemStack(hover);
}
this.hover = null;
}
@Override
public void onMouseClick(Vec2d pos)
{
// Drop the holding item if the hover item doesn't exist
if(hover == null)
{
if(!holding.isEmpty())
{
Layer layer = Main.world.getLayer();
layer.spawnEntity(new EntityItem(
Main.player.getPos(), Main.player.getVelocity(),
holding.copy(), Math.toRadians(Main.player.angle)));
holding.count = 0;
}
return;
}
ItemStack hover = this.hover.getItemStack();
// Are these the same item
if(holding.stackEquals(hover) && !holding.isEmpty() && !hover.isEmpty())
{
if(this.hover.isItemAllowed(holding))
{
// Merge the hover stack into the holding stack
if(holding.count + hover.count > holding.item.max) {
int overflow = holding.count + hover.count - holding.item.max;
hover.count = holding.item.max;
holding.count = overflow;
}
else {
hover.count += holding.count;
holding.count = 0;
}
this.hover.setItemStack(hover);
}
}
else if(holding.isEmpty() || this.hover.isItemAllowed(holding))
{
// Swap the stacks
ItemStack stack = holding.copy();
holding.count = hover.count;
holding.item = hover.item;
holding.meta = hover.meta;
hover.count = stack.count;
hover.item = stack.item;
hover.meta = stack.meta;
this.hover.setItemStack(hover);
}
this.hover = null;
}
@Override
public void onActivate() {
// TODO Auto-generated method stub
}
@Override
public void onBack()
{
if(!holding.isEmpty())
{
Layer layer = Main.world.getLayer();
layer.spawnEntity(new EntityItem(
Main.player.getPos(), Main.player.getVelocity(),
holding.copy(), Math.toRadians(Main.player.angle)));
holding.count = 0;
}
}
}

View File

@ -0,0 +1,126 @@
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
{
private GUIItemHolder itemHolder;
private Vec2d pos = new Vec2d(0, 0);
private GUIItemSlotGetter getter;
private double hitboxSize;
private boolean renderItem;
private Model model_empty = Models.ITEM_EMPTY.getGuiModel();
public GUIItemSlot(GUIItemHolder itemHolder, double hitboxSize, boolean renderItem, GUIItemSlotGetter getter) {
this.renderItem = renderItem;
this.hitboxSize = hitboxSize;
this.itemHolder = itemHolder;
this.getter = getter;
}
public void setPos(Vec2d pos) {
this.pos = pos;
}
public boolean isItemAllowed(ItemStack stack) {
return getter.isAllowed(stack);
}
public void setItemStack(ItemStack stack) {
getter.setItemStack(stack);
}
public ItemStack getItemStack() {
return getter.getItemStack();
}
public void setModelEmpty(ModelItem model) {
model_empty = model.getGuiModel();
}
@Override
public void render(Vec2d mousePos)
{
ItemStack stack = getter.getItemStack();
Matrix4 matrix = Matrix4.translate(pos.x, pos.y, 0);
Model model = stack.item.getModel(stack.meta).getGuiModel();
if(stack.isEmpty()) {
model = model_empty;
}
if(renderItem)
{
model.setModel(matrix);
model.render();
}
if(checkMouseHover(mousePos))
{
double offset = (0.85 - hitboxSize) / 2;
Matrix4 hover_matrix = Matrix4.multiply(matrix, Matrix4.translate(offset, offset, 0));
hover_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(hitboxSize, hitboxSize, hitboxSize)), hover_matrix);
Models.UI_ITEM_HOVER.setModel(hover_matrix);
Models.UI_ITEM_HOVER.render();
itemHolder.setHover(this);
}
if(renderItem && !stack.isEmpty())
{
if(stack.count > 1)
{
Matrix4 text_matrix = Matrix4.multiply(matrix, Matrix4.translate(-0.75 / 4, -0.75 / 4, 0));
text_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(0.4, 0.4, 0.4)), text_matrix);
Text.render("" + stack.count, text_matrix);
}
}
}
@Override
public boolean checkMouseHover(Vec2d pos)
{
double offset = (0.85 - hitboxSize) / 2;
double px = this.pos.x + offset;
double py = this.pos.y + offset;
return pos.x > px && pos.x < px + hitboxSize && pos.y > py && pos.y < py + hitboxSize;
}
@Override
public void onMouseClick(Vec2d pos) {
itemHolder.setHover(this);
}
@Override
public void onRightClick(Vec2d pos) {
itemHolder.setHover(this);
}
@Override
public void onActivate() {
}
@Override
public void onBack() {
}
@Override
public void update(Vec2d mousePos) {
}
}

View File

@ -0,0 +1,9 @@
package projectzombie.menu.gui;
import projectzombie.util.math.ItemStack;
public interface GUIItemSlotGetter {
public boolean isAllowed(ItemStack stack);
public ItemStack getItemStack();
public void setItemStack(ItemStack stack);
}

View File

@ -0,0 +1,31 @@
package projectzombie.menu.gui;
import projectzombie.inventory.IInventory;
import projectzombie.util.math.ItemStack;
public class GUIItemSlotGetterStorage implements GUIItemSlotGetter
{
private IInventory inventory;
private int index;
public GUIItemSlotGetterStorage(IInventory inventory, int index) {
this.inventory = inventory;
this.index = index;
}
@Override
public boolean isAllowed(ItemStack stack) {
return true;
}
@Override
public ItemStack getItemStack() {
return inventory.getItem(index);
}
@Override
public void setItemStack(ItemStack stack) {
inventory.setItem(stack, index);
}
}

View File

@ -5,12 +5,12 @@ import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.text.Text; import projectzombie.text.Text;
public class Label implements GUIComponent public class GUILabel implements GUIComponent
{ {
private Vec2d pos = new Vec2d(0, 0); private Vec2d pos = new Vec2d(0, 0);
private Vec2d size = new Vec2d(0.5, 0.5); private Vec2d size = new Vec2d(0.5, 0.5);
private String text = ""; private String text = "";
private Alignment alignment = Alignment.CENTRE; private GUIAlignment alignment = GUIAlignment.CENTRE;
public void setText(String text) { public void setText(String text) {
this.text = text; this.text = text;
@ -24,7 +24,7 @@ public class Label implements GUIComponent
this.size = size; this.size = size;
} }
public void setAlign(Alignment alignment) { public void setAlign(GUIAlignment alignment) {
this.alignment = alignment; this.alignment = alignment;
} }
@ -68,5 +68,13 @@ public class Label implements GUIComponent
@Override @Override
public void onActivate() { public void onActivate() {
} }
@Override
public void update(Vec2d mousePos) {
}
@Override
public void onRightClick(Vec2d pos) {
}
} }

View File

@ -4,7 +4,7 @@ import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import gl_engine.vec.Vec4d; import gl_engine.vec.Vec4d;
public class Overlay implements GUIComponent public class GUIOverlay implements GUIComponent
{ {
Vec4d color = new Vec4d(0, 0, 0, 0); Vec4d color = new Vec4d(0, 0, 0, 0);
@ -36,5 +36,13 @@ public class Overlay implements GUIComponent
@Override @Override
public void onActivate() { public void onActivate() {
} }
@Override
public void update(Vec2d mousePos) {
}
@Override
public void onRightClick(Vec2d pos) {
}
} }

View File

@ -1,9 +1,9 @@
package projectzombie.menu.gui.components; package projectzombie.menu.gui.components;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.menu.gui.Button; import projectzombie.menu.gui.GUIButton;
public class ButtonBasic extends Button { public class ButtonBasic extends GUIButton {
private ButtonCallback callback; private ButtonCallback callback;

View File

@ -1,7 +1,7 @@
package projectzombie.menu.gui.components; package projectzombie.menu.gui.components;
import projectzombie.menu.gui.Button; import projectzombie.menu.gui.GUIButton;
public interface ButtonCallback { public interface ButtonCallback {
public void onClick(Button button); public void onClick(GUIButton button);
} }

View File

@ -3,9 +3,9 @@ package projectzombie.menu.gui.components;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.menu.MenuSettings; import projectzombie.menu.MenuSettings;
import projectzombie.menu.gui.ButtonGroup; import projectzombie.menu.gui.GUIButtonGroup;
public class ButtonGroupPause extends ButtonGroup public class ButtonGroupPause extends GUIButtonGroup
{ {
public ButtonGroupPause() public ButtonGroupPause()
{ {

View File

@ -1,7 +1,7 @@
package projectzombie.menu.gui.components; package projectzombie.menu.gui.components;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.menu.gui.Alignment; import projectzombie.menu.gui.GUIAlignment;
import projectzombie.settings.Settings; import projectzombie.settings.Settings;
public class ButtonSetting extends ButtonBasic public class ButtonSetting extends ButtonBasic
@ -10,7 +10,7 @@ public class ButtonSetting extends ButtonBasic
public ButtonSetting(String text, ButtonCallback callback) { public ButtonSetting(String text, ButtonCallback callback) {
super(text, callback); super(text, callback);
this.setAlign(Alignment.RIGHT); this.setAlign(GUIAlignment.RIGHT);
} }
@Override @Override

View File

@ -1,9 +1,9 @@
package projectzombie.menu.gui.components; package projectzombie.menu.gui.components;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.menu.gui.Label; import projectzombie.menu.gui.GUILabel;
public class LabelMain extends Label public class LabelMain extends GUILabel
{ {
public LabelMain() { public LabelMain() {
setText("Project Zombie"); setText("Project Zombie");

View File

@ -1,9 +1,9 @@
package projectzombie.menu.gui.components; package projectzombie.menu.gui.components;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.menu.gui.Label; import projectzombie.menu.gui.GUILabel;
public class LabelPause extends Label public class LabelPause extends GUILabel
{ {
public LabelPause(String text) { public LabelPause(String text) {
setText(text); setText(text);

Some files were not shown because too many files have changed in this diff Show More