Sync workspace with server

This commit is contained in:
josua 2020-06-02 11:30:03 +10:00
parent 3c9b7a23e9
commit 400746b88a
207 changed files with 2540 additions and 467 deletions

2
.classpath Normal file → Executable file
View File

@ -2,11 +2,11 @@
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/binary-data-format-v1.3.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/mainloop.jar"/> <classpathentry kind="lib" path="/home/josua/code/Java Libraries/mainloop.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2/joml-1.9.16.jar"/> <classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2/joml-1.9.16.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2/joml-1.9.16-javadoc.jar"/> <classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2/joml-1.9.16-javadoc.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2/joml-1.9.16-sources.jar"/> <classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2/joml-1.9.16-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/LWJGL"/> <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/LWJGL"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/binary-data-format-v1.8.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

0
.gitignore vendored Normal file → Executable file
View File

0
.project Normal file → Executable file
View File

0
.settings/org.eclipse.jdt.core.prefs Normal file → Executable file
View File

BIN
layer.bdf Normal file

Binary file not shown.

0
resources/sound/explosion.ogg Normal file → Executable file
View File

0
resources/sound/gun0.ogg Normal file → Executable file
View File

0
resources/sound/gun1.ogg Normal file → Executable file
View File

0
resources/sound/gun2.ogg Normal file → Executable file
View File

0
resources/sound/gun3.ogg Normal file → Executable file
View File

0
resources/sound/gun4.ogg Normal file → Executable file
View File

0
resources/sound/gun5.ogg Normal file → Executable file
View File

0
resources/sound/gun6.ogg Normal file → Executable file
View File

0
resources/sound/gun7.ogg Normal file → Executable file
View File

0
resources/sound/gun8.ogg Normal file → Executable file
View File

0
resources/sound/gun9.ogg Normal file → Executable file
View File

0
resources/sound/hit0.ogg Normal file → Executable file
View File

0
resources/sound/hit1.ogg Normal file → Executable file
View File

0
resources/sound/hit2.ogg Normal file → Executable file
View File

0
resources/texmap.old.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 89 KiB

BIN
resources/texmap.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 105 KiB

BIN
resources/texmap.xcf Normal file → Executable file

Binary file not shown.

BIN
settings.bdf Normal file → Executable file

Binary file not shown.

16
src/projectzombie/Main.java Normal file → Executable file
View File

@ -2,18 +2,24 @@ package projectzombie;
import java.util.Random; import java.util.Random;
import bdf.file.BdfCompressedFileManager;
import mainloop.manager.MainloopManager; import mainloop.manager.MainloopManager;
import projectzombie.audio.AudioEngine; import projectzombie.audio.AudioEngine;
import projectzombie.audio.AudioSources; import projectzombie.audio.AudioSources;
import projectzombie.display.Camera;
import projectzombie.display.DisplayStatsEventHandler; import projectzombie.display.DisplayStatsEventHandler;
import projectzombie.display.DisplayWindow; import projectzombie.display.DisplayWindow;
import projectzombie.display.bossbar.BossBars; import projectzombie.display.bossbar.BossBars;
import projectzombie.entity.EntityEventHandler; import projectzombie.entity.EntityEventHandler;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Entities;
import projectzombie.init.Items;
import projectzombie.init.LayerGenerators;
import projectzombie.init.Layers; import projectzombie.init.Layers;
import projectzombie.init.Resources; import projectzombie.init.Resources;
import projectzombie.init.Sounds; import projectzombie.init.Sounds;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.init.Tiles;
import projectzombie.input.JoystickCallback; import projectzombie.input.JoystickCallback;
import projectzombie.input.KeyCallback; import projectzombie.input.KeyCallback;
import projectzombie.mainloop.MainloopEventHandler; import projectzombie.mainloop.MainloopEventHandler;
@ -46,6 +52,11 @@ public class Main
Layers.init(rand.nextLong()); Layers.init(rand.nextLong());
player = new EntityPlayer(); player = new EntityPlayer();
GameTimer.resetTime(); GameTimer.resetTime();
/*BdfCompressedFileManager bdf = new BdfCompressedFileManager("./layer.bdf");
Main.world = new World();
Main.world.BdfClassLoad(bdf);*/
BossBars.clear(); BossBars.clear();
} }
@ -56,6 +67,11 @@ public class Main
Cheats.init(args); Cheats.init(args);
Settings.init(); Settings.init();
Items.init();
Entities.init();
Tiles.init();
LayerGenerators.init();
// Load the resources // Load the resources
Resources.loadResources(); Resources.loadResources();

0
src/projectzombie/audio/AudioEngine.java Normal file → Executable file
View File

0
src/projectzombie/audio/AudioObject.java Normal file → Executable file
View File

0
src/projectzombie/audio/AudioRandom.java Normal file → Executable file
View File

0
src/projectzombie/audio/AudioSources.java Normal file → Executable file
View File

3
src/projectzombie/display/Camera.java Normal file → Executable file
View File

@ -10,6 +10,7 @@ public class Camera
public Vec2d angle; public Vec2d angle;
public int renderDistance; public int renderDistance;
public double cameraDistance; public double cameraDistance;
public double distanceFromPlayer;
public static Camera camera; public static Camera camera;
@ -20,5 +21,7 @@ public class Camera
cameraDistance, new Vec2d(Math.toRadians(angle.x), Math.toRadians(-angle.y)))); cameraDistance, new Vec2d(Math.toRadians(angle.x), Math.toRadians(-angle.y))));
this.cameraDistance = cameraDistance; this.cameraDistance = cameraDistance;
this.renderDistance = renderDistance; this.renderDistance = renderDistance;
this.distanceFromPlayer = 10;
} }
} }

6
src/projectzombie/display/DisplayRender.java Normal file → Executable file
View File

@ -24,6 +24,7 @@ import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
import projectzombie.util.math.vec.Vec3d; import projectzombie.util.math.vec.Vec3d;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.chunk.ChunkEventHandler;
public class DisplayRender public class DisplayRender
{ {
@ -59,6 +60,7 @@ public class DisplayRender
// Push the matrix // Push the matrix
GlHelpers.pushMatrix(); GlHelpers.pushMatrix();
if(ChunkEventHandler.loaded)
{ {
// Set matrix mode // Set matrix mode
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
@ -104,9 +106,9 @@ public class DisplayRender
// Render the sorted transparent objects // Render the sorted transparent objects
TransparentObjects.render(camera); TransparentObjects.render(camera);
GlHelpers.popMatrix();
} }
GlHelpers.popMatrix();
} }
// Render the user interface // Render the user interface

0
src/projectzombie/display/DisplayRenderUI.java Normal file → Executable file
View File

View File

8
src/projectzombie/display/DisplayWindow.java Normal file → Executable file
View File

@ -1,5 +1,9 @@
package projectzombie.display; package projectzombie.display;
import static org.lwjgl.glfw.GLFW.GLFW_DOUBLEBUFFER;
import static org.lwjgl.glfw.GLFW.GLFW_FALSE;
import static org.lwjgl.glfw.GLFW.glfwWindowHint;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
@ -64,7 +68,9 @@ public class DisplayWindow implements IMainloopTask
this.height = h.get()*4; this.height = h.get()*4;
// Set the window hint // Set the window hint
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, 0);
GLFW.glfwWindowHint(GLFW.GLFW_SCALE_TO_MONITOR, 1);
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, 0);
GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MAJOR, 3); GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MAJOR, 3);
GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MINOR, 3); GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MINOR, 3);

18
src/projectzombie/display/bossbar/BossBars.java Normal file → Executable file
View File

@ -24,6 +24,8 @@ public class BossBars
TextureReference health_bg = Textures.UI_HEALTH_BG; TextureReference health_bg = Textures.UI_HEALTH_BG;
ArrayList<IBossBar> toRemove = new ArrayList<IBossBar>(); ArrayList<IBossBar> toRemove = new ArrayList<IBossBar>();
double s = GlHelpers.getScale() / 10.0;
// Render the boss bars // Render the boss bars
int i = 0; int i = 0;
for(IBossBar bossbar : bossbars) for(IBossBar bossbar : bossbars)
@ -32,15 +34,15 @@ public class BossBars
double a = 1 - (bossbar.getHealth() / max_health); double a = 1 - (bossbar.getHealth() / max_health);
GlHelpers.begin(); GlHelpers.begin();
health_bg.texCoord(0, 1); GlHelpers.vertex2(-4, 8.5 - i); health_bg.texCoord(0, 1); GlHelpers.vertex2(-4*s, 8.5*s - i);
health_bg.texCoord(0, 0); GlHelpers.vertex2(-4, 9.0 - i); health_bg.texCoord(0, 0); GlHelpers.vertex2(-4*s, 9.0*s - i);
health_bg.texCoord(1, 0); GlHelpers.vertex2(4, 9.0 - i); health_bg.texCoord(1, 0); GlHelpers.vertex2(4*s, 9.0*s - i);
health_bg.texCoord(1, 1); GlHelpers.vertex2(4, 8.5 - i); health_bg.texCoord(1, 1); GlHelpers.vertex2(4*s, 8.5*s - i);
health_fg.texCoord(0, 1); GlHelpers.vertex2(-4, 8.5 - i); health_fg.texCoord(0, 1); GlHelpers.vertex2(-4*s, 8.5*s - i);
health_fg.texCoord(0, 0); GlHelpers.vertex2(-4, 9.0 - i); health_fg.texCoord(0, 0); GlHelpers.vertex2(-4*s, 9.0*s - i);
health_fg.texCoord(1-a, 0); GlHelpers.vertex2(4-a*8, 9.0 - i); health_fg.texCoord(1-a, 0); GlHelpers.vertex2(4*s-a*8*s, 9.0*s - i);
health_fg.texCoord(1-a, 1); GlHelpers.vertex2(4-a*8, 8.5 - i); health_fg.texCoord(1-a, 1); GlHelpers.vertex2(4*s-a*8*s, 8.5*s - i);
GlHelpers.end(); GlHelpers.end();
i += 1; i += 1;

0
src/projectzombie/display/bossbar/IBossBar.java Normal file → Executable file
View File

View File

View File

View File

40
src/projectzombie/display/lighting/TileLighting.java Normal file → Executable file
View File

