Added deaths, added breaking particles
This commit is contained in:
parent
745305e2f3
commit
121c6f10eb
|
|
@ -1,7 +1,11 @@
|
|||
package shootergame.entity;
|
||||
|
||||
import shootergame.display.Camera;
|
||||
import shootergame.inventory.Inventory;
|
||||
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.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
|
@ -9,19 +13,42 @@ import shootergame.world.layer.Layer;
|
|||
public class EntityItem extends EntityVertical
|
||||
{
|
||||
private ItemStack stack;
|
||||
private double height = 0;
|
||||
private double height_speed;
|
||||
private int pickup_time = 100;
|
||||
|
||||
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.pos = pos;
|
||||
this.stack = stack;
|
||||
this.angle = RandomHelpers.randrange(rand, 360);
|
||||
height_speed = RandomHelpers.randrange(rand, 10000) / 200000.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(Chunk chunk, Layer 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))
|
||||
{
|
||||
if(e instanceof EntityInventory)
|
||||
|
|
@ -38,3 +65,12 @@ 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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class EntityTnt extends EntityVertical
|
|||
private 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;
|
||||
this.angle = angle;
|
||||
|
|
|
|||
|
|
@ -8,20 +8,20 @@ import shootergame.util.math.vec.Vec2d;
|
|||
public class EntityVertical extends Entity
|
||||
{
|
||||
private TextureReference tex;
|
||||
private double height;
|
||||
private Vec2d size;
|
||||
|
||||
public EntityVertical(TextureReference tex, double height) {
|
||||
this.height = height;
|
||||
public EntityVertical(TextureReference tex, Vec2d size) {
|
||||
this.size = size;
|
||||
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);
|
||||
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
|
||||
public void render(Vec2d pos, Camera camera) {
|
||||
this.render(pos, camera, tex, height);
|
||||
this.render(pos, camera, tex, size);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import shootergame.Main;
|
|||
import shootergame.init.Sounds;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.util.math.random.OpenSimplexNoise;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.util.math.vec.Vec3d;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
|
@ -21,7 +22,7 @@ public class EntityZombie extends EntityVertical implements EntityAlive
|
|||
private int gun_interval = 0;
|
||||
|
||||
public EntityZombie() {
|
||||
super(Textures.ENTITY_ZOMBIE, 1);
|
||||
super(Textures.ENTITY_ZOMBIE, new Vec2d(1, 1));
|
||||
noise_movement = new OpenSimplexNoise(rand.nextLong());
|
||||
noise_gun_fire = new OpenSimplexNoise(rand.nextLong());
|
||||
noise_gun_angle = new OpenSimplexNoise(rand.nextLong());
|
||||
|
|
|
|||
|
|
@ -1,23 +1,32 @@
|
|||
package shootergame.entity.particle;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.display.Camera;
|
||||
import shootergame.entity.EntityParticle;
|
||||
import shootergame.entity.EntityVertical;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.texture.IHasTexture;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.TileState;
|
||||
import shootergame.util.math.random.RandomHelpers;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
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)
|
||||
{
|
||||
if(ts.tile instanceof IHasTexture)
|
||||
{
|
||||
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 {
|
||||
|
|
@ -25,10 +34,12 @@ public class EntityBreak extends EntityVertical
|
|||
}
|
||||
}
|
||||
|
||||
public EntityBreak(Vec2d pos, TileState ts) {
|
||||
super(getTexture(ts), 1);
|
||||
public ParticleBreak(Vec2d pos, TileState ts) {
|
||||
super(getTexture(ts), new Vec2d(1/4.0, 1/4.0));
|
||||
this.opaqueTile = ts.tile.opaqueTile;
|
||||
this.pos = pos;
|
||||
this.angle = RandomHelpers.randrange(rand, 360);
|
||||
height_speed = RandomHelpers.randrange(rand, 10000) / 200000.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -36,6 +47,29 @@ public class EntityBreak extends EntityVertical
|
|||
super.tick(chunk, layer);
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,8 +48,10 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
|||
|
||||
public int ammo = 1000;
|
||||
|
||||
private static final Vec2d size = new Vec2d(1, 1);
|
||||
|
||||
public EntityPlayer() {
|
||||
super(TextureReference.EMPTY, 0);
|
||||
super(TextureReference.EMPTY, size);
|
||||
|
||||
this.angle = 45;
|
||||
rand = new Random();
|
||||
|
|
@ -66,16 +68,19 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
|||
@Override
|
||||
public void tick(Chunk chunk, Layer layer)
|
||||
{
|
||||
// Reset the health if god mode is active
|
||||
|
||||
// Player deaths
|
||||
if(health < 0)
|
||||
{
|
||||
if(Cheats.god_mode) {
|
||||
this.resetHealth();
|
||||
}
|
||||
|
||||
// Don't tick if the player is dead
|
||||
else if(health < 0) {
|
||||
else {
|
||||
dead = true;
|
||||
health = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Is the player dead or in an animation
|
||||
if(dead || in_animation) return;
|
||||
|
|
@ -151,10 +156,10 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
|||
|
||||
// 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
|
||||
else super.render(pos, camera, Textures.ENTITY_PLAYER_STILL, 1);
|
||||
else super.render(pos, camera, Textures.ENTITY_PLAYER_STILL, size);
|
||||
|
||||
// Pop the matrix
|
||||
GlHelpers.popMatrix();
|
||||
|
|
@ -197,7 +202,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
|||
@Override
|
||||
public void removeHealth(double amount) {
|
||||
health -= amount;
|
||||
if(health < 0) health = 0;
|
||||
if(health < 0) health = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class TileChest extends TileVertical
|
|||
{
|
||||
|
||||
public TileChest(String id) {
|
||||
super(id, Textures.TILE_CHEST, 1);
|
||||
super(id, Textures.TILE_CHEST, new Vec2d(1, 1));
|
||||
|
||||
this.tileSolid = 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package shootergame.tiles;
|
||||
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
|
||||
public class TileFire extends TileVertical
|
||||
{
|
||||
|
||||
public TileFire(String id) {
|
||||
super(id, Textures.TILE_FIRE, 6);
|
||||
super(id, Textures.TILE_FIRE, new Vec2d(1, 6));
|
||||
|
||||
// Set some settings
|
||||
this.opaqueTile = true;
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ package shootergame.tiles;
|
|||
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
|
||||
public class TileLadder extends TileVertical
|
||||
{
|
||||
|
||||
public TileLadder(String id) {
|
||||
super(id, Textures.TILE_LADDER, 1);
|
||||
super(id, Textures.TILE_LADDER, new Vec2d(1, 1));
|
||||
|
||||
this.opaqueTile = true;
|
||||
this.tileSolid = true;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import shootergame.world.layer.Layer;
|
|||
public class TileLadderUp extends TileVertical
|
||||
{
|
||||
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.tileSolid = true;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package shootergame.tiles;
|
||||
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
|
||||
public class TileRock extends TileVertical
|
||||
{
|
||||
|
||||
public TileRock(String id) {
|
||||
super(id, Textures.TILE_ROCK, 1);
|
||||
super(id, Textures.TILE_ROCK, new Vec2d(1, 1));
|
||||
|
||||
// Set some settings
|
||||
this.opaqueTile = true;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package shootergame.tiles;
|
||||
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
|
||||
public class TileTree extends TileVertical
|
||||
{
|
||||
|
||||
public TileTree(String id) {
|
||||
super(id, Textures.TILE_TREE, 4);
|
||||
super(id, Textures.TILE_TREE, new Vec2d(1, 4));
|
||||
|
||||
// Set some settings
|
||||
this.opaqueTile = true;
|
||||
|
|
|
|||
|
|
@ -13,20 +13,20 @@ import shootergame.util.math.vec.Vec2i;
|
|||
public class TileVertical extends Tile implements IHasTexture
|
||||
{
|
||||
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);
|
||||
|
||||
// Store some variables
|
||||
this.tex = tex;
|
||||
this.h = height;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Vec2d pos, Camera camera, short meta) {
|
||||
super.render(pos, camera, meta);
|
||||
VerticalRender.render(pos, camera, tex, h);
|
||||
VerticalRender.render(pos, camera, tex, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ import shootergame.util.math.vec.Vec2d;
|
|||
|
||||
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
|
||||
GlHelpers.pushMatrix();
|
||||
|
|
@ -25,10 +26,10 @@ public class VerticalRender
|
|||
|
||||
// Render the tile
|
||||
GlHelpers.begin();
|
||||
tex.texCoord(1, 1); GlHelpers.vertex3(0, 0.5, 0);
|
||||
tex.texCoord(0, 1); GlHelpers.vertex3(1, 0.5, 0);
|
||||
tex.texCoord(0, 0); GlHelpers.vertex3(1, 0.5, h);
|
||||
tex.texCoord(1, 0); GlHelpers.vertex3(0, 0.5, h);
|
||||
tex.texCoord(1, 1); GlHelpers.vertex3(0.5-w, 0.5, 0);
|
||||
tex.texCoord(0, 1); GlHelpers.vertex3(0.5+w, 0.5, 0);
|
||||
tex.texCoord(0, 0); GlHelpers.vertex3(0.5+w, 0.5, h);
|
||||
tex.texCoord(1, 0); GlHelpers.vertex3(0.5-w, 0.5, h);
|
||||
GlHelpers.end();
|
||||
|
||||
// Pop the matrix
|
||||
|
|
|
|||
|
|
@ -6,16 +6,34 @@ import shootergame.util.math.MathHelpers;
|
|||
|
||||
public abstract class TextureReference
|
||||
{
|
||||
private int start_x;
|
||||
private int start_y;
|
||||
private int end_x;
|
||||
private int end_y;
|
||||
public int start_x;
|
||||
public int start_y;
|
||||
public int end_x;
|
||||
public int end_y;
|
||||
|
||||
public static final TextureReference EMPTY = new TextureReferenceEmpty();
|
||||
|
||||
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)
|
||||
{
|
||||
// Save all the specified values
|
||||
|
|
|
|||
|
|
@ -6,10 +6,13 @@ import java.util.Random;
|
|||
import shootergame.display.Camera;
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.entity.EntityAlive;
|
||||
import shootergame.entity.EntityTnt;
|
||||
import shootergame.entity.particle.ParticleBreak;
|
||||
import shootergame.init.Tiles;
|
||||
import shootergame.tiles.Tile;
|
||||
import shootergame.util.math.MathHelpers;
|
||||
import shootergame.util.math.TileState;
|
||||
import shootergame.util.math.random.RandomHelpers;
|
||||
import shootergame.util.math.range.Range2i;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.util.math.vec.Vec2i;
|
||||
|
|
@ -175,6 +178,9 @@ public class Chunk
|
|||
|
||||
if(!ts.tile.unbreakable) {
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue