Added deaths, added breaking particles

This commit is contained in:
josua 2019-08-31 14:32:28 +10:00
parent 745305e2f3
commit 121c6f10eb
16 changed files with 165 additions and 56 deletions

View File

@ -1,7 +1,11 @@
package shootergame.entity; package shootergame.entity;
import shootergame.display.Camera;
import shootergame.inventory.Inventory; import shootergame.inventory.Inventory;
import shootergame.items.ItemStack; import shootergame.items.ItemStack;
import shootergame.util.gl.GlHelpers;
import shootergame.util.gl.texture.TextureReference;
import shootergame.util.math.random.RandomHelpers;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -9,19 +13,42 @@ import shootergame.world.layer.Layer;
public class EntityItem extends EntityVertical public class EntityItem extends EntityVertical
{ {
private ItemStack stack; private ItemStack stack;
private double height = 0;
private double height_speed;
private int pickup_time = 100;
public EntityItem(Vec2d pos, ItemStack stack) { public EntityItem(Vec2d pos, ItemStack stack) {
super(stack.item.texture, 1); super(stack.item.texture, new Vec2d(0.5, 0.5));
this.opaqueTile = true; this.opaqueTile = true;
this.pos = pos; this.pos = pos;
this.stack = stack; this.stack = stack;
this.angle = RandomHelpers.randrange(rand, 360);
height_speed = RandomHelpers.randrange(rand, 10000) / 200000.0;
} }
@Override @Override
public void tick(Chunk chunk, Layer layer) { public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer); super.tick(chunk, layer);
height += height_speed;
height_speed -= 0.001;
pickup_time -= 1;
if(pickup_time < 0) {
pickup_time = 0;
}
if(height <= 0) {
height_speed = 0;
}
else {
moveForward(0.01);
}
if(pickup_time == 0)
{
for(Entity e : layer.getNearbyEntities(pos, 1)) for(Entity e : layer.getNearbyEntities(pos, 1))
{ {
if(e instanceof EntityInventory) if(e instanceof EntityInventory)
@ -37,4 +64,13 @@ public class EntityItem extends EntityVertical
} }
} }
} }
}
@Override
public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) {
GlHelpers.pushMatrix();
GlHelpers.translate(0, 0, height);
super.render(pos, camera, tex, size);
GlHelpers.popMatrix();
}
} }

View File