@ -20,6 +20,7 @@ public class TileLighting implements IMainloopTask
public static void update() public static void update()
{ {
if(Camera.camera == null) return;
if(!ChunkEventHandler.loaded) return; if(!ChunkEventHandler.loaded) return;
Layer layer = Main.world.getLayer(); Layer layer = Main.world.getLayer();
EntityPlayer player = Main.player; EntityPlayer player = Main.player;
@ -55,6 +56,11 @@ public class TileLighting implements IMainloopTask
MainloopHelpers.loopAsync(0, range.maxValue(), MainloopHelpers.loopAsync(0, range.maxValue(),
(it) -> { (it) -> {
if(!ChunkEventHandler.loaded) {
return;
}
Vec4i upto = Vec4i.fromId(range, it); Vec4i upto = Vec4i.fromId(range, it);
Vec2i cpos = new Vec2i( Vec2i cpos = new Vec2i(
@ -140,12 +146,20 @@ public class TileLighting implements IMainloopTask
// Set the light level // Set the light level
if(daylightMode) { if(daylightMode) {
if(tile_f.tile.passNaturalLight && tile_b.tile.passNaturalLight && it == 1) { if(tile_f.tile.passNaturalLight && tile_b.tile.passNaturalLight && it != 0) {
return; return;
} }
if(light <= chunk_t.getDaylightLevel(lid)) return; if(light <= chunk_t.getDaylightLevel(lid)) return;
chunk_t.setDaylightLevel(light, lid); chunk_t.setDaylightLevel(light, lid);
} else { } else {
if((tile_f.tile.emitsLight || tile_b.tile.emitsLight) && it == 1) {
double light_external = MathHelpers.biggest(
tile_f.tile.getLightLevel(tile_f, lpos),
tile_b.tile.getLightLevel(tile_b, lpos));
if(light_external >= light) {
return;
};
}
if(light <= chunk_t.getLightLevel(lid)) return; if(light <= chunk_t.getLightLevel(lid)) return;
chunk_t.setLightLevel(light, lid); chunk_t.setLightLevel(light, lid);
} }
@ -163,30 +177,6 @@ public class TileLighting implements IMainloopTask
new Vec2i(lpos.x, lpos.y-1) new Vec2i(lpos.x, lpos.y-1)
}; };
int samechunk = 0;
for(Vec2i position : positions) {
Vec2i new_cpos = Layer.getChunkPosFromPos(position);
if(new_cpos.equal(chunk.c_pos)) {
samechunk += 1;
}
}
if(samechunk == 4) {
double neighbour_light = 0;
for(Vec2i position : positions) {
TileState tf = chunk.getFrontTile(position);
TileState tb = chunk.getBackTile(position);
neighbour_light = MathHelpers.smallest(MathHelpers.biggest(
tb.tile.getLightLevel(tb, position),
tf.tile.getLightLevel(tf, position)),
neighbour_light);
}
if(neighbour_light > light) {
return;
}
}
// Add the light to all the adjacent positions // Add the light to all the adjacent positions
for(Vec2i position : positions) { for(Vec2i position : positions) {
addLightToTiles(chunks, layer, position, it + 1, light - dissipation, daylightMode); addLightToTiles(chunks, layer, position, it + 1, light - dissipation, daylightMode);

View File

View File

View File

197
src/projectzombie/entity/Entity.java Normal file → Executable file
View File

@ -1,7 +1,13 @@
package projectzombie.entity; package projectzombie.entity;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Random; import java.util.Random;
import bdf.classes.IBdfClassManager;
import bdf.types.BdfArray;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import mainloop.task.IMainloopTask; import mainloop.task.IMainloopTask;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
@ -14,17 +20,16 @@ import projectzombie.util.math.TileState;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
import projectzombie.util.math.vec.Vec2i; import projectzombie.util.math.vec.Vec2i;
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 class Entity implements ITransparentObject public class Entity implements ITransparentObject, IBdfClassManager
{ {
public Vec2d pos; public Vec2d pos;
public double angle = 0;
public boolean opaqueTile = true; public boolean opaqueTile = true;
public double hitbox = 1; public double hitbox = 1;
public boolean isSolid = false; public boolean isSolid = false;
public Chunk chunk; public Chunk chunk;
private double speed = 1;
private TileState tile_front; private TileState tile_front;
private TileState tile_back; private TileState tile_back;
public boolean crossUnWalkable = true; public boolean crossUnWalkable = true;
@ -34,18 +39,123 @@ public class Entity implements ITransparentObject
public int stepOnTileCooldown = 0; public int stepOnTileCooldown = 0;
protected double getTilesLightDissipation() {
if(chunk == null) return 0;
TileState tsf = chunk.getFrontTile(pos.toInt());
TileState tsb = chunk.getBackTile(pos.toInt());
return MathHelpers.biggest(
tsf.tile.getLightDissipation(tsf),
tsb.tile.getLightDissipation(tsb));
}
protected double getLightWithHeight(double light) {
double height = 1;
if(this instanceof EntityHeight) {
height *= ((EntityHeight)this).getHeight();
}
return light - (this.getTilesLightDissipation() * Math.abs(height));
}
public int getID() {
for(int i=0;i<Entities.entities.size();i++) {
Class<? extends Entity> ec = Entities.entities.get(i);
if(ec == this.getClass()) {
return i;
}
}
return -1;
}
public static Entity loadEntity(BdfObject bdf)
{
try
{
// Load the entity id
BdfNamedList nl = bdf.getNamedList();
int id = nl.get("id").getInteger();
// Send back null if the id is out of range
if(id < 0 || id >= Entities.entities.size()) {
System.out.println("Warning: Invalid ID detected: " + id);
return null;
}
// Get the class and the constructor
Class<? extends Entity> ecl = Entities.entities.get(id);
Constructor<? extends Entity> econ = ecl.getConstructor(BdfObject.class);
// Send back the new entity
return econ.newInstance(bdf);
}
catch(
NoSuchMethodException |
SecurityException |
InstantiationException |
IllegalAccessException |
IllegalArgumentException |
InvocationTargetException e)
{
e.printStackTrace();
// Send null if there was an issue
return null;
}
}
public Entity(Vec2d pos) public Entity(Vec2d pos)
{ {
// Add this entity to the list of entities
Entities.entities.add(this);
// Store the specified values // Store the specified values
this.pos = pos; this.pos = pos;
} }
public Entity(BdfObject bdf) {
this.BdfClassLoad(bdf);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
BdfNamedList nl = bdf.getNamedList();
BdfArray e = nl.get("e").getArray();
pos = new Vec2d(e.get(0));
opaqueTile = e.get(1).getBoolean();
hitbox = e.get(2).getDouble();
isSolid = e.get(3).getBoolean();
crossUnWalkable = e.get(4).getBoolean();
goThroughSolid = e.get(5).getBoolean();
emitsLight = e.get(6).getBoolean();
stepOnTileCooldown = e.get(7).getInteger();
}
@Override
public void BdfClassSave(BdfObject bdf)
{
// Get the ID and return if its invalid (entity can't be saved)
int id = getID();
if(id == -1) return;
BdfNamedList nl = bdf.getNamedList();
nl.set("id", BdfObject.withInteger(getID()));
BdfObject pos_bdf = new BdfObject();
pos.BdfClassSave(pos_bdf);
BdfArray e = new BdfArray();
nl.set("e", BdfObject.withArray(e));
e.add(pos_bdf);
e.add(BdfObject.withBoolean(opaqueTile));
e.add(BdfObject.withDouble(hitbox));
e.add(BdfObject.withBoolean(isSolid));
e.add(BdfObject.withBoolean(crossUnWalkable));
e.add(BdfObject.withBoolean(goThroughSolid));
e.add(BdfObject.withBoolean(emitsLight));
e.add(BdfObject.withInteger(stepOnTileCooldown));
}
public void tick(Chunk chunk, Layer layer) { public void tick(Chunk chunk, Layer layer) {
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); Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
if(chunk == null) chunk = layer.getChunk(pos); if(chunk == null) chunk = layer.getChunk(pos);
this.chunk = chunk; this.chunk = chunk;
@ -56,15 +166,23 @@ public class Entity implements ITransparentObject
stepOnTileCooldown -= 1; stepOnTileCooldown -= 1;
} }
if(this.isSolid) moveAwayFromSolidEntities(layer);
{
this.addSlowness(tile_back.tile.slowness);
this.addSlowness(tile_front.tile.slowness);
}
} }
public void addSlowness(double amount) { protected void moveAwayFromSolidEntities(Layer layer)
speed *= (1 - amount); {
if(!goThroughSolid)
{
for(Entity e : layer.getNearbyEntities(pos, hitbox))
{
if(e.isSolid && e != this) {
double angle = Math.toDegrees(Math.atan2(
pos.y - e.pos.y,
pos.x - e.pos.x));
moveTowards(angle + 180, 0.1);
}
}
}
} }
public void render(Vec2d pos, Camera camera) { public void render(Vec2d pos, Camera camera) {
@ -91,19 +209,17 @@ public class Entity implements ITransparentObject
return this.opaqueTile; return this.opaqueTile;
} }
public void moveForward(double speed) {
this.moveTowards(0, speed);
}
public void moveBackward(double speed) {
this.moveTowards(0, -speed);
}
public void moveTowards(double angle, double speed) public void moveTowards(double angle, double speed)
{ {
if(chunk == null) {
chunk = Main.world.getLayer().getChunk(pos);
}
// Calculate the new position // Calculate the new position
speed *= this.speed; speed *= 1 - MathHelpers.biggest(
Vec2d pos = this.pos.add(MathHelpers.moveTowards2(speed, Math.toRadians(this.angle + angle))); chunk.getFrontTile(pos.toInt()).tile.slowness,
chunk.getBackTile(pos.toInt()).tile.slowness);
Vec2d pos = this.pos.add(MathHelpers.moveTowards2(speed, Math.toRadians(angle)));
// Check if the new position is legal // Check if the new position is legal
if(this.moveIsLegal(new Vec2d(this.pos.x, pos.y))) this.pos.y = pos.y; if(this.moveIsLegal(new Vec2d(this.pos.x, pos.y))) this.pos.y = pos.y;
@ -113,16 +229,20 @@ public class Entity implements ITransparentObject
if(this.isSolid) activateSteppedOnTile(); if(this.isSolid) activateSteppedOnTile();
} }
public void moveForward() { public void moveInVector(Vec2d vec, double speed)
this.moveForward(0.1); {
} // Calculate the new position
speed *= 1 - MathHelpers.biggest(
public void moveBackward() { chunk.getFrontTile(pos.toInt()).tile.slowness,
this.moveBackward(0.1); chunk.getBackTile(pos.toInt()).tile.slowness);
} Vec2d pos = vec.multiply(speed).add(this.pos);
public void moveTowards(double angle) { // Check if the new position is legal
moveTowards(angle, 0.1); if(this.moveIsLegal(new Vec2d(this.pos.x, pos.y))) this.pos.y = pos.y;
if(this.moveIsLegal(new Vec2d(pos.x, this.pos.y))) this.pos.x = pos.x;
// Activate stepped on tiles if the entity is "solid"
if(this.isSolid) activateSteppedOnTile();
} }
public void kill() { public void kill() {
@ -168,7 +288,6 @@ public class Entity implements ITransparentObject
// Is this entity solid // Is this entity solid
if(!goThroughSolid || !crossUnWalkable) if(!goThroughSolid || !crossUnWalkable)
{ {
// Check the tile the player is standing on // Check the tile the player is standing on
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
@ -236,8 +355,12 @@ public class Entity implements ITransparentObject
@Override @Override
public void MainLoopUpdate() { public void MainLoopUpdate() {
if(!ChunkEventHandler.loaded)
return;
if(chunk == null)
chunk = Main.world.getLayer().getChunk(pos);
if(Main.menu.doGameloop) { if(Main.menu.doGameloop) {
moveTowards(Math.toRadians(angle) + 180, a[0]/100.0); moveTowards(angle, a[0]/100.0);
a[0] -= a[0] / 100.0; a[0] -= a[0] / 100.0;
} }
} }

0
src/projectzombie/entity/EntityAlive.java Normal file → Executable file
View File

91
src/projectzombie/entity/EntityBoss.java Normal file → Executable file
View File

@ -1,5 +1,9 @@
package projectzombie.entity; package projectzombie.entity;
import java.util.Random;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.display.bossbar.BossBars; import projectzombie.display.bossbar.BossBars;
@ -19,7 +23,7 @@ import projectzombie.util.math.vec.Vec3d;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
public class EntityBoss extends EntityVertical implements IBossBar public class EntityBoss extends EntityVertical implements IBossBar, EntityKillWithParticles
{ {
private boolean moving = false; private boolean moving = false;
private boolean firing = false; private boolean firing = false;
@ -27,10 +31,55 @@ public class EntityBoss extends EntityVertical implements IBossBar
private double health = max_health; private double health = max_health;
private int bullet_frequency = 0; private int bullet_frequency = 0;
private int spawn_frequency = 0; private int spawn_frequency = 0;
private double time = 0;
private OpenSimplexNoise noise_gun; private OpenSimplexNoise noise_gun;
private OpenSimplexNoise noise_walk; private OpenSimplexNoise noise_walk;
private OpenSimplexNoise noise_spawn; private OpenSimplexNoise noise_spawn;
protected OpenSimplexNoise noise_target_x;
protected OpenSimplexNoise noise_target_y;
private long seed;
public EntityBoss(BdfObject bdf) {
super(bdf, TextureReference.EMPTY, new Vec2d(4, 4));
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
health = nl.get("health").getDouble();
bullet_frequency = nl.get("bullet_freq").getInteger();
spawn_frequency = nl.get("spawn_frq").getInteger();
this.isSolid = true;
this.goThroughSolid = false;
this.crossUnWalkable = false;
this.hitbox = 2;
long seed = nl.get("seed").getLong();
Random rand = new Random(seed);
this.noise_gun = new OpenSimplexNoise(rand.nextLong());
this.noise_walk = new OpenSimplexNoise(rand.nextLong());
this.noise_spawn = new OpenSimplexNoise(rand.nextLong());
this.noise_target_x = new OpenSimplexNoise(rand.nextLong());
this.noise_target_y = new OpenSimplexNoise(rand.nextLong());
BossBars.register(this);
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("health", BdfObject.withDouble(health));
nl.set("bullet_freq", BdfObject.withInteger(bullet_frequency));
nl.set("spawn_freq", BdfObject.withInteger(spawn_frequency));
nl.set("seed", BdfObject.withLong(seed));
}
public EntityBoss(Vec2d pos) { public EntityBoss(Vec2d pos) {
super(pos, TextureReference.EMPTY, new Vec2d(4, 4)); super(pos, TextureReference.EMPTY, new Vec2d(4, 4));
@ -38,11 +87,15 @@ public class EntityBoss extends EntityVertical implements IBossBar
this.isSolid = true; this.isSolid = true;
this.goThroughSolid = false; this.goThroughSolid = false;
this.crossUnWalkable = false; this.crossUnWalkable = false;
this.hitbox = 1; this.hitbox = 2;
long seed = rand.nextLong();
Random rand = new Random(seed);
this.noise_gun = new OpenSimplexNoise(rand.nextLong()); this.noise_gun = new OpenSimplexNoise(rand.nextLong());
this.noise_walk = new OpenSimplexNoise(rand.nextLong()); this.noise_walk = new OpenSimplexNoise(rand.nextLong());
this.noise_spawn = new OpenSimplexNoise(rand.nextLong()); this.noise_spawn = new OpenSimplexNoise(rand.nextLong());
this.noise_target_x = new OpenSimplexNoise(rand.nextLong());
this.noise_target_y = new OpenSimplexNoise(rand.nextLong());
BossBars.register(this); BossBars.register(this);
} }
@ -51,8 +104,12 @@ public class EntityBoss extends EntityVertical implements IBossBar
public void tick(Chunk chunk, Layer layer) { public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer); super.tick(chunk, layer);
double angle = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y); double angle = Math.atan2(
this.angle = Math.toDegrees(angle) + 180; pos.x - Main.player.pos.x + noise_target_x.eval(
time*2, Main.player.pos.x/25, Main.player.pos.y/25)*10,
pos.y - Main.player.pos.y + noise_target_y.eval(
time*2, Main.player.pos.y/25, Main.player.pos.y/25)*10);
angle = Math.toDegrees(angle) + 180;
if(this.noise_spawn.eval(GameTimer.getTime() / 500.0, 0) > 0.2) { if(this.noise_spawn.eval(GameTimer.getTime() / 500.0, 0) > 0.2) {
if(spawn_frequency == 0) { if(spawn_frequency == 0) {
@ -77,7 +134,7 @@ public class EntityBoss extends EntityVertical implements IBossBar
if(bullet_frequency == 0) if(bullet_frequency == 0)
{ {
Vec2d gun_offset = MathHelpers.moveTowards2(1, Math.toRadians(90 + this.angle)); Vec2d gun_offset = MathHelpers.moveTowards2(1, Math.toRadians(90));
Vec3d pos1 = new Vec3d(pos.x + gun_offset.x, pos.y + gun_offset.y, 1); Vec3d pos1 = new Vec3d(pos.x + gun_offset.x, pos.y + gun_offset.y, 1);
double distance_1 = pos1.distance(new Vec3d(pos.x, pos.y, pos1.z)); double distance_1 = pos1.distance(new Vec3d(pos.x, pos.y, pos1.z));
@ -90,9 +147,9 @@ public class EntityBoss extends EntityVertical implements IBossBar
double angle2_0 = Math.toDegrees(Math.atan2(pos2.x - Main.player.pos.x, pos2.y - Main.player.pos.y)) + 180; double angle2_0 = Math.toDegrees(Math.atan2(pos2.x - Main.player.pos.x, pos2.y - Main.player.pos.y)) + 180;
double angle2_1 = Math.toDegrees(Math.atan2(distance_2, pos2.z - 1)) - 90; double angle2_1 = Math.toDegrees(Math.atan2(distance_2, pos2.z - 1)) - 90;
layer.spawnEntity(new EntityBullet(pos.add(gun_offset), this, angle1_0, 20, 5, 1000 layer.spawnEntity(new EntityBullet(pos.add(gun_offset), this, angle1_0, 20, 1000
).withHeight(angle1_1, pos1.z)); ).withHeight(angle1_1, pos1.z));
layer.spawnEntity(new EntityBullet(pos.subtract(gun_offset), this, angle2_0, 20, 5, 1000 layer.spawnEntity(new EntityBullet(pos.subtract(gun_offset), this, angle2_0, 20, 1000
).withHeight(angle2_1, pos2.z)); ).withHeight(angle2_1, pos2.z));
bullet_frequency = 10; bullet_frequency = 10;
} }
@ -109,13 +166,16 @@ public class EntityBoss extends EntityVertical implements IBossBar
} }
if(this.noise_walk.eval(GameTimer.getTime() / 500.0, 0) > -0.4) { if(this.noise_walk.eval(GameTimer.getTime() / 500.0, 0) > -0.4) {
this.moveForward(); this.moveTowards(angle);
this.moving = true; this.moving = true;
} }
else { else {
this.moving = false; this.moving = false;
} }
// Increase time
time += 0.001;
} }
@Override @Override
@ -186,21 +246,10 @@ public class EntityBoss extends EntityVertical implements IBossBar
return health >= 0; return health >= 0;
} }
@Override
public void moveTowards(double angle) { public void moveTowards(double angle) {
this.moveTowards(angle, 0.02); this.moveTowards(angle, 0.02);
} }
@Override
public void moveBackward() {
this.moveBackward(0.02);
}
@Override
public void moveForward() {
this.moveForward(0.02);
}
@Override @Override
public void onDeath(Layer layer) { public void onDeath(Layer layer) {
IBossBar.super.onDeath(layer); IBossBar.super.onDeath(layer);
@ -229,4 +278,8 @@ public class EntityBoss extends EntityVertical implements IBossBar
@Override @Override
public void push(double amount, double angle) { public void push(double amount, double angle) {
} }
@Override
protected void moveAwayFromSolidEntities(Layer layer) {
}
} }

53
src/projectzombie/entity/EntityBullet.java Normal file → Executable file
View File

@ -1,9 +1,13 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.particle.ParticleBlood; import projectzombie.entity.particle.ParticleBlood;
import projectzombie.init.Sounds; import projectzombie.init.Sounds;
import projectzombie.settings.SettingQuality;
import projectzombie.tiles.Tile; import projectzombie.tiles.Tile;
import projectzombie.tiles.TileBulletBreakable;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.random.RandomHelpers;
@ -19,20 +23,49 @@ public class EntityBullet extends EntityParticle
private Entity parent; private Entity parent;
private double damage; private double damage;
private int breakchance;
private double height = 0.2; private double height = 0.2;
private double height_angle = 0; private double height_angle = 0;
private double angle = 0;
private Vec3d velocity; private Vec3d velocity;
public EntityBullet(Vec2d pos, Entity parent, double angle, double damage, int breakchance, int despawn_time) { public EntityBullet(BdfObject bdf) {
super(pos, 0.2, 0.4); super(bdf);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
time = nl.get("time").getInteger();
damage = nl.get("damage").getDouble();
height = nl.get("height").getDouble();
height_angle = nl.get("angle_h").getDouble();
angle = nl.get("angle").getDouble();
velocity = new Vec3d(nl.get("velocity"));
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("time", BdfObject.withInteger(time));
nl.set("damage", BdfObject.withDouble(damage));
nl.set("height", BdfObject.withDouble(height));
nl.set("angle_h", BdfObject.withDouble(height_angle));
nl.set("angle", BdfObject.withDouble(angle));
velocity.BdfClassSave(nl.get("velocity"));
}
public EntityBullet(Vec2d pos, Entity parent, double angle, double damage, int despawn_time) {
super(pos, 0.2, despawn_time);
// Store some specified values // Store some specified values
this.angle = angle; this.angle = angle;
this.parent = parent; this.parent = parent;
this.damage = damage; this.damage = damage;
this.breakchance = breakchance;
this.time = despawn_time; this.time = despawn_time;
// Calculate the velocity vector // Calculate the velocity vector
@ -86,7 +119,8 @@ public class EntityBullet extends EntityParticle
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_f.tileHitbox) if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_f.tileHitbox)
{ {
// Break the block // Break the block
if(RandomHelpers.randrange(rand, breakchance) == 0) { if(tile_f instanceof TileBulletBreakable && RandomHelpers.randrange(rand,
((TileBulletBreakable)tile_f).getBulletBreakChance()) == 0) {
chunk.breakFrontTile(tpos); chunk.breakFrontTile(tpos);
} }
@ -97,7 +131,8 @@ public class EntityBullet extends EntityParticle
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_b.tileHitbox) if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_b.tileHitbox)
{ {
// Break the block // Break the block
if(RandomHelpers.randrange(rand, breakchance) == 0) { if(tile_f instanceof TileBulletBreakable && RandomHelpers.randrange(rand,
((TileBulletBreakable)tile_f).getBulletBreakChance()) == 0) {
chunk.breakBackTile(tpos); chunk.breakBackTile(tpos);
} }
@ -120,8 +155,10 @@ public class EntityBullet extends EntityParticle
e.push(1, angle); e.push(1, angle);
// Spawn some blood particles // Spawn some blood particles
for(int i=0;i<ea.bloodParticles();i++) { if(EntityParticle.MODE != SettingQuality.OFF) {
chunk.spawnEntity(new ParticleBlood(rand, pos.copy(), angle)); for(int i=0;i<ea.bloodParticles();i++) {
chunk.spawnEntity(new ParticleBlood(rand, pos.copy(), angle));
}
} }
// Play the hit noise // Play the hit noise

4
src/projectzombie/entity/EntityDummy.java Normal file → Executable file
View File

@ -1,10 +1,14 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfObject;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
public class EntityDummy extends EntityVertical implements EntityAlive public class EntityDummy extends EntityVertical implements EntityAlive
{ {
public EntityDummy(BdfObject bdf) {
super(bdf, Textures.ENTITY_DUMMY, new Vec2d(1, 1));
}
public EntityDummy(Vec2d pos) { public EntityDummy(Vec2d pos) {
super(pos, Textures.ENTITY_DUMMY, new Vec2d(1, 1)); super(pos, Textures.ENTITY_DUMMY, new Vec2d(1, 1));

0
src/projectzombie/entity/EntityEventHandler.java Normal file → Executable file
View File

27
src/projectzombie/entity/EntityExplosion.java Normal file → Executable file
View File

@ -1,11 +1,14 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.entity.particle.ParticleBlood; import projectzombie.entity.particle.ParticleBlood;
import projectzombie.entity.particle.ParticleBreak; import projectzombie.entity.particle.ParticleBreak;
import projectzombie.entity.particle.ParticleSmoke; import projectzombie.entity.particle.ParticleSmoke;
import projectzombie.init.Sounds; import projectzombie.init.Sounds;
import projectzombie.init.Tiles; import projectzombie.init.Tiles;
import projectzombie.util.gl.texture.IHasTexture;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
import projectzombie.util.math.TileState; import projectzombie.util.math.TileState;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
@ -19,12 +22,34 @@ public class EntityExplosion extends Entity
private double damage; private double damage;
private int radius; private int radius;
public EntityExplosion(BdfObject bdf) {
super(bdf);
}
public EntityExplosion(Vec2d pos, int radius, double damage) { public EntityExplosion(Vec2d pos, int radius, double damage) {
super(pos); super(pos);
this.damage = damage; this.damage = damage;
this.radius = radius; this.radius = radius;
} }
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
damage = nl.get("damage").getDouble();
radius = nl.get("radius").getInteger();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("damage", BdfObject.withDouble(damage));
nl.set("radius", BdfObject.withInteger(radius));
}
@Override @Override
public void tick(Chunk chunk, Layer layer) { public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer); super.tick(chunk, layer);
@ -81,11 +106,13 @@ public class EntityExplosion extends Entity
// Set the tiles // Set the tiles
if(!bts.tile.unbreakable) { if(!bts.tile.unbreakable) {
l.setBackTile(ets, tpos); l.setBackTile(ets, tpos);
if(fts.tile instanceof IHasTexture)
l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), bts)); l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), bts));
} }
if(!fts.tile.unbreakable) { if(!fts.tile.unbreakable) {
l.setFrontTile(Tiles.VOID.getDefaultState(), tpos); l.setFrontTile(Tiles.VOID.getDefaultState(), tpos);
if(fts.tile instanceof IHasTexture)
l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), fts)); l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), fts));
} }

7
src/projectzombie/entity/EntityFlare.java Normal file → Executable file
View File

@ -1,5 +1,6 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfObject;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.gl.texture.TextureReference;
@ -8,6 +9,10 @@ import projectzombie.world.layer.Layer;
public class EntityFlare extends EntityTnt public class EntityFlare extends EntityTnt
{ {
public EntityFlare(BdfObject bdf) {
super(bdf);
}
@Override @Override
protected void explode(Layer layer) { protected void explode(Layer layer) {
kill(); kill();
@ -26,7 +31,7 @@ public class EntityFlare extends EntityTnt
@Override @Override
public double getLightLevel() { public double getLightLevel() {
return (1 - (this.height * (1/12.0))) * ( rand.nextDouble() / 10.0 + 0.9 ); return getLightWithHeight(1 - (this.height * (1/12.0))) * ( rand.nextDouble() / 10.0 + 0.9 );
} }
} }

31
src/projectzombie/entity/EntityGrapplingHook.java Normal file → Executable file
View File

@ -1,9 +1,10 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Layers;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
@ -16,6 +17,28 @@ public class EntityGrapplingHook extends EntityVertical
private int layerId; private int layerId;
private double height; private double height;
private Entity entity; private Entity entity;
public EntityGrapplingHook(BdfObject bdf) {
super(bdf, Textures.ENTITY_GRAPPLING_HOOK, new Vec2d(1, 16));
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
layerId = nl.get("layer").getInteger();
height = nl.get("height").getDouble();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("layer", BdfObject.withInteger(layerId));
nl.set("height", BdfObject.withDouble(height));
}
public EntityGrapplingHook(Vec2d pos, int layerId, Entity entity) { public EntityGrapplingHook(Vec2d pos, int layerId, Entity entity) {
super(pos, Textures.ENTITY_GRAPPLING_HOOK, new Vec2d(1, 16)); super(pos, Textures.ENTITY_GRAPPLING_HOOK, new Vec2d(1, 16));
@ -50,7 +73,11 @@ public class EntityGrapplingHook extends EntityVertical
if(h >= 8) if(h >= 8)
{ {
ea.setHeight(0); ea.setHeight(0);
Main.world.setLayer(Layers.getLayer(layerId)); Main.world.setLayer(layerId);
if(layer.layergen.destroyOnLeave) {
Main.world.removeLayer(layerId);
}
if(entity instanceof EntityPlayer) if(entity instanceof EntityPlayer)
{ {

0
src/projectzombie/entity/EntityHeight.java Normal file → Executable file
View File

0
src/projectzombie/entity/EntityInventory.java Normal file → Executable file
View File

76
src/projectzombie/entity/EntityItem.java Normal file → Executable file
View File

@ -1,6 +1,9 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.init.Textures;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.gl.texture.TextureReference;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
@ -14,21 +17,65 @@ public class EntityItem extends EntityVertical
private ItemStack stack; private ItemStack stack;
private double height = 0; private double height = 0;
private double height_speed; private double height_speed;
private int pickup_time = 100; private int pickup_time = 200;
private long age = 0;
public double angle;
public EntityItem(BdfObject bdf) {
super(bdf, TextureReference.EMPTY, new Vec2d(0.5, 0.5));
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
stack = new ItemStack(nl.get("stack"));
height = nl.get("height").getDouble();
height_speed = nl.get("speed_h").getDouble();
pickup_time = nl.get("pickup").getInteger();
age = nl.get("age").getLong();
angle = nl.get("angle").getDouble();
tex = stack.item.texture;
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
stack.BdfClassSave(nl.get("stack"));
nl.set("height", BdfObject.withDouble(height));
nl.set("speed_h", BdfObject.withDouble(height_speed));
nl.set("pickup", BdfObject.withInteger(pickup_time));
nl.set("age", BdfObject.withLong(age));
nl.set("angle", BdfObject.withDouble(angle));
}
public EntityItem(Vec2d pos, ItemStack stack) { public EntityItem(Vec2d pos, ItemStack stack) {
super(pos, stack.item.texture, new Vec2d(0.5, 0.5)); super(pos, stack.item.texture, new Vec2d(0.5, 0.5));
this.emitsLight = true;
this.opaqueTile = true; this.opaqueTile = true;
this.stack = stack; this.stack = stack;
this.angle = RandomHelpers.randrange(rand, 360); this.angle = RandomHelpers.randrange(rand, 360);
height_speed = RandomHelpers.randrange(rand, 10000) / 200000.0; height_speed = RandomHelpers.randrange(rand, 10000) / 200000.0;
} }
@Override
public double getLightLevel() {
if(this.stack.isEmpty()) return 0;
return getLightWithHeight(this.stack.item.getLightLevel());
}
@Override @Override
public void tick(Chunk chunk, Layer layer) { public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer); super.tick(chunk, layer);
age += 1;
height += height_speed; height += height_speed;
height_speed -= 0.001; height_speed -= 0.001;
@ -42,7 +89,30 @@ public class EntityItem extends EntityVertical
} }
else { else {
moveForward(0.01); moveTowards(angle, 0.01);
}
// Merge nearby stacks
for(Entity e : layer.getNearbyEntities(pos, 1))
{
if(e instanceof EntityItem && e != this) {
EntityItem ei = (EntityItem) e;
if(
ei.stack.meta == this.stack.meta &&
ei.stack.item == this.stack.item &&
ei.age > this.age
) {
this.pickup_time = 200;
this.stack.count += ei.stack.count;
this.pos = new Vec2d(
ei.pos.x / 2 + this.pos.x / 2,
ei.pos.y / 2 + this.pos.y / 2);
this.height = ei.height / 2 + this.height / 2;
this.height_speed = ei.height_speed / 2 + this.height_speed / 2;
ei.kill();
}
}
} }
if(pickup_time == 0) if(pickup_time == 0)
@ -68,7 +138,7 @@ public class EntityItem extends EntityVertical
public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) { public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) {
GlHelpers.pushMatrix(); GlHelpers.pushMatrix();
GlHelpers.translate3(0, 0, height); GlHelpers.translate3(0, 0, height);
super.render(pos, camera, tex, size); super.render(pos, camera, stack.item.texture, size);
GlHelpers.popMatrix(); GlHelpers.popMatrix();
} }
} }

View File

@ -0,0 +1,6 @@
package projectzombie.entity;
public interface EntityKillWithParticles
{
public void killWithParticles();
}

10
src/projectzombie/entity/EntityParticle.java Normal file → Executable file
View File

@ -1,7 +1,9 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfObject;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.settings.SettingQuality;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
@ -9,9 +11,15 @@ import projectzombie.world.layer.Layer;
public class EntityParticle extends Entity public class EntityParticle extends Entity
{ {
public static SettingQuality MODE = SettingQuality.FANCY;
private double height; private double height;
private double size; private double size;
public EntityParticle(BdfObject bdf) {
super(bdf);
}
public EntityParticle(Vec2d pos, double size, double height) { public EntityParticle(Vec2d pos, double size, double height) {
super(pos); super(pos);
@ -34,7 +42,7 @@ public 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.pos.squareDistance(pos) > 32) this.kill(); if(Main.player.pos.squareDistance(pos) > Camera.camera.renderDistance * 16) this.kill();
} }
@Override @Override

40
src/projectzombie/entity/EntityTnt.java Normal file → Executable file
View File

@ -1,5 +1,7 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.particle.ParticleSpark; import projectzombie.entity.particle.ParticleSpark;
import projectzombie.init.Textures; import projectzombie.init.Textures;
@ -18,6 +20,38 @@ public class EntityTnt extends EntityVertical
private int explode_radius; private int explode_radius;
private double explode_damage; private double explode_damage;
public EntityTnt(BdfObject bdf) {
super(bdf, Textures.ENTITY_TNT, new Vec2d(0.5, 0.5));
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
height = nl.get("height").getDouble();
velocity = new Vec3d(nl.get("velocity"));
BdfNamedList explode = nl.get("explosion").getNamedList();
explode_time = explode.get("time").getInteger();
explode_radius = explode.get("radius").getInteger();
explode_damage = explode.get("damage").getDouble();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("height", BdfObject.withDouble(height));
velocity.BdfClassSave(nl.get("velocity"));
BdfNamedList explode = nl.get("explosion").getNamedList();
explode.set("time", BdfObject.withInteger(explode_time));
explode.set("radius", BdfObject.withInteger(explode_radius));
explode.set("damage", BdfObject.withDouble(explode_damage));
}
public EntityTnt(Vec2d pos, double angle, int explode_radius, double explode_damage) { public EntityTnt(Vec2d pos, double angle, int explode_radius, double explode_damage) {
super(pos, Textures.ENTITY_TNT, new Vec2d(0.5, 0.5)); super(pos, Textures.ENTITY_TNT, new Vec2d(0.5, 0.5));
@ -93,7 +127,11 @@ public class EntityTnt extends EntityVertical
@Override @Override
public double getLightLevel() { public double getLightLevel() {
return (1 - (this.height * (1/12.0))) * rand.nextDouble(); return getLightWithHeight(1 - (this.height * (1/12.0))) * ( rand.nextDouble() / 10.0 + 0.9 );
}
@Override
protected void moveAwayFromSolidEntities(Layer layer) {
} }
} }

24
src/projectzombie/entity/EntityVertical.java Normal file → Executable file
View File

@ -1,18 +1,27 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfObject;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.particle.ParticleBreak;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.gl.VerticalRender; import projectzombie.util.gl.VerticalRender;
import projectzombie.util.gl.texture.IHasTexture;
import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.gl.texture.TextureReference;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
import projectzombie.util.math.vec.Vec2i; import projectzombie.util.math.vec.Vec2i;
import projectzombie.util.math.vec.Vec3d; import projectzombie.util.math.vec.Vec3d;
public class EntityVertical extends Entity public class EntityVertical extends Entity implements IHasTexture
{ {
private TextureReference tex; public TextureReference tex;
private Vec2d size; public Vec2d size;
public EntityVertical(BdfObject bdf, TextureReference tex, Vec2d size) {
super(bdf);
this.size = size;
this.tex = tex;
}
public EntityVertical(Vec2d pos, TextureReference tex, Vec2d size) { public EntityVertical(Vec2d pos, TextureReference tex, Vec2d size) {
super(pos); super(pos);
@ -37,4 +46,13 @@ public class EntityVertical extends Entity
this.render(pos, camera, tex, size); this.render(pos, camera, tex, size);
GlHelpers.color4(1, 1, 1, 1); GlHelpers.color4(1, 1, 1, 1);
} }
@Override
public TextureReference getTexture() {
return tex;
}
public void killWithParticles() {
ParticleBreak.spawnParticles(chunk, pos, this);
}
} }

138
src/projectzombie/entity/EntityZombie.java Normal file → Executable file
View File

@ -1,27 +1,94 @@
package projectzombie.entity; package projectzombie.entity;
import java.util.Random;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.gl.texture.TextureReference;
import projectzombie.util.math.astar.AStar;
import projectzombie.util.math.astar.AStarSearcher;
import projectzombie.util.math.random.OpenSimplexNoise; import projectzombie.util.math.random.OpenSimplexNoise;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
import projectzombie.util.math.vec.Vec2i;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
public class EntityZombie extends EntityVertical implements EntityAlive public class EntityZombie extends EntityVertical implements EntityAlive, EntityKillWithParticles
{ {
protected OpenSimplexNoise noise_movement; protected OpenSimplexNoise noise_movement;
protected OpenSimplexNoise noise_gun_fire; protected OpenSimplexNoise noise_gun_fire;
protected OpenSimplexNoise noise_gun_angle; protected OpenSimplexNoise noise_gun_angle;
protected OpenSimplexNoise noise_target_x; protected OpenSimplexNoise noise_target_x;
protected OpenSimplexNoise noise_target_y; protected OpenSimplexNoise noise_target_y;
protected long seed;
protected double time; protected double time;
protected double health_max = 100; protected double health_max = 100;
protected double health = health_max; protected double health = health_max;
protected int gun_interval = 0; protected int gun_interval = 0;
protected int gun_level = 0; protected int gun_level = 0;
private Vec2i walk_direction;
private int walk_scan_cooldown = 0;
private boolean can_see_player = false;
private int walking_for = 0;
private static final Vec2d size = new Vec2d(1, 1);
public EntityZombie(BdfObject bdf) {
super(bdf, Textures.ENTITY_ZOMBIE_F, size);
// Set some settings
hitbox = 0.5;
isSolid = true;
goThroughSolid = false;
crossUnWalkable = false;
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
health_max = nl.get("max_health").getDouble();
health = nl.get("health").getDouble();
gun_interval = nl.get("gun_interval").getInteger();
gun_level = nl.get("gun_level").getInteger();
seed = nl.get("seed").getLong();
Random rand = new Random(seed);
noise_movement = new OpenSimplexNoise(rand.nextLong());
noise_gun_fire = new OpenSimplexNoise(rand.nextLong());
noise_gun_angle = new OpenSimplexNoise(rand.nextLong());
noise_target_x = new OpenSimplexNoise(rand.nextLong());
noise_target_y = new OpenSimplexNoise(rand.nextLong());
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("max_health", BdfObject.withDouble(health_max));
nl.set("health", BdfObject.withDouble(health));
nl.set("gun_interval", BdfObject.withInteger(gun_interval));
nl.set("gun_level", BdfObject.withInteger(gun_level));
nl.set("seed", BdfObject.withLong(seed));
}
public EntityZombie(Vec2d pos) { public EntityZombie(Vec2d pos) {
super(pos, Textures.ENTITY_ZOMBIE, new Vec2d(1, 1)); super(pos, Textures.ENTITY_ZOMBIE_F, size);
seed = rand.nextLong();
Random rand = new Random(seed);
noise_movement = new OpenSimplexNoise(rand.nextLong()); noise_movement = new OpenSimplexNoise(rand.nextLong());
noise_gun_fire = new OpenSimplexNoise(rand.nextLong()); noise_gun_fire = new OpenSimplexNoise(rand.nextLong());
noise_gun_angle = new OpenSimplexNoise(rand.nextLong()); noise_gun_angle = new OpenSimplexNoise(rand.nextLong());
@ -40,21 +107,48 @@ public class EntityZombie extends EntityVertical implements EntityAlive
public void tick(Chunk chunk, Layer layer) { public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer); super.tick(chunk, layer);
// Get the player targeted area //System.out.println(walk_direction != null ? (walk_direction.x + ", " + walk_direction.y + ": " + pos.toInt().x + ", " + pos.toInt().y) : "null");
Vec2d target = new Vec2d(
Main.player.pos.x + noise_target_x.eval(time*5, Main.player.pos.x/10, Main.player.pos.y/10)*10,
Main.player.pos.y + noise_target_y.eval(time*5, Main.player.pos.x/10, Main.player.pos.y/10)*10);
// Get the angle between the player and the zombie if(walk_direction == null) {
double angle_walk = Math.atan2(pos.x - target.x, pos.y - target.y); walk_scan_cooldown -= 1;
double angle_fire = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y); }
// Move forward towards the player if(
this.angle = Math.toDegrees(angle_walk) + 180; (walk_direction != null && pos.toInt().equal(walk_direction) &&
this.moveForward(); pos.squareDistance(Main.player.pos) > 2) ||
walk_scan_cooldown < 1 || walking_for > 200)
if(noise_gun_fire.eval(time, 0) > 0 && !Main.player.dead && !Main.player.in_animation)
{ {
AStar astar = new AStar(pos.toInt(), 16, new AStarSearcher(layer, crossUnWalkable));
Vec2i path[] = astar.getPath(Main.player.pos.toInt());
walk_scan_cooldown = 100;
walking_for = 0;
if(path != null && path.length > 1) {
walk_direction = path[1];
} else {
walk_direction = Main.player.pos.toInt();
}
can_see_player = (path != null);
}
// Walk towards the player
if(walk_direction != null)
{
double angle = Math.toDegrees(Math.atan2(
walk_direction.x - (this.pos.x - 0.5) + noise_target_x.eval(time, pos.x/10, pos.y/10),
walk_direction.y - (this.pos.y - 0.5) + noise_target_y.eval(time, pos.x/10, pos.y/10)));
this.moveTowards(angle);
walking_for += 1;
}
if(can_see_player && noise_gun_fire.eval(time, 0) > 0 && !Main.player.dead && !Main.player.in_animation)
{
// Get the angle between the player and the zombie
double angle_fire = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y);
gun_interval += 1; gun_interval += 1;
gun_interval %= 10; gun_interval %= 10;
@ -66,8 +160,7 @@ public class EntityZombie extends EntityVertical implements EntityAlive
// Fire the gun // Fire the gun
int d = (int)(1 + gun_level / 5.0); int d = (int)(1 + gun_level / 5.0);
int b = (int)(1 - gun_level / 5.0); layer.spawnEntity(new EntityBullet(pos.copy(), this, angle_gun, 20*d*d, 60));
layer.spawnEntity(new EntityBullet(pos.copy(), this, angle_gun, 20*d*d, 5*b*b, 60));
} }
} }
@ -76,13 +169,16 @@ public class EntityZombie extends EntityVertical implements EntityAlive
} }
@Override @Override
public void moveForward() { public TextureReference getTexture() {
this.moveForward(0.06); return Textures.ENTITY_ZOMBIE_F;
} }
@Override public void moveInVector(Vec2d vec) {
public void moveBackward() { super.moveInVector(vec, 0.06);
super.moveBackward(0.06); }
public void moveTowards(double angle) {
super.moveTowards(angle, 0.06);
} }
@Override @Override

7
src/projectzombie/entity/EntityZombieArmored.java Normal file → Executable file
View File

@ -1,5 +1,6 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.types.BdfObject;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.gl.texture.TextureReference;
@ -7,7 +8,9 @@ import projectzombie.util.math.vec.Vec2d;
public class EntityZombieArmored extends EntityZombie public class EntityZombieArmored extends EntityZombie
{ {
public EntityZombieArmored(BdfObject bdf) {
super(bdf);
}
public EntityZombieArmored(Vec2d pos) { public EntityZombieArmored(Vec2d pos) {
super(pos); super(pos);
@ -20,7 +23,7 @@ public class EntityZombieArmored extends EntityZombie
@Override @Override
public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) { public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) {
super.render(pos, camera, Textures.ENTITY_ZOMBIE_ARMORED, new Vec2d(1, 1)); super.render(pos, camera, Textures.ENTITY_ZOMBIE_F_ARMORED, size);
} }
@Override @Override

14
src/projectzombie/entity/particle/ParticleBlood.java Normal file → Executable file
View File

@ -4,6 +4,7 @@ import java.util.Random;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.settings.SettingQuality;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.random.RandomHelpers;
@ -19,17 +20,18 @@ public class ParticleBlood extends EntityParticle
private double time = 1000; private double time = 1000;
private double height = 0; private double height = 0;
private Vec3d velocity; private Vec3d velocity;
private double angle_height;
public ParticleBlood(Random rand, Vec2d pos, double angle) { public ParticleBlood(Random rand, Vec2d pos, double angle) {
super(pos, rand.nextDouble() / 5, 0); super(pos, rand.nextDouble() / 5, 0);
this.angle = angle + RandomHelpers.randrange(rand, -100, 100); angle += RandomHelpers.randrange(rand, -100, 100);
this.angle_height = RandomHelpers.randrange(rand, 9000, 18000) / 100; double angle_height = RandomHelpers.randrange(rand, 9000, 18000) / 100;
this.height = rand.nextDouble(); this.height = rand.nextDouble();
r_color = RandomHelpers.randrange(rand, 200, 800) / 1000.0; r_color = RandomHelpers.randrange(rand, 200, 800) / 1000.0;
velocity = MathHelpers.moveTowards3(0.1, velocity = MathHelpers.moveTowards3(0.1,
new Vec2d(Math.toRadians(this.angle), Math.toRadians(angle_height))); new Vec2d(Math.toRadians(angle), Math.toRadians(angle_height)));
time = RandomHelpers.randrange(rand, 800, 1200);
} }
@Override @Override
@ -55,6 +57,10 @@ public class ParticleBlood extends EntityParticle
// Should this particle too old; destroy it // Should this particle too old; destroy it
if(time < 0) chunk.killEntity(this); if(time < 0) chunk.killEntity(this);
if(MODE == SettingQuality.OFF) {
kill();
}
} }
@Override @Override

128
src/projectzombie/entity/particle/ParticleBreak.java Normal file → Executable file
View File

@ -2,8 +2,13 @@ package projectzombie.entity.particle;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.Entity;
import projectzombie.entity.EntityParticle;
import projectzombie.entity.EntityVertical; import projectzombie.entity.EntityVertical;
import projectzombie.settings.SettingQuality;
import projectzombie.tiles.TileVertical;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.gl.texture.AnimationReference;
import projectzombie.util.gl.texture.IHasTexture; import projectzombie.util.gl.texture.IHasTexture;
import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.gl.texture.TextureReference;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
@ -19,13 +24,73 @@ public class ParticleBreak extends EntityVertical
{ {
private double height = 0; private double height = 0;
private Vec3d velocity; private Vec3d velocity;
private int time = 1000; private int time = 0;
private boolean landed = false;
public static void spawnParticles(Chunk chunk, Vec2d pos, Entity e)
{
if(EntityParticle.MODE == SettingQuality.OFF) {
return;
}
int height = 1;
if(e instanceof EntityVertical) {
height = MathHelpers.floor(((EntityVertical)e).size.y);
}
for(int i=0;i<50 * height;i++) {
chunk.spawnEntity(new ParticleBreak(pos.copy(), e));
}
}
public static void spawnParticles(Chunk chunk, Vec2d pos, TileState s)
{
if(EntityParticle.MODE == SettingQuality.OFF) {
return;
}
int height = 1;
if(s.tile instanceof TileVertical) {
height = MathHelpers.floor(((TileVertical)s.tile).size.y);
}
for(int i=0;i<50 * height;i++) {
chunk.spawnEntity(new ParticleBreak(pos.copy(), s));
}
}
private static TextureReference getTexture(TileState ts) private static TextureReference getTexture(TileState ts)
{ {
if(ts.tile instanceof IHasTexture) if(ts.tile instanceof IHasTexture)
{ {
TextureReference tex = ((IHasTexture)ts.tile).getTexture(); TextureReference tex = ((IHasTexture)ts.tile).getTexture();
if(tex instanceof AnimationReference) {
tex = ((AnimationReference)tex).c;
}
int px = RandomHelpers.randrange(rand, tex.start_x, tex.end_x - 2);
int py = RandomHelpers.randrange(rand, tex.start_y, tex.end_y - 2);
return tex.getTextureReference(px, px + 2, py, py + 2);
}
else {
return TextureReference.EMPTY;
}
}
private static TextureReference getTexture(Entity entity)
{
if(entity instanceof IHasTexture)
{
TextureReference tex = ((IHasTexture)entity).getTexture();
if(tex instanceof AnimationReference) {
tex = ((AnimationReference)tex).c;
}
int px = RandomHelpers.randrange(rand, tex.start_x, tex.end_x - 2); int px = RandomHelpers.randrange(rand, tex.start_x, tex.end_x - 2);
int py = RandomHelpers.randrange(rand, tex.start_y, tex.end_y - 2); int py = RandomHelpers.randrange(rand, tex.start_y, tex.end_y - 2);
return tex.getTextureReference(px, px + 2, py, py + 2); return tex.getTextureReference(px, px + 2, py, py + 2);
@ -37,14 +102,51 @@ public class ParticleBreak extends EntityVertical
} }
public ParticleBreak(Vec2d pos, TileState ts) { public ParticleBreak(Vec2d pos, TileState ts) {
super(pos, getTexture(ts), new Vec2d(1/4.0, 1/4.0)); super(pos, getTexture(ts), new Vec2d(1/8.0, 1/8.0));
this.opaqueTile = ts.tile.opaqueTile; double angle = RandomHelpers.randrange(rand, 360);
this.angle = RandomHelpers.randrange(rand, 360);
if(EntityParticle.MODE == SettingQuality.FANCY) {
this.opaqueTile = ts.tile.opaqueTile;
} else {
this.opaqueTile = false;
}
if(ts.tile instanceof TileVertical) {
TileVertical ts_v = (TileVertical) ts.tile;
height = RandomHelpers.randrange(rand, 0, MathHelpers.floor(ts_v.size.y));
}
Vec2d side_v = MathHelpers.moveTowards2(0.01, Math.toRadians(angle)); Vec2d side_v = MathHelpers.moveTowards2(0.01, Math.toRadians(angle));
velocity = new Vec3d( velocity = new Vec3d(
side_v.x, side_v.y, side_v.x, side_v.y,
RandomHelpers.randrange(rand, 10000) / 200000.0); RandomHelpers.randrange(rand, 10000) / 200000.0);
time = RandomHelpers.randrange(rand, 800, 1200);
}
public ParticleBreak(Vec2d pos, Entity entity) {
super(pos, getTexture(entity), new Vec2d(1/8.0, 1/8.0));
double angle = RandomHelpers.randrange(rand, 360);
if(EntityParticle.MODE == SettingQuality.FANCY) {
this.opaqueTile = entity.opaqueTile;
} else {
this.opaqueTile = false;
}
if(entity instanceof EntityVertical) {
EntityVertical entity_v = (EntityVertical) entity;
height = RandomHelpers.randrange(rand, 0, MathHelpers.floor(entity_v.size.y));
}
Vec2d side_v = MathHelpers.moveTowards2(0.01, Math.toRadians(angle));
velocity = new Vec3d(
side_v.x, side_v.y,
RandomHelpers.randrange(rand, 10000) / 200000.0);
time = RandomHelpers.randrange(rand, 500, 1500);
} }
@Override @Override
@ -58,10 +160,18 @@ public class ParticleBreak extends EntityVertical
time -= 1; time -= 1;
height += velocity.z; if(!landed) {
velocity.z -= MathHelpers.FallSpeed; height += velocity.z;
velocity.z -= MathHelpers.FallSpeed;
}
if(height < -1) { if(height < 0) {
height = 0;
velocity = velocity.multiply(0);
landed = true;
}
if(time < 0) {
kill(); kill();
} }
@ -69,6 +179,10 @@ public class ParticleBreak extends EntityVertical
pos.x += velocity.x; pos.x += velocity.x;
pos.y += velocity.y; pos.y += velocity.y;
} }
if(EntityParticle.MODE == SettingQuality.OFF) {
kill();
}
} }
@Override @Override

5
src/projectzombie/entity/particle/ParticleLava.java Normal file → Executable file
View File

@ -4,6 +4,7 @@ import java.util.Random;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.settings.SettingQuality;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.random.RandomHelpers;
@ -40,6 +41,10 @@ public class ParticleLava extends EntityParticle
if(height < -1) { if(height < -1) {
kill(); kill();
} }
if(MODE == SettingQuality.OFF) {
kill();
}
} }
@Override @Override

