diff --git a/src/shootergame/entity/Entity.java b/src/shootergame/entity/Entity.java index b5b3701..6a4b038 100644 --- a/src/shootergame/entity/Entity.java +++ b/src/shootergame/entity/Entity.java @@ -28,6 +28,8 @@ public class Entity implements ITransparentObject private double speed = 1; private TileState tile_front; private TileState tile_back; + public boolean crossUnWalkable = true; + public boolean goThroughSolid = true; public Entity(Vec2d pos, double angle) { @@ -153,10 +155,8 @@ public class Entity implements ITransparentObject tile_front = Main.world.getLayer().getFrontTile(t_pos); // 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 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; // Send false if the tile isn't walkable - if(!t.tileWalkable) { + if((!t.tileWalkable) && (!crossUnWalkable)) { 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; // Send false if the tile isn't walkable - if(!t.tileWalkable) { + if((!t.tileWalkable) && (!crossUnWalkable)) { return false; } // Check the tiles hitbox if the tile is solid - if(t.tileSolid) + 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) diff --git a/src/shootergame/entity/EntityTnt.java b/src/shootergame/entity/EntityTnt.java index e19caaf..0e361da 100644 --- a/src/shootergame/entity/EntityTnt.java +++ b/src/shootergame/entity/EntityTnt.java @@ -22,7 +22,7 @@ import shootergame.world.layer.Layer; public class EntityTnt extends EntityVertical { private double height = 0.4; - private Vec3d velocity; + private double velocity_up; private int explode_time; private int explode_radius; @@ -31,9 +31,12 @@ public class EntityTnt extends EntityVertical public EntityTnt(Vec2d pos, double angle, int explode_radius) { 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.explode_radius = explode_radius; + this.crossUnWalkable = true; + this.goThroughSolid = false; // Set to 2.5 seconds this.explode_time = 250; @@ -43,32 +46,19 @@ public class EntityTnt extends EntityVertical public void tick(Chunk chunk, Layer 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 - velocity.z -= 0.001; + height += velocity_up; + velocity_up -= 0.001; - // Reduce the velocty - velocity.x /= 1.01; - velocity.y /= 1.01; - velocity.z /= 1.01; + // Move forwards + moveForward(0.05); // Make the tnt bounce on the ground if(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 explode_time -= 1; if(explode_time < 0) @@ -106,8 +96,23 @@ public class EntityTnt extends EntityVertical (short)blackened_gradient), tpos); if(!fts.tile.unbreakable) l.setFrontTile(Tiles.VOID.getDefaultState(), tpos); - // Summon some blood - l.spawnEntity(new ParticleBlood(rand, new Vec2d(px, py), py)); + boolean killed_entities = false; + + // 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(); } - @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; - } - } diff --git a/src/shootergame/entity/EntityZombie.java b/src/shootergame/entity/EntityZombie.java index 7809c4f..4bb2d0c 100644 --- a/src/shootergame/entity/EntityZombie.java +++ b/src/shootergame/entity/EntityZombie.java @@ -32,6 +32,8 @@ public class EntityZombie extends EntityVertical implements EntityAlive // Set some settings hitbox = 0.5; isSolid = true; + goThroughSolid = false; + crossUnWalkable = false; } @Override diff --git a/src/shootergame/entity/player/EntityPlayer.java b/src/shootergame/entity/player/EntityPlayer.java index fc4c54d..28a97bb 100644 --- a/src/shootergame/entity/player/EntityPlayer.java +++ b/src/shootergame/entity/player/EntityPlayer.java @@ -36,6 +36,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive private Random rand; private double health_max = 1000; private double health = health_max; + public boolean dead = false; public EntityPlayer() { this.angle = 45; @@ -44,6 +45,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive // Set some settings hitbox = 0.5; isSolid = true; + goThroughSolid = false; + crossUnWalkable = false; } @Override @@ -55,7 +58,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive } // Don't tick if the player is dead - if(this.getHealth() < 0) return; + if(dead) return; // Call super 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 public void moveForward() { this.moveForward(0.08); @@ -102,7 +119,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive public void render(Vec2d pos, Camera camera) { // Don't render if the player is dead - if(this.getHealth() < 0) return; + if(dead) return; // Translation GlHelpers.pushMatrix(); @@ -121,6 +138,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive public void fireBullet(double angle) { + if(dead) return; + bullet_frequency += 1; bullet_frequency %= 10; @@ -132,10 +151,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive } } - private boolean throwTnt_last = false; - - public void throwTnt(double angle) - { + public void throwTnt(double angle) { + if(dead) return; Main.world.getLayer().spawnEntity(new EntityTnt(pos.copy(), angle + this.angle, 10)); } diff --git a/src/shootergame/world/chunk/Chunk.java b/src/shootergame/world/chunk/Chunk.java index 2ee8fdb..382cb75 100644 --- a/src/shootergame/world/chunk/Chunk.java +++ b/src/shootergame/world/chunk/Chunk.java @@ -187,7 +187,9 @@ public class Chunk 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); + } } } diff --git a/src/shootergame/world/layer/Layer.java b/src/shootergame/world/layer/Layer.java index 01cd885..d2e6b23 100644 --- a/src/shootergame/world/layer/Layer.java +++ b/src/shootergame/world/layer/Layer.java @@ -143,8 +143,10 @@ public class Layer ArrayList entities = new ArrayList(); Vec2i cpos = getChunkPosFromPos(pos); - for(int x=-1;x<=1;x++) { - for(int y=-1;y<=1;y++) + int scan_distance = (int)distance / Chunk.CHUNK_SIZE.mx + 1; + + 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); 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 ) { // 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