TNT kills alive entities, explosion blood is dependant on entities

killed, improved management of player deaths.
This commit is contained in:
josua 2019-08-28 14:35:38 +10:00
parent 2f9e19d072
commit 230ae4846c
6 changed files with 80 additions and 70 deletions

View File

@ -28,6 +28,8 @@ public class Entity implements ITransparentObject
private double speed = 1; 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 goThroughSolid = true;
public Entity(Vec2d pos, double angle) public Entity(Vec2d pos, double angle)
{ {
@ -153,10 +155,8 @@ public class Entity implements ITransparentObject
tile_front = Main.world.getLayer().getFrontTile(t_pos); tile_front = Main.world.getLayer().getFrontTile(t_pos);
// Is this entity solid // Is this entity solid
if(isSolid) if(!goThroughSolid || !crossUnWalkable)
{ {
// Get the layer
Layer l = Main.world.getLayer();
// 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);
@ -166,9 +166,20 @@ public class Entity implements ITransparentObject
Tile t = tile_back.tile; Tile t = tile_back.tile;
// Send false if the tile isn't walkable // Send false if the tile isn't walkable
if(!t.tileWalkable) { if((!t.tileWalkable) && (!crossUnWalkable)) {
return false; return false;
} }
// Check the tiles hitbox if the tile is solid
if((t.tileSolid) && (!goThroughSolid))
{
// Is the entity in the tiles hitbox
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox)
{
// Send back false
return false;
}
}
} }
{ {
@ -176,12 +187,12 @@ public class Entity implements ITransparentObject
Tile t = tile_front.tile; Tile t = tile_front.tile;
// Send false if the tile isn't walkable // Send false if the tile isn't walkable
if(!t.tileWalkable) { if((!t.tileWalkable) && (!crossUnWalkable)) {
return false; return false;
} }
// Check the tiles hitbox if the tile is solid // Check the tiles hitbox if the tile is solid
if(t.tileSolid) if((t.tileSolid) && (!goThroughSolid))
{ {
// Is the entity in the tiles hitbox // Is the entity in the tiles hitbox
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox) if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox)

View File

@ -22,7 +22,7 @@ import shootergame.world.layer.Layer;
public class EntityTnt extends EntityVertical public class EntityTnt extends EntityVertical
{ {
private double height = 0.4; private double height = 0.4;
private Vec3d velocity; private double velocity_up;
private int explode_time; private int explode_time;
private int explode_radius; private int explode_radius;
@ -31,9 +31,12 @@ public class EntityTnt extends EntityVertical
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, 0.5);
velocity = MathHelpers.moveTowards3(0.1, new Vec2d(Math.toRadians(angle), Math.toRadians(20))); velocity_up = 0.01;
this.angle = angle;
this.pos = pos; this.pos = pos;
this.explode_radius = explode_radius; this.explode_radius = explode_radius;
this.crossUnWalkable = true;
this.goThroughSolid = false;
// Set to 2.5 seconds // Set to 2.5 seconds
this.explode_time = 250; this.explode_time = 250;
@ -43,32 +46,19 @@ public class EntityTnt extends EntityVertical
public void tick(Chunk chunk, Layer layer) { public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer); super.tick(chunk, layer);
double nx = pos.x + velocity.x;
double ny = pos.y + velocity.y;
height += velocity.z;
// Create a downward gravitational pull // Create a downward gravitational pull
velocity.z -= 0.001; height += velocity_up;
velocity_up -= 0.001;
// Reduce the velocty // Move forwards
velocity.x /= 1.01; moveForward(0.05);
velocity.y /= 1.01;
velocity.z /= 1.01;
// Make the tnt bounce on the ground // Make the tnt bounce on the ground
if(height < 0) { if(height < 0) {
height = 0; height = 0;
velocity.z = -velocity.z; velocity_up = -velocity_up;
} }
// Make the tnt bounce off obsticles
if(moveIsLegal(new Vec2d(nx, pos.y)))
pos.x = nx;
else velocity.x *= -1;
if(moveIsLegal(new Vec2d(pos.y, ny)))
pos.y = ny;
else velocity.y *= -1;
// Is it time for the tnt to blow up // Is it time for the tnt to blow up
explode_time -= 1; explode_time -= 1;
if(explode_time < 0) if(explode_time < 0)
@ -106,8 +96,23 @@ public class EntityTnt extends EntityVertical
(short)blackened_gradient), tpos); (short)blackened_gradient), tpos);
if(!fts.tile.unbreakable) l.setFrontTile(Tiles.VOID.getDefaultState(), tpos); if(!fts.tile.unbreakable) l.setFrontTile(Tiles.VOID.getDefaultState(), tpos);
// Summon some blood boolean killed_entities = false;
l.spawnEntity(new ParticleBlood(rand, new Vec2d(px, py), py));
// Kill all the nearby entities
for(Entity e : layer.getNearbyEntities(pos, explode_radius))
{
// Is this entity alive
if(e instanceof EntityAlive)
{
// Kill the entity
killed_entities = true;
e.kill();
}
}
// Spawn some blood if entities were killed
if(killed_entities)
l.spawnEntity(new ParticleBlood(rand, new Vec2d(px, py), py));
} }
} }
} }
@ -131,37 +136,6 @@ public class EntityTnt extends EntityVertical
GlHelpers.popMatrix(); GlHelpers.popMatrix();
} }
@Override
public boolean moveIsLegal(Vec2d pos)
{
// Get the position of the tile the tnt is over
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
// Get the foreground tile and the background tile
Layer l = Main.world.getLayer();
TileState tile_f = l.getFrontTile(tpos);
TileState tile_b = l.getBackTile(tpos);
// Is the tile solid and has the tnt crashed into it
if(tile_f.tile.tileSolid) {
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_f.tile.tileHitbox)
{
// Send back false
return false;
}
}
if(tile_b.tile.tileSolid) {
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_b.tile.tileHitbox)
{
// Send back false
return false;
}
}
// Send back true by default
return true;
}
} }

View File

@ -32,6 +32,8 @@ public class EntityZombie extends EntityVertical implements EntityAlive
// Set some settings // Set some settings
hitbox = 0.5; hitbox = 0.5;
isSolid = true; isSolid = true;
goThroughSolid = false;
crossUnWalkable = false;
} }
@Override @Override

View File

@ -36,6 +36,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
private Random rand; private Random rand;
private double health_max = 1000; private double health_max = 1000;
private double health = health_max; private double health = health_max;
public boolean dead = false;
public EntityPlayer() { public EntityPlayer() {
this.angle = 45; this.angle = 45;
@ -44,6 +45,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
// Set some settings // Set some settings
hitbox = 0.5; hitbox = 0.5;
isSolid = true; isSolid = true;
goThroughSolid = false;
crossUnWalkable = false;
} }
@Override @Override
@ -55,7 +58,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
} }
// Don't tick if the player is dead // Don't tick if the player is dead
if(this.getHealth() < 0) return; if(dead) return;
// Call super // Call super
super.tick(chunk, layer); super.tick(chunk, layer);
@ -88,6 +91,20 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
} }
} }
@Override
public void kill()
{
// Is god mode inactive; kill the player
if(!Cheats.god_mode) {
dead = true;
}
}
@Override
public void moveTowards(double angle, double speed) {
if(!dead) super.moveTowards(angle, speed);
}
@Override @Override
public void moveForward() { public void moveForward() {
this.moveForward(0.08); this.moveForward(0.08);
@ -102,7 +119,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
public void render(Vec2d pos, Camera camera) public void render(Vec2d pos, Camera camera)
{ {
// Don't render if the player is dead // Don't render if the player is dead
if(this.getHealth() < 0) return; if(dead) return;
// Translation // Translation
GlHelpers.pushMatrix(); GlHelpers.pushMatrix();
@ -121,6 +138,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
public void fireBullet(double angle) public void fireBullet(double angle)
{ {
if(dead) return;
bullet_frequency += 1; bullet_frequency += 1;
bullet_frequency %= 10; bullet_frequency %= 10;
@ -132,10 +151,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
} }
} }
private boolean throwTnt_last = false; public void throwTnt(double angle) {
if(dead) return;
public void throwTnt(double angle)
{
Main.world.getLayer().spawnEntity(new EntityTnt(pos.copy(), angle + this.angle, 10)); Main.world.getLayer().spawnEntity(new EntityTnt(pos.copy(), angle + this.angle, 10));
} }

View File

@ -187,7 +187,9 @@ public class Chunk
e.pos.y + distance > pos.y && e.pos.y + distance > pos.y &&
e.pos.y - distance < pos.y e.pos.y - distance < pos.y
) { ) {
nearby_entities.add(e); if(MathHelpers.distance2d(e.pos.x, e.pos.y, pos.x, pos.y) < distance) {
nearby_entities.add(e);
}
} }
} }

View File

@ -143,8 +143,10 @@ public class Layer
ArrayList<Entity> entities = new ArrayList<Entity>(); ArrayList<Entity> entities = new ArrayList<Entity>();
Vec2i cpos = getChunkPosFromPos(pos); Vec2i cpos = getChunkPosFromPos(pos);
for(int x=-1;x<=1;x++) { int scan_distance = (int)distance / Chunk.CHUNK_SIZE.mx + 1;
for(int y=-1;y<=1;y++)
for(int x=-scan_distance;x<=scan_distance;x++) {
for(int y=-scan_distance;y<=scan_distance;y++)
{ {
//System.out.println("x: "+x+", y: "+y); //System.out.println("x: "+x+", y: "+y);
for(Entity e : chunks.get(new Vec2i(x+cpos.x, y+cpos.y)).getNearbyEntities(pos, distance)) { for(Entity e : chunks.get(new Vec2i(x+cpos.x, y+cpos.y)).getNearbyEntities(pos, distance)) {
@ -161,7 +163,9 @@ public class Layer
Main.player.pos.y - distance < pos.y Main.player.pos.y - distance < pos.y
) { ) {
// Add the player to the list of entities // Add the player to the list of entities
entities.add(Main.player); if(MathHelpers.distance2d(Main.player.pos.x, Main.player.pos.y, pos.x, pos.y) < distance) {
entities.add(Main.player);
}
} }
// Send back the list of nearby entities // Send back the list of nearby entities