6
src/projectzombie/entity/particle/ParticleSmoke.java Normal file → Executable file
View File

@ -2,8 +2,10 @@ package projectzombie.entity.particle;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.EntityParticle;
import projectzombie.entity.EntityVertical; import projectzombie.entity.EntityVertical;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.settings.SettingQuality;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.random.RandomHelpers;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
@ -48,6 +50,10 @@ public class ParticleSmoke extends EntityVertical
height += height_speed; height += height_speed;
opacity -= disappear_speed; opacity -= disappear_speed;
if(EntityParticle.MODE == SettingQuality.OFF) {
kill();
}
} }
} }

5
src/projectzombie/entity/particle/ParticleSpark.java Normal file → Executable file
View File

@ -2,6 +2,7 @@ package projectzombie.entity.particle;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.settings.SettingQuality;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
@ -30,6 +31,10 @@ public class ParticleSpark extends EntityParticle
// Destroy this particle // Destroy this particle
kill(); kill();
} }
if(MODE == SettingQuality.OFF) {
kill();
}
} }
@Override @Override

11
src/projectzombie/entity/particle/ParticleWater.java Normal file → Executable file
View File

@ -2,6 +2,7 @@ package projectzombie.entity.particle;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.settings.SettingQuality;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.random.RandomHelpers;
@ -20,7 +21,7 @@ public class ParticleWater extends EntityParticle
super(pos, rand.nextDouble()/5, 0); super(pos, rand.nextDouble()/5, 0);
// Set the velocity // Set the velocity
velocity = MathHelpers.moveTowards3(0.1, new Vec2d(Math.toRadians( velocity = MathHelpers.moveTowards3(0.05, new Vec2d(Math.toRadians(
RandomHelpers.randrange(rand, 360)), Math.toRadians(RandomHelpers.randrange(rand, 0, 45)))); RandomHelpers.randrange(rand, 360)), Math.toRadians(RandomHelpers.randrange(rand, 0, 45))));
} }
@ -38,6 +39,10 @@ public class ParticleWater extends EntityParticle
if(height < 0) { if(height < 0) {
kill(); kill();
} }
if(MODE == SettingQuality.OFF) {
kill();
}
} }
@Override @Override
@ -46,9 +51,9 @@ public class ParticleWater extends EntityParticle
GlHelpers.translate3(0, 0, height); GlHelpers.translate3(0, 0, height);
Vec3d light = chunk.getRGBLightLevel(new Vec2i( Vec3d light = chunk.getRGBLightLevel(new Vec2i(
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
GlHelpers.color4(0, 0, light.z, 0.4); GlHelpers.color3(light.x * 0.2, light.y * 0.2, light.z * 0.6);
super.render(pos, camera); super.render(pos, camera);
GlHelpers.color4(1, 1, 1, 1); GlHelpers.color3(1, 1, 1);
GlHelpers.popMatrix(); GlHelpers.popMatrix();
} }

128
src/projectzombie/entity/player/EntityPlayer.java Normal file → Executable file
View File

@ -1,15 +1,22 @@
package projectzombie.entity.player; package projectzombie.entity.player;
import java.io.FileOutputStream;
import java.util.zip.DeflaterOutputStream;
import bdf.types.BdfIndent;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import mainloop.task.IMainloopTask; import mainloop.task.IMainloopTask;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.Entity;
import projectzombie.entity.EntityAlive; import projectzombie.entity.EntityAlive;
import projectzombie.entity.EntityBullet; import projectzombie.entity.EntityBullet;
import projectzombie.entity.EntityHeight; import projectzombie.entity.EntityHeight;
import projectzombie.entity.EntityInventory; import projectzombie.entity.EntityInventory;
import projectzombie.entity.EntityItem; import projectzombie.entity.EntityItem;
import projectzombie.entity.EntityVertical; import projectzombie.entity.EntityVertical;
import projectzombie.entity.particle.ParticleBreak;
import projectzombie.init.Items;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.inventory.Inventory; import projectzombie.inventory.Inventory;
import projectzombie.menu.MenuDeath; import projectzombie.menu.MenuDeath;
@ -20,7 +27,10 @@ import projectzombie.util.math.ItemStack;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
import projectzombie.util.math.vec.Vec2i; import projectzombie.util.math.vec.Vec2i;
import projectzombie.util.math.vec.Vec3d;
import projectzombie.world.World;
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 class EntityPlayer extends EntityVertical implements EntityAlive, EntityInventory, EntityHeight public class EntityPlayer extends EntityVertical implements EntityAlive, EntityInventory, EntityHeight
@ -32,6 +42,9 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
public boolean GUN = false; public boolean GUN = false;
public boolean moving = false; public boolean moving = false;
public TextureReference PLAYER_MOVING = Textures.ENTITY_PLAYER_B_W_MOVING;
public TextureReference PLAYER_STILL = Textures.ENTITY_PLAYER_B_W_STILL;
public double height = 0; public double height = 0;
private int bullet_frequency = 0; private int bullet_frequency = 0;
@ -48,8 +61,45 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
public int defence_level = 0; public int defence_level = 0;
public int gun_level = 0; public int gun_level = 0;
public double angle;
public double speed;
private static final Vec2d size = new Vec2d(1, 1); private static final Vec2d size = new Vec2d(1, 1);
public EntityPlayer(BdfObject bdf) {
super(bdf, TextureReference.EMPTY, size);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
height = nl.get("height").getDouble();
bullet_frequency = nl.get("bullet_frequency").getInteger();
health = nl.get("health").getDouble();
dead = nl.get("dead").getBoolean();
inventory = new Inventory(nl.get("inventory"));
ammo = nl.get("ammo").getInteger();
defence_level = nl.get("defence_level").getInteger();
gun_level = nl.get("gun_level").getInteger();
angle = nl.get("angle").getDouble();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("height", BdfObject.withDouble(height));
nl.set("bullet_frequency", BdfObject.withInteger(bullet_frequency));
nl.set("health", BdfObject.withDouble(health));
nl.set("dead", BdfObject.withBoolean(dead));
inventory.BdfClassSave(nl.get("inventory"));
nl.set("ammo", BdfObject.withInteger(ammo));
nl.set("defence_level", BdfObject.withInteger(defence_level));
nl.set("gun_level", BdfObject.withInteger(gun_level));
nl.set("angle", BdfObject.withDouble(angle));
}
public EntityPlayer() { public EntityPlayer() {
super(new Vec2d(0, 0), TextureReference.EMPTY, size); super(new Vec2d(0, 0), TextureReference.EMPTY, size);
@ -61,24 +111,48 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
goThroughSolid = false; goThroughSolid = false;
crossUnWalkable = false; crossUnWalkable = false;
emitsLight = true; emitsLight = true;
speed = 0.1;
// Create the inventory // Create the inventory
inventory = new Inventory(6); inventory = new Inventory(6);
inventory.setItem(new ItemStack(Items.LANTERN, 99, (byte)0), 2);
inventory.setItem(new ItemStack(Items.SPAWN_ZOMBIE, 99, (byte)0), 3);
} }
@Override @Override
public double getLightLevel() { public double getLightLevel()
return 1; {
if(Main.menu.playerEmitsLight) {
return getLightWithHeight(1);
}
ItemStack item = inventory.getItem(inventory_hand);
if(!item.isEmpty()) {
return getLightWithHeight(item.item.getLightLevel());
}
return 0;
}
@Override
public TextureReference getTexture() {
return PLAYER_STILL;
} }
@Override @Override
public void tick(Chunk chunk, Layer layer) public void tick(Chunk chunk, Layer layer)
{ {
chunk = layer.getChunk(pos);
if(dead) return; if(dead) return;
// Handle player deaths // Handle player deaths
if(health <= 0) if(health <= 0)
{ {
ParticleBreak.spawnParticles(chunk, pos, this);
if(Cheats.god_mode) { if(Cheats.god_mode) {
this.resetHealth(); this.resetHealth();
} }
@ -105,6 +179,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
} }
}); });
} }
return;
} }
// Is the player dead or in an animation // Is the player dead or in an animation
@ -116,23 +192,23 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
// Rotate left // Rotate left
if(MOVE_LEFT) { if(MOVE_LEFT) {
this.angle -= 1; this.angle -= 1;
this.angle = MathHelpers.mod(this.angle, 360);
} }
// Rotate right // Rotate right
if(MOVE_RIGHT) { if(MOVE_RIGHT) {
this.angle += 1; this.angle += 1;
this.angle = MathHelpers.mod(this.angle, 360);
} }
this.angle = MathHelpers.mod(this.angle, 360);
// Move forward // Move forward
if(MOVE_FORWARD) { if(MOVE_FORWARD) {
this.moveForward(); this.moveTowards(this.angle);
} }
// Move backward // Move backward
if(MOVE_BACKWARD) { if(MOVE_BACKWARD) {
this.moveBackward(); this.moveTowards(this.angle + 180);
} }
// Use the gun // Use the gun
@ -145,9 +221,13 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
public void kill() public void kill()
{ {
// Is god mode inactive; kill the player // Is god mode inactive; kill the player
if(!Cheats.god_mode) { if(Cheats.god_mode) {
dead = true; return;
} }
ParticleBreak.spawnParticles(chunk, pos, this);
dead = true;
} }
@Override @Override
@ -156,14 +236,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
super.moveTowards(angle, speed); super.moveTowards(angle, speed);
} }
@Override public void moveTowards(double angle) {
public void moveForward() { this.moveTowards(angle, 0.08);
this.moveForward(0.08);
}
@Override
public void moveBackward(double speed) {
super.moveBackward(0.08);
} }
@Override @Override
@ -172,21 +246,26 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
// Don't render if the player is dead // Don't render if the player is dead
if(dead) return; if(dead) return;
// Don't render if the chunk isnt loaded
if(!ChunkEventHandler.loaded) {
return;
}
// Translation // Translation
GlHelpers.pushMatrix(); GlHelpers.pushMatrix();
GlHelpers.translate3(0, 0, height); GlHelpers.translate3(0, 0, height);
// Set the colour due to the lighting // Set the colour due to the lighting
double light = chunk.getDynamicLightLevel(new Vec2i( Vec3d light = chunk.getRGBLightLevel(new Vec2i(
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
GlHelpers.color3(light, light, light); GlHelpers.color3(light.x, light.y, light.z);
// Moving // Moving
if(MOVE_BACKWARD || MOVE_FORWARD || moving) if(MOVE_BACKWARD || MOVE_FORWARD || moving)
super.render(pos, camera, Textures.ENTITY_PLAYER_MOVING, size); super.render(pos, camera, PLAYER_MOVING, size);
// Standing still // Standing still
else super.render(pos, camera, Textures.ENTITY_PLAYER_STILL, size); else super.render(pos, camera, PLAYER_STILL, size);
// Pop the matrix // Pop the matrix
GlHelpers.popMatrix(); GlHelpers.popMatrix();
@ -207,9 +286,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
// Summon bullets at this angle relative to the player // Summon bullets at this angle relative to the player
int d = (int)(1 + gun_level / 4.0); int d = (int)(1 + gun_level / 4.0);
int b = (int)(1 + gun_level / 4.0);
Main.world.getLayer().spawnEntity(new EntityBullet(pos.copy(), this, angle + this.angle, Main.world.getLayer().spawnEntity(new EntityBullet(pos.copy(), this, angle + this.angle,
20*d*d, 5/b, 60).withHeight(0, height)); 20*d*d, 60).withHeight(0, height));
} }
} }
@ -219,7 +297,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
ItemStack is = inventory.getItem(inventory_hand); ItemStack is = inventory.getItem(inventory_hand);
if(!is.isEmpty()) { if(!is.isEmpty()) {
is.item.onAction(is, Main.world.getLayer(), chunk, this); is.item.onPlayerAction(is, Main.world.getLayer(), chunk, this);
} }
} }
@ -271,7 +349,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
if(!i.isEmpty()) if(!i.isEmpty())
{ {
Entity e = new EntityItem(pos.copy(), new ItemStack(i.item, 1, i.meta)); EntityItem e = new EntityItem(pos.copy(), new ItemStack(i.item, 1, i.meta));
e.angle = angle; e.angle = angle;
Main.world.getLayer().spawnEntity(e); Main.world.getLayer().spawnEntity(e);
i.count -= 1; i.count -= 1;

41
src/projectzombie/init/Entities.java Normal file → Executable file
View File

@ -2,9 +2,48 @@ package projectzombie.init;
import java.util.ArrayList; import java.util.ArrayList;
import bdf.types.BdfObject;
import projectzombie.entity.Entity; import projectzombie.entity.Entity;
import projectzombie.entity.EntityBoss;
import projectzombie.entity.EntityBullet;
import projectzombie.entity.EntityDummy;
import projectzombie.entity.EntityExplosion;
import projectzombie.entity.EntityFlare;
import projectzombie.entity.EntityGrapplingHook;
import projectzombie.entity.EntityItem;
import projectzombie.entity.EntityTnt;
import projectzombie.entity.EntityZombie;
import projectzombie.entity.EntityZombieArmored;
import projectzombie.entity.player.EntityPlayer;
public class Entities public class Entities
{ {
public static final ArrayList<Entity> entities = new ArrayList<Entity>(); public static final ArrayList<Class<? extends Entity>> entities = new ArrayList<>();
private static void register(Class<? extends Entity> e)
{
try {
e.getConstructor(BdfObject.class);
} catch (NoSuchMethodException | SecurityException err) {
err.printStackTrace();
System.exit(1);
}
entities.add(e);
}
public static void init()
{
register(EntityZombie.class);
register(EntityZombieArmored.class);
register(EntityTnt.class);
register(EntityItem.class);
register(EntityGrapplingHook.class);
register(EntityFlare.class);
register(EntityExplosion.class);
register(EntityDummy.class);
register(EntityBullet.class);
register(EntityBoss.class);
register(EntityPlayer.class);
}
} }

52
src/projectzombie/init/Items.java Normal file → Executable file
View File

@ -1,5 +1,7 @@
package projectzombie.init; package projectzombie.init;
import java.util.ArrayList;
import projectzombie.items.Item; import projectzombie.items.Item;
import projectzombie.items.ItemAmmo; import projectzombie.items.ItemAmmo;
import projectzombie.items.ItemDefenceUpgrade; import projectzombie.items.ItemDefenceUpgrade;
@ -9,17 +11,49 @@ import projectzombie.items.ItemGrapplingHook;
import projectzombie.items.ItemGunUpgrade; import projectzombie.items.ItemGunUpgrade;
import projectzombie.items.ItemHealthPotion; import projectzombie.items.ItemHealthPotion;
import projectzombie.items.ItemLantern; import projectzombie.items.ItemLantern;
import projectzombie.items.ItemRock;
import projectzombie.items.ItemTnt; import projectzombie.items.ItemTnt;
import projectzombie.items.spawner.ItemSpawnZombie;
public class Items public class Items
{ {
public static final Item AMMO = new ItemAmmo("ammo"); public static ArrayList<Item> items = new ArrayList<Item>();
public static final Item DEFENCE_UPGRADE = new ItemDefenceUpgrade("defence_upgrade");
public static final Item GUN_UPGRADE = new ItemGunUpgrade("gun_upgrade"); private static void register(Item item) {
public static final Item HEALTH_POTION = new ItemHealthPotion("health_potion"); item.id = items.size();
public static final Item EMPTY = new ItemEmpty("empty"); items.add(item);
public static final Item TNT = new ItemTnt("tnt"); }
public static final Item LANTERN = new ItemLantern("lantern");
public static final Item FLARE = new ItemFlare("flare"); public static void init()
public static final Item GRAPPLING_HOOK = new ItemGrapplingHook("grappling_hook"); {
register(EMPTY);
register(AMMO);
register(DEFENCE_UPGRADE);
register(GUN_UPGRADE);
register(HEALTH_POTION);
register(TNT);
register(LANTERN);
register(FLARE);
register(GRAPPLING_HOOK);
register(SPAWN_ZOMBIE);
register(ROCK);
register(AMMO);
}
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 EMPTY = new ItemEmpty();
public static final Item TNT = new ItemTnt();
public static final Item LANTERN = new ItemLantern();
public static final Item FLARE = new ItemFlare();
public static final Item GRAPPLING_HOOK = new ItemGrapplingHook();
public static final Item SPAWN_ZOMBIE = new ItemSpawnZombie();
public static final Item ROCK = new ItemRock();
} }

View File

@ -0,0 +1,46 @@
package projectzombie.init;
import java.util.ArrayList;
import projectzombie.world.layer.layergen.LayerGen;
import projectzombie.world.layer.layergen.LayerGenBossArena;
import projectzombie.world.layer.layergen.LayerGenCaves;
import projectzombie.world.layer.layergen.LayerGenEarth;
import projectzombie.world.layer.layergen.LayerGenLavaCaves;
public class LayerGenerators
{
private static final ArrayList<LayerGen> lgens = new ArrayList<LayerGen>();
private static void register(LayerGen lg) {
lg.id = lgens.size();
lgens.add(lg);
}
public static void init()
{
register(EARTH);
register(CAVES);
register(LAVA_CAVES);
register(BOSS_ARENA);
}
public static LayerGen loadFromID(int id) {
return lgens.get(id);
}
public static int getLGID(LayerGen lg) {
for(int i=0;i<lgens.size();i++) {
LayerGen lgi = lgens.get(i);
if(lgi == lg) {
return i;
}
}
return -1;
}
public static final LayerGen EARTH = new LayerGenEarth();
public static final LayerGen CAVES = new LayerGenCaves();
public static final LayerGen LAVA_CAVES = new LayerGenLavaCaves();
public static final LayerGen BOSS_ARENA = new LayerGenBossArena();
}

27
src/projectzombie/init/Layers.java Normal file → Executable file
View File

@ -1,39 +1,26 @@
package projectzombie.init; package projectzombie.init;
import java.util.ArrayList;
import java.util.Random; 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.LayerGenCaves;
import projectzombie.world.layer.layergen.LayerGenEarth;
import projectzombie.world.layer.layergen.LayerGenLavaCaves;
public class Layers public class Layers
{ {
private static ArrayList<Layer> id_layers = new ArrayList<Layer>();
public static void init(long seed) public static void init(long seed)
{ {
// Create all the layers // Create all the layers
EARTH = new Layer(new Random(seed), new LayerGenEarth(), 0); EARTH = new Layer(new Random(seed), LayerGenerators.EARTH);
CAVES = new Layer(new Random(seed), new LayerGenCaves(), 1); CAVES = new Layer(new Random(seed), LayerGenerators.CAVES);
LAVA_CAVES = new Layer(new Random(seed), new LayerGenLavaCaves(), 2); LAVA_CAVES = new Layer(new Random(seed), LayerGenerators.LAVA_CAVES);
// Setup all the id-able layers
id_layers = new ArrayList<Layer>();
id_layers.add(EARTH);
id_layers.add(CAVES);
id_layers.add(LAVA_CAVES);
// Create the world and set the earth as the default layer // Create the world and set the earth as the default layer
Main.world = new World(); Main.world = new World();
Main.world.setLayer(EARTH); Main.world.addLayer(EARTH);
} Main.world.addLayer(CAVES);
Main.world.addLayer(LAVA_CAVES);
public static Layer getLayer(int id) { Main.world.setLayer(0);
return id_layers.get(id);
} }
public static Layer EARTH; public static Layer EARTH;

0
src/projectzombie/init/Resources.java Normal file → Executable file
View File

0
src/projectzombie/init/Sounds.java Normal file → Executable file
View File

81
src/projectzombie/init/Textures.java Normal file → Executable file
View File

@ -97,37 +97,70 @@ public class Textures
public static final TextureReference ITEM_GUN_UPGRADE = texmap.getTextureReference(0, 1, 4, 5); public static final TextureReference ITEM_GUN_UPGRADE = texmap.getTextureReference(0, 1, 4, 5);
public static final TextureReference ITEM_DEFENCE_UPGRADE = texmap.getTextureReference(1, 2, 4, 5); public static final TextureReference ITEM_DEFENCE_UPGRADE = texmap.getTextureReference(1, 2, 4, 5);
// Fire public static final TextureReference ITEM_ROCK = texmap.getTextureReference(0, 1, 3, 4);
public static final TextureReference TILE_FIRE_0 = texmap.getTextureReference(0, 1, 1, 2);
public static final TextureReference TILE_FIRE_1 = texmap.getTextureReference(1, 2, 1, 2);
public static final TextureReference TILE_FIRE_2 = texmap.getTextureReference(2, 3, 1, 2);
public static final TextureReference TILE_FIRE_3 = texmap.getTextureReference(3, 4, 1, 2);
public static final TextureReference TILE_FIRE = new AnimationReference(
8, TILE_FIRE_0, TILE_FIRE_1, TILE_FIRE_2, TILE_FIRE_3);
// Player // Player Back White Varient
public static final TextureReference ENTITY_PLAYER_STILL = texmap.getTextureReference(0, 1, 2, 3); public static final TextureReference ENTITY_PLAYER_B_W_STILL = texmap.getTextureReference(28, 29, 0, 1);
public static final TextureReference ENTITY_PLAYER_MOVING = new AnimationReference(10, public static final TextureReference ENTITY_PLAYER_B_W_MOVING = new AnimationReference(10,
texmap.getTextureReference(0, 1, 2, 3), texmap.getTextureReference(28, 29, 0, 1),
texmap.getTextureReference(1, 2, 2, 3), texmap.getTextureReference(29, 30, 0, 1),
texmap.getTextureReference(2, 3, 2, 3), texmap.getTextureReference(30, 31, 0, 1),
texmap.getTextureReference(3, 4, 2, 3) texmap.getTextureReference(31, 32, 0, 1)
);
// Player Front White Varient
public static final TextureReference ENTITY_PLAYER_F_W_STILL = texmap.getTextureReference(28, 29, 1, 2);
public static final TextureReference ENTITY_PLAYER_F_W_MOVING = new AnimationReference(10,
texmap.getTextureReference(28, 29, 1, 2),
texmap.getTextureReference(29, 30, 1, 2),
texmap.getTextureReference(30, 31, 1, 2),
texmap.getTextureReference(31, 32, 1, 2)
);
// Player Back Black Varient
public static final TextureReference ENTITY_PLAYER_B_B_STILL = texmap.getTextureReference(28, 29, 2, 3);
public static final TextureReference ENTITY_PLAYER_B_B_MOVING = new AnimationReference(10,
texmap.getTextureReference(28, 29, 2, 3),
texmap.getTextureReference(29, 30, 2, 3),
texmap.getTextureReference(30, 31, 2, 3),
texmap.getTextureReference(31, 32, 2, 3)
);
// Player Front Black Varient
public static final TextureReference ENTITY_PLAYER_F_B_STILL = texmap.getTextureReference(28, 29, 3, 4);
public static final TextureReference ENTITY_PLAYER_F_B_MOVING = new AnimationReference(10,
texmap.getTextureReference(28, 29, 3, 4),
texmap.getTextureReference(29, 30, 3, 4),
texmap.getTextureReference(30, 31, 3, 4),
texmap.getTextureReference(31, 32, 3, 4)
); );
// Zombie // Zombie
public static final TextureReference ENTITY_ZOMBIE = new AnimationReference(10, public static final TextureReference ENTITY_ZOMBIE_B = new AnimationReference(10,
texmap.getTextureReference(0, 1, 3, 4), texmap.getTextureReference(28, 29, 4, 5),
texmap.getTextureReference(1, 2, 3, 4), texmap.getTextureReference(29, 30, 4, 5),
texmap.getTextureReference(2, 3, 3, 4), texmap.getTextureReference(30, 31, 4, 5),
texmap.getTextureReference(3, 4, 3, 4) texmap.getTextureReference(31, 32, 4, 5)
);
public static final TextureReference ENTITY_ZOMBIE_F = new AnimationReference(10,
texmap.getTextureReference(28, 29, 5, 6),
texmap.getTextureReference(29, 30, 5, 6),
texmap.getTextureReference(30, 31, 5, 6),
texmap.getTextureReference(31, 32, 5, 6)
); );
// Zombie Bomber // Zombie Bomber
public static final TextureReference ENTITY_ZOMBIE_ARMORED = new AnimationReference(10, public static final TextureReference ENTITY_ZOMBIE_B_ARMORED = new AnimationReference(10,
texmap.getTextureReference(2, 3, 15, 16), texmap.getTextureReference(28, 29, 6, 7),
texmap.getTextureReference(3, 4, 15, 16), texmap.getTextureReference(29, 30, 6, 7),
texmap.getTextureReference(4, 5, 15, 16), texmap.getTextureReference(30, 31, 6, 7),
texmap.getTextureReference(5, 6, 15, 16) texmap.getTextureReference(31, 32, 6, 7)
);
public static final TextureReference ENTITY_ZOMBIE_F_ARMORED = new AnimationReference(10,
texmap.getTextureReference(28, 29, 7, 8),
texmap.getTextureReference(29, 30, 7, 8),
texmap.getTextureReference(30, 31, 7, 8),
texmap.getTextureReference(31, 32, 7, 8)
); );
// Water // Water

78
src/projectzombie/init/Tiles.java Normal file → Executable file
View File

@ -1,10 +1,11 @@
package projectzombie.init; package projectzombie.init;
import java.util.ArrayList;
import projectzombie.tiles.Tile; import projectzombie.tiles.Tile;
import projectzombie.tiles.TileBossPortal; import projectzombie.tiles.TileBossPortal;
import projectzombie.tiles.TileChest; import projectzombie.tiles.TileChest;
import projectzombie.tiles.TileDirt; import projectzombie.tiles.TileDirt;
import projectzombie.tiles.TileFire;
import projectzombie.tiles.TileGrass; import projectzombie.tiles.TileGrass;
import projectzombie.tiles.TileLadder; import projectzombie.tiles.TileLadder;
import projectzombie.tiles.TileLadderUp; import projectzombie.tiles.TileLadderUp;
@ -24,24 +25,59 @@ import projectzombie.tiles.TileWaterFlow;
public class Tiles public class Tiles
{ {
public static final Tile GRASS = new TileGrass("grass"); public static ArrayList<Tile> tiles = new ArrayList<Tile>();
public static final Tile FIRE = new TileFire("fire");
public static final Tile SAND = new TileSand("sand"); private static void register(Tile tile)
public static final Tile STONE = new TileStone("stone"); {
public static final Tile DIRT = new TileDirt("dirt"); int id = tiles.size();
public static final Tile TREE = new TileTree("tree");
public static final Tile VOID = new TileVoid("void"); if(id > Short.MAX_VALUE) {
public static final Tile ROCK = new TileRock("rock"); throw new RuntimeException("Too many tiles registered. Maximum tiles: " + Short.MAX_VALUE);
public static final Tile LAVA = new TileLava("lava"); }
public static final Tile WATER = new TileWater("water");
public static final Tile LAVA_FLOW = new TileLavaFlow("lava_flow"); tile.id = (short)id;
public static final Tile WATER_FLOW = new TileWaterFlow("water_flow"); tiles.add(tile);
public static final Tile LADDER = new TileLadder("ladder"); }
public static final Tile PORTAL_DOWN = new TilePortalDown("portal_down");
public static final Tile WALL = new TileWall("wall"); public static void init() {
public static final Tile LADDER_UP = new TileLadderUp("ladder_up"); register(VOID);
public static final Tile CHEST = new TileChest("chest"); register(GRASS);
public static final Tile LANTERN = new TileLantern("lantern"); register(SAND);
public static final Tile WALL_UNBREAKABLE = new TileWallUnbreakable("wall_unbreakable"); register(STONE);
public static final Tile BOSS_PORTAL = new TileBossPortal("boss_portal"); register(DIRT);
register(TREE);
register(ROCK);
register(LAVA);
register(WATER);
register(LAVA_FLOW);
register(WATER_FLOW);
register(LADDER);
register(PORTAL_DOWN);
register(WALL);
register(LADDER_UP);
register(CHEST);
register(LANTERN);
register(WALL_UNBREAKABLE);
register(BOSS_PORTAL);
}
public static final Tile GRASS = new TileGrass();
public static final Tile SAND = new TileSand();
public static final Tile STONE = new TileStone();
public static final Tile DIRT = new TileDirt();
public static final Tile TREE = new TileTree();
public static final Tile VOID = new TileVoid();
public static final Tile ROCK = new TileRock();
public static final Tile LAVA = new TileLava();
public static final Tile WATER = new TileWater();
public static final Tile LAVA_FLOW = new TileLavaFlow();
public static final Tile WATER_FLOW = new TileWaterFlow();
public static final Tile LADDER = new TileLadder();
public static final Tile PORTAL_DOWN = new TilePortalDown();
public static final Tile WALL = new TileWall();
public static final Tile LADDER_UP = new TileLadderUp();
public static final Tile CHEST = new TileChest();
public static final Tile LANTERN = new TileLantern();
public static final Tile WALL_UNBREAKABLE = new TileWallUnbreakable();
public static final Tile BOSS_PORTAL = new TileBossPortal();
} }

0
src/projectzombie/input/CursorEnterCallback.java Normal file → Executable file
View File

0
src/projectzombie/input/CursorPosCallback.java Normal file → Executable file
View File

0
src/projectzombie/input/GameInput.java Normal file → Executable file
View File

0
src/projectzombie/input/InputMode.java Normal file → Executable file
View File

0
src/projectzombie/input/JoystickCallback.java Normal file → Executable file
View File

0
src/projectzombie/input/KeyCallback.java Normal file → Executable file
View File

0
src/projectzombie/input/KeyCharCallback.java Normal file → Executable file
View File

0
src/projectzombie/input/MouseButtonCallback.java Normal file → Executable file
View File

0
src/projectzombie/input/ScrollWheelCallback.java Normal file → Executable file
View File

0
src/projectzombie/input/types/Input.java Normal file → Executable file
View File

0
src/projectzombie/input/types/InputGUI.java Normal file → Executable file
View File

5
src/projectzombie/input/types/InputGame.java Normal file → Executable file
View File

@ -4,6 +4,7 @@ import projectzombie.Main;
import projectzombie.menu.MenuGamePause; import projectzombie.menu.MenuGamePause;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
import projectzombie.world.chunk.ChunkEventHandler;
public class InputGame implements Input public class InputGame implements Input
{ {
@ -14,7 +15,9 @@ public class InputGame implements Input
if(state) if(state)
{ {
// Move the player in the left sticks angle // Move the player in the left sticks angle
Main.player.moveTowards(angle); if(ChunkEventHandler.loaded) {
Main.player.moveTowards(angle + Main.player.angle);
}
// Set the players moving to true // Set the players moving to true
Main.player.moving = true; Main.player.moving = true;

0
src/projectzombie/inventory/IInventory.java Normal file → Executable file
View File

38
src/projectzombie/inventory/Inventory.java Normal file → Executable file
View File

@ -1,8 +1,12 @@
package projectzombie.inventory; package projectzombie.inventory;
import bdf.classes.IBdfClassManager;
import bdf.types.BdfArray;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
public class Inventory implements IInventory public class Inventory implements IInventory, IBdfClassManager
{ {
protected ItemStack[] items; protected ItemStack[] items;
@ -43,5 +47,37 @@ public class Inventory implements IInventory
items[slot] = ItemStack.EMPTY; items[slot] = ItemStack.EMPTY;
return stack; return stack;
} }
@Override
public void BdfClassLoad(BdfObject bdf)
{
BdfNamedList nl = bdf.getNamedList();
items = new ItemStack[nl.get("size").getInteger()];
BdfArray array = nl.get("items").getArray();
for(int i=0;i<items.length;i++) {
items[i] = new ItemStack(array.get(i));
}
}
@Override
public void BdfClassSave(BdfObject bdf)
{
BdfNamedList nl = bdf.getNamedList();
nl.set("size", BdfObject.withInteger(items.length));
BdfArray array = nl.get("items").getArray();
for(ItemStack stack : items) {
BdfObject stack_bdf = new BdfObject();
stack.BdfClassSave(stack_bdf);
array.add(stack_bdf);
}
}
public Inventory(BdfObject bdf) {
BdfClassLoad(bdf);
}
} }

13
src/projectzombie/items/Item.java Normal file → Executable file
View File

@ -2,6 +2,7 @@ package projectzombie.items;
import projectzombie.entity.Entity; import projectzombie.entity.Entity;
import projectzombie.entity.EntityInventory; import projectzombie.entity.EntityInventory;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.inventory.Inventory; import projectzombie.inventory.Inventory;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;
import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.gl.texture.TextureReference;
@ -13,11 +14,7 @@ import projectzombie.world.layer.Layer;
public class Item public class Item
{ {
public TextureReference texture; public TextureReference texture;
public String id; public int id;
public Item(String id) {
this.id = id;
}
public void render(Vec2d pos, Vec2d size) public void render(Vec2d pos, Vec2d size)
{ {
@ -31,7 +28,7 @@ public class Item
GlHelpers.end(); GlHelpers.end();
} }
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) { public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
stack.count -= 1; stack.count -= 1;
} }
@ -39,6 +36,10 @@ public class Item
return ""; return "";
} }
public double getLightLevel() {
return 0;
}
public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity) public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity)
{ {
// Update the stacks count // Update the stacks count

3
src/projectzombie/items/ItemAmmo.java Normal file → Executable file
View File

@ -10,8 +10,7 @@ import projectzombie.world.layer.Layer;
public class ItemAmmo extends Item public class ItemAmmo extends Item
{ {
public ItemAmmo(String id) { public ItemAmmo() {
super(id);
this.texture = Textures.ITEM_AMMO_BOX; this.texture = Textures.ITEM_AMMO_BOX;
} }

9
src/projectzombie/items/ItemDefenceUpgrade.java Normal file → Executable file
View File

@ -1,7 +1,7 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
@ -10,17 +10,16 @@ import projectzombie.world.layer.Layer;
public class ItemDefenceUpgrade extends Item public class ItemDefenceUpgrade extends Item
{ {
public ItemDefenceUpgrade(String id) { public ItemDefenceUpgrade() {
super(id);
this.texture = Textures.ITEM_DEFENCE_UPGRADE; this.texture = Textures.ITEM_DEFENCE_UPGRADE;
} }
@Override @Override
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player)
{ {
if(Main.player.defence_level < stack.meta) { if(Main.player.defence_level < stack.meta) {
super.onAction(stack, layer, chunk, entity); super.onPlayerAction(stack, layer, chunk, player);
Main.player.defence_level = stack.meta; Main.player.defence_level = stack.meta;
} }
} }

6
src/projectzombie/items/ItemEmpty.java Normal file → Executable file
View File

@ -1,6 +1,7 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.entity.Entity; import projectzombie.entity.Entity;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2d;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
@ -9,12 +10,11 @@ import projectzombie.world.layer.Layer;
public class ItemEmpty extends Item public class ItemEmpty extends Item
{ {
public ItemEmpty(String id) { public ItemEmpty() {
super(id);
} }
@Override @Override
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) { public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
} }
@Override @Override

11
src/projectzombie/items/ItemFlare.java Normal file → Executable file
View File

@ -1,7 +1,7 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.entity.Entity;
import projectzombie.entity.EntityFlare; import projectzombie.entity.EntityFlare;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
@ -10,16 +10,15 @@ import projectzombie.world.layer.Layer;
public class ItemFlare extends Item public class ItemFlare extends Item
{ {
public ItemFlare(String id) { public ItemFlare() {
super(id);
this.texture = Textures.ENTITY_FLARE; this.texture = Textures.ENTITY_FLARE;
} }
@Override @Override
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) { public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
super.onAction(stack, layer, chunk, entity); super.onPlayerAction(stack, layer, chunk, player);
layer.spawnEntity(new EntityFlare(entity.pos.copy(), entity.angle)); layer.spawnEntity(new EntityFlare(player.pos.copy(), player.angle));
} }
@Override @Override

13
src/projectzombie/items/ItemGrapplingHook.java Normal file → Executable file
View File

@ -1,7 +1,7 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.entity.Entity;
import projectzombie.entity.EntityGrapplingHook; import projectzombie.entity.EntityGrapplingHook;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
import projectzombie.util.math.MathHelpers; import projectzombie.util.math.MathHelpers;
@ -12,8 +12,7 @@ import projectzombie.world.layer.Layer;
public class ItemGrapplingHook extends Item public class ItemGrapplingHook extends Item
{ {
public ItemGrapplingHook(String id) { public ItemGrapplingHook() {
super(id);
this.texture = Textures.ITEM_GRAPPLING_HOOK; this.texture = Textures.ITEM_GRAPPLING_HOOK;
} }
@ -24,11 +23,11 @@ public class ItemGrapplingHook extends Item
} }
@Override @Override
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) { public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
super.onAction(stack, layer, chunk, entity); super.onPlayerAction(stack, layer, chunk, player);
Vec2d pos = entity.pos.add(MathHelpers.moveTowards2(0.01, Math.toRadians(entity.angle))); Vec2d pos = player.pos.add(MathHelpers.moveTowards2(0.01, Math.toRadians(player.angle)));
layer.spawnEntity(new EntityGrapplingHook(pos, stack.meta, entity)); layer.spawnEntity(new EntityGrapplingHook(pos, stack.meta, player));
} }
} }

9
src/projectzombie/items/ItemGunUpgrade.java Normal file → Executable file
View File

@ -1,7 +1,7 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
@ -10,17 +10,16 @@ import projectzombie.world.layer.Layer;
public class ItemGunUpgrade extends Item public class ItemGunUpgrade extends Item
{ {
public ItemGunUpgrade(String id) { public ItemGunUpgrade() {
super(id);
this.texture = Textures.ITEM_GUN_UPGRADE; this.texture = Textures.ITEM_GUN_UPGRADE;
} }
@Override @Override
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player)
{ {
if(Main.player.gun_level < stack.meta) { if(Main.player.gun_level < stack.meta) {
super.onAction(stack, layer, chunk, entity); super.onPlayerAction(stack, layer, chunk, player);
Main.player.gun_level = stack.meta; Main.player.gun_level = stack.meta;
} }
} }

21
src/projectzombie/items/ItemHealthPotion.java Normal file → Executable file
View File

@ -1,7 +1,6 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer;
import projectzombie.entity.EntityAlive;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
@ -10,8 +9,7 @@ import projectzombie.world.layer.Layer;
public class ItemHealthPotion extends Item public class ItemHealthPotion extends Item
{ {
public ItemHealthPotion(String id) { public ItemHealthPotion() {
super(id);
this.texture = Textures.ITEM_HEALTH_POTION; this.texture = Textures.ITEM_HEALTH_POTION;
} }
@ -22,17 +20,10 @@ public class ItemHealthPotion extends Item
} }
@Override @Override
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) { public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
super.onAction(stack, layer, chunk, entity); super.onPlayerAction(stack, layer, chunk, player);
// Is the entity alive // Heal the player
if(entity instanceof EntityAlive) player.addHealth(stack.meta);
{
// Cast to alive entity
EntityAlive entity_a = (EntityAlive)entity;
// Heal the entity
entity_a.addHealth(stack.meta);
}
} }
} }