@ -27,7 +27,7 @@ public class EntityTnt extends EntityVertical
private int explode_radius; private int explode_radius;
public EntityTnt(Vec2d pos, double angle, int explode_radius) { public EntityTnt(Vec2d pos, double angle, int explode_radius) {
super(Textures.ENTITY_TNT, 0.5); super(Textures.ENTITY_TNT, new Vec2d(0.5, 0.5));
velocity_up = 0.01; velocity_up = 0.01;
this.angle = angle; this.angle = angle;

View File

@ -8,20 +8,20 @@ import shootergame.util.math.vec.Vec2d;
public class EntityVertical extends Entity public class EntityVertical extends Entity
{ {
private TextureReference tex; private TextureReference tex;
private double height; private Vec2d size;
public EntityVertical(TextureReference tex, double height) { public EntityVertical(TextureReference tex, Vec2d size) {
this.height = height; this.size = size;
this.tex = tex; this.tex = tex;
} }
public void render(Vec2d pos, Camera camera, TextureReference tex, double height) { public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) {
super.render(pos, camera); super.render(pos, camera);
VerticalRender.render(new Vec2d(pos.x - 0.5, pos.y - 0.5), camera, tex, height); VerticalRender.render(new Vec2d(pos.x - 0.5, pos.y - 0.5), camera, tex, size);
} }
@Override @Override
public void render(Vec2d pos, Camera camera) { public void render(Vec2d pos, Camera camera) {
this.render(pos, camera, tex, height); this.render(pos, camera, tex, size);
} }
} }

View File

@ -6,6 +6,7 @@ import shootergame.Main;
import shootergame.init.Sounds; import shootergame.init.Sounds;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.util.math.random.OpenSimplexNoise; import shootergame.util.math.random.OpenSimplexNoise;
import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec3d; import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -21,7 +22,7 @@ public class EntityZombie extends EntityVertical implements EntityAlive
private int gun_interval = 0; private int gun_interval = 0;
public EntityZombie() { public EntityZombie() {
super(Textures.ENTITY_ZOMBIE, 1); super(Textures.ENTITY_ZOMBIE, new Vec2d(1, 1));
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());

View File

@ -1,23 +1,32 @@
package shootergame.entity.particle; package shootergame.entity.particle;
import shootergame.Main; import shootergame.Main;
import shootergame.display.Camera;
import shootergame.entity.EntityParticle; import shootergame.entity.EntityParticle;
import shootergame.entity.EntityVertical; import shootergame.entity.EntityVertical;
import shootergame.util.gl.GlHelpers;
import shootergame.util.gl.texture.IHasTexture; import shootergame.util.gl.texture.IHasTexture;
import shootergame.util.gl.texture.TextureReference; import shootergame.util.gl.texture.TextureReference;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.random.RandomHelpers;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
public class EntityBreak extends EntityVertical public class ParticleBreak extends EntityVertical
{ {
private double height = 0;
private double height_speed;
private int time = 1000;
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();
return tex; 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 { else {
@ -25,10 +34,12 @@ public class EntityBreak extends EntityVertical
} }
} }
public EntityBreak(Vec2d pos, TileState ts) { public ParticleBreak(Vec2d pos, TileState ts) {
super(getTexture(ts), 1); super(getTexture(ts), new Vec2d(1/4.0, 1/4.0));
this.opaqueTile = ts.tile.opaqueTile; this.opaqueTile = ts.tile.opaqueTile;
this.pos = pos; this.pos = pos;
this.angle = RandomHelpers.randrange(rand, 360);
height_speed = RandomHelpers.randrange(rand, 10000) / 200000.0;
} }
@Override @Override
@ -36,6 +47,29 @@ public class EntityBreak extends EntityVertical
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) > 32 || time < 0) {
this.kill();
}
time -= 1;
height += height_speed;
height_speed -= 0.001;
if(height <= 0) {
height_speed = 0;
}
else {
moveForward(0.01);
}
}
@Override
public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) {
GlHelpers.pushMatrix();
GlHelpers.translate(0, 0, height);
super.render(pos, camera, tex, size);
GlHelpers.popMatrix();
} }
} }

View File