16
src/projectzombie/items/ItemLantern.java Normal file → Executable file
View File

@ -1,6 +1,6 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Textures; import projectzombie.init.Textures;
import projectzombie.init.Tiles; import projectzombie.init.Tiles;
import projectzombie.util.math.ItemStack; import projectzombie.util.math.ItemStack;
@ -12,19 +12,23 @@ import projectzombie.world.layer.Layer;
public class ItemLantern extends Item public class ItemLantern extends Item
{ {
public ItemLantern(String id) { public ItemLantern() {
super(id);
this.texture = Textures.TILE_LANTERN; this.texture = Textures.TILE_LANTERN;
} }
@Override @Override
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) public double getLightLevel() {
return 1;
}
@Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player)
{ {
Vec2i tpos = new Vec2i(MathHelpers.floor(entity.pos.x), MathHelpers.floor(entity.pos.y)); Vec2i tpos = new Vec2i(MathHelpers.floor(player.pos.x), MathHelpers.floor(player.pos.y));
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.onAction(stack, layer, chunk, entity); super.onPlayerAction(stack, layer, chunk, player);
} }
} }

View File

@ -0,0 +1,27 @@
package projectzombie.items;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Textures;
import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ItemRock extends Item
{
public ItemRock() {
this.texture = Textures.TILE_ROCK;
}
@Override
public String getName(short meta) {
return "Rock";
}
@Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
//super.onAction(stack, layer, chunk, entity);
}
}

View File

@ -0,0 +1,25 @@
package projectzombie.items;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.util.math.ItemStack;
import projectzombie.util.math.vec.Vec2d;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ItemSpawn extends Item
{
@Override
public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) {
super.onPlayerAction(stack, layer, chunk, player);
this.spawnEntity(layer, chunk, player.pos.copy());
}
public void spawnEntity(Layer layer, Chunk chunk, Vec2d pos) {
}
}

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