@ -48,8 +48,10 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
public int ammo = 1000; public int ammo = 1000;
private static final Vec2d size = new Vec2d(1, 1);
public EntityPlayer() { public EntityPlayer() {
super(TextureReference.EMPTY, 0); super(TextureReference.EMPTY, size);
this.angle = 45; this.angle = 45;
rand = new Random(); rand = new Random();
@ -66,16 +68,19 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
@Override @Override
public void tick(Chunk chunk, Layer layer) public void tick(Chunk chunk, Layer layer)
{ {
// Reset the health if god mode is active
// Player deaths
if(health < 0)
{
if(Cheats.god_mode) { if(Cheats.god_mode) {
this.resetHealth(); this.resetHealth();
} }
// Don't tick if the player is dead else {
else if(health < 0) {
dead = true; dead = true;
health = 0; health = 0;
} }
}
// Is the player dead or in an animation // Is the player dead or in an animation
if(dead || in_animation) return; if(dead || in_animation) return;
@ -151,10 +156,10 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
// Moving // Moving
if(MOVE_BACKWARD || MOVE_FORWARD || moving) if(MOVE_BACKWARD || MOVE_FORWARD || moving)
super.render(pos, camera, Textures.ENTITY_PLAYER_MOVING, 1); super.render(pos, camera, Textures.ENTITY_PLAYER_MOVING, size);
// Standing still // Standing still
else super.render(pos, camera, Textures.ENTITY_PLAYER_STILL, 1); else super.render(pos, camera, Textures.ENTITY_PLAYER_STILL, size);
// Pop the matrix // Pop the matrix
GlHelpers.popMatrix(); GlHelpers.popMatrix();
@ -197,7 +202,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
@Override @Override
public void removeHealth(double amount) { public void removeHealth(double amount) {
health -= amount; health -= amount;
if(health < 0) health = 0; if(health < 0) health = -1;
} }
@Override @Override

View File

@ -15,7 +15,7 @@ public class TileChest extends TileVertical
{ {
public TileChest(String id) { public TileChest(String id) {
super(id, Textures.TILE_CHEST, 1); super(id, Textures.TILE_CHEST, new Vec2d(1, 1));
this.tileSolid = true; this.tileSolid = true;
this.opaqueTile = true; this.opaqueTile = true;
@ -27,7 +27,8 @@ public class TileChest extends TileVertical
public void onActivated(Chunk chunk, Layer layer, Vec2i tpos, Entity entity, short meta) { public void onActivated(Chunk chunk, Layer layer, Vec2i tpos, Entity entity, short meta) {
super.onActivated(chunk, layer, tpos, entity, meta); super.onActivated(chunk, layer, tpos, entity, meta);
layer.spawnEntity(new EntityItem(new Vec2d(tpos.x, tpos.y), new ItemStack(Items.HEALTH_POTION, 1, (short)20))); layer.spawnEntity(new EntityItem(new Vec2d(tpos.x+0.5, tpos.y+0.5), new ItemStack(Items.HEALTH_POTION, 1, (short)20)));
layer.breakFrontTile(tpos);
} }
} }

View File

@ -1,12 +1,13 @@
package shootergame.tiles; package shootergame.tiles;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.util.math.vec.Vec2d;
public class TileFire extends TileVertical public class TileFire extends TileVertical
{ {
public TileFire(String id) { public TileFire(String id) {
super(id, Textures.TILE_FIRE, 6); super(id, Textures.TILE_FIRE, new Vec2d(1, 6));
// Set some settings // Set some settings
this.opaqueTile = true; this.opaqueTile = true;

View File

@ -2,12 +2,13 @@ package shootergame.tiles;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.util.gl.texture.TextureReference; import shootergame.util.gl.texture.TextureReference;
import shootergame.util.math.vec.Vec2d;
public class TileLadder extends TileVertical public class TileLadder extends TileVertical
{ {
public TileLadder(String id) { public TileLadder(String id) {
super(id, Textures.TILE_LADDER, 1); super(id, Textures.TILE_LADDER, new Vec2d(1, 1));
this.opaqueTile = true; this.opaqueTile = true;
this.tileSolid = true; this.tileSolid = true;

View File

@ -14,7 +14,7 @@ import shootergame.world.layer.Layer;
public class TileLadderUp extends TileVertical public class TileLadderUp extends TileVertical
{ {
public TileLadderUp(String id) { public TileLadderUp(String id) {
super(id, Textures.TILE_LADDER_UP, 16); super(id, Textures.TILE_LADDER_UP, new Vec2d(1, 16));
this.opaqueTile = true; this.opaqueTile = true;
this.tileSolid = true; this.tileSolid = true;

View File

@ -1,12 +1,13 @@
package shootergame.tiles; package shootergame.tiles;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.util.math.vec.Vec2d;
public class TileRock extends TileVertical public class TileRock extends TileVertical
{ {
public TileRock(String id) { public TileRock(String id) {
super(id, Textures.TILE_ROCK, 1); super(id, Textures.TILE_ROCK, new Vec2d(1, 1));
// Set some settings // Set some settings
this.opaqueTile = true; this.opaqueTile = true;

View File

@ -1,12 +1,13 @@
package shootergame.tiles; package shootergame.tiles;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.util.math.vec.Vec2d;
public class TileTree extends TileVertical public class TileTree extends TileVertical
{ {
public TileTree(String id) { public TileTree(String id) {
super(id, Textures.TILE_TREE, 4); super(id, Textures.TILE_TREE, new Vec2d(1, 4));
// Set some settings // Set some settings
this.opaqueTile = true; this.opaqueTile = true;

View File

@ -13,20 +13,20 @@ import shootergame.util.math.vec.Vec2i;
public class TileVertical extends Tile implements IHasTexture public class TileVertical extends Tile implements IHasTexture
{ {
private TextureReference tex; private TextureReference tex;
private int h; private Vec2d size;
public TileVertical(String id, TextureReference tex, int height) { public TileVertical(String id, TextureReference tex, Vec2d size) {
super(id); super(id);
// Store some variables // Store some variables
this.tex = tex; this.tex = tex;
this.h = height; this.size = size;
} }
@Override @Override
public void render(Vec2d pos, Camera camera, short meta) { public void render(Vec2d pos, Camera camera, short meta) {
super.render(pos, camera, meta); super.render(pos, camera, meta);
VerticalRender.render(pos, camera, tex, h); VerticalRender.render(pos, camera, tex, size);
} }
@Override @Override

View File

@ -7,9 +7,10 @@ import shootergame.util.math.vec.Vec2d;
public class VerticalRender public class VerticalRender
{ {
public static void render(Vec2d pos, Camera camera, TextureReference tex, double height) public static void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size)
{ {
double h = height; double w = size.x/2.0;
double h = size.y;
// Push the matrix // Push the matrix
GlHelpers.pushMatrix(); GlHelpers.pushMatrix();
@ -25,10 +26,10 @@ public class VerticalRender
// Render the tile // Render the tile
GlHelpers.begin(); GlHelpers.begin();
tex.texCoord(1, 1); GlHelpers.vertex3(0, 0.5, 0); tex.texCoord(1, 1); GlHelpers.vertex3(0.5-w, 0.5, 0);
tex.texCoord(0, 1); GlHelpers.vertex3(1, 0.5, 0); tex.texCoord(0, 1); GlHelpers.vertex3(0.5+w, 0.5, 0);
tex.texCoord(0, 0); GlHelpers.vertex3(1, 0.5, h); tex.texCoord(0, 0); GlHelpers.vertex3(0.5+w, 0.5, h);
tex.texCoord(1, 0); GlHelpers.vertex3(0, 0.5, h); tex.texCoord(1, 0); GlHelpers.vertex3(0.5-w, 0.5, h);
GlHelpers.end(); GlHelpers.end();
// Pop the matrix // Pop the matrix

View File

@ -6,16 +6,34 @@ import shootergame.util.math.MathHelpers;
public abstract class TextureReference public abstract class TextureReference
{ {
private int start_x; public int start_x;
private int start_y; public int start_y;
private int end_x; public int end_x;
private int end_y; public int end_y;
public static final TextureReference EMPTY = new TextureReferenceEmpty(); public static final TextureReference EMPTY = new TextureReferenceEmpty();
TextureReference() { TextureReference() {
} }
public TextureReference getTextureReference(int start_x, int end_x, int start_y, int end_y) {
TextureReference parent = this;
return new TextureReference(start_x, end_x, start_y, end_y)
{
@Override
public int getMaxX() {
return parent.getMaxX();
}
@Override
public int getMaxY() {
return parent.getMaxY();
}
};
}
public TextureReference(int start_x, int end_x, int start_y, int end_y) public TextureReference(int start_x, int end_x, int start_y, int end_y)
{ {
// Save all the specified values // Save all the specified values

View File

@ -6,10 +6,13 @@ import java.util.Random;
import shootergame.display.Camera; import shootergame.display.Camera;
import shootergame.entity.Entity; import shootergame.entity.Entity;
import shootergame.entity.EntityAlive; import shootergame.entity.EntityAlive;
import shootergame.entity.EntityTnt;
import shootergame.entity.particle.ParticleBreak;
import shootergame.init.Tiles; import shootergame.init.Tiles;
import shootergame.tiles.Tile; import shootergame.tiles.Tile;
import shootergame.util.math.MathHelpers; import shootergame.util.math.MathHelpers;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.random.RandomHelpers;
import shootergame.util.math.range.Range2i; import shootergame.util.math.range.Range2i;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
@ -175,6 +178,9 @@ public class Chunk
if(!ts.tile.unbreakable) { if(!ts.tile.unbreakable) {
setBackTile(layer.layergen.getTileDestroyed(), pos); setBackTile(layer.layergen.getTileDestroyed(), pos);
for(int i=0;i<20;i++) {
spawnEntity(new ParticleBreak(new Vec2d(pos.x+0.5, pos.y+0.5), ts));
}
} }
} }
@ -184,6 +190,9 @@ public class Chunk
if(!ts.tile.unbreakable) { if(!ts.tile.unbreakable) {
setFrontTile(Tiles.VOID.getDefaultState(), pos); setFrontTile(Tiles.VOID.getDefaultState(), pos);
for(int i=0;i<20;i++) {
spawnEntity(new ParticleBreak(new Vec2d(pos.x+0.5, pos.y+0.5), ts));
}
} }
} }