diff --git a/resources/sound/gun0.ogg b/resources/sound/gun0.ogg new file mode 100644 index 0000000..58218af Binary files /dev/null and b/resources/sound/gun0.ogg differ diff --git a/resources/sound/gun1.ogg b/resources/sound/gun1.ogg new file mode 100644 index 0000000..679e2c6 Binary files /dev/null and b/resources/sound/gun1.ogg differ diff --git a/resources/sound/gun2.ogg b/resources/sound/gun2.ogg new file mode 100644 index 0000000..1ec23b7 Binary files /dev/null and b/resources/sound/gun2.ogg differ diff --git a/resources/sound/gun3.ogg b/resources/sound/gun3.ogg new file mode 100644 index 0000000..27f4628 Binary files /dev/null and b/resources/sound/gun3.ogg differ diff --git a/resources/sound/gun.ogg b/resources/sound/gun4.ogg similarity index 58% rename from resources/sound/gun.ogg rename to resources/sound/gun4.ogg index a06d485..50a98da 100644 Binary files a/resources/sound/gun.ogg and b/resources/sound/gun4.ogg differ diff --git a/resources/sound/gun5.ogg b/resources/sound/gun5.ogg new file mode 100644 index 0000000..b551cf4 Binary files /dev/null and b/resources/sound/gun5.ogg differ diff --git a/resources/sound/gun6.ogg b/resources/sound/gun6.ogg new file mode 100644 index 0000000..28917dd Binary files /dev/null and b/resources/sound/gun6.ogg differ diff --git a/resources/sound/gun7.ogg b/resources/sound/gun7.ogg new file mode 100644 index 0000000..bfb7d0e Binary files /dev/null and b/resources/sound/gun7.ogg differ diff --git a/resources/sound/gun8.ogg b/resources/sound/gun8.ogg new file mode 100644 index 0000000..1001b3d Binary files /dev/null and b/resources/sound/gun8.ogg differ diff --git a/resources/sound/gun9.ogg b/resources/sound/gun9.ogg new file mode 100644 index 0000000..0b2004c Binary files /dev/null and b/resources/sound/gun9.ogg differ diff --git a/resources/sound/hit0.ogg b/resources/sound/hit0.ogg new file mode 100644 index 0000000..f8a62d3 Binary files /dev/null and b/resources/sound/hit0.ogg differ diff --git a/resources/sound/hit1.ogg b/resources/sound/hit1.ogg new file mode 100644 index 0000000..780716f Binary files /dev/null and b/resources/sound/hit1.ogg differ diff --git a/resources/sound/hit2.ogg b/resources/sound/hit2.ogg new file mode 100644 index 0000000..807475c Binary files /dev/null and b/resources/sound/hit2.ogg differ diff --git a/resources/texmap.png b/resources/texmap.png index fb2115b..12e79f3 100644 Binary files a/resources/texmap.png and b/resources/texmap.png differ diff --git a/resources/texmap.xcf b/resources/texmap.xcf new file mode 100644 index 0000000..b24f115 Binary files /dev/null and b/resources/texmap.xcf differ diff --git a/src/shootergame/Main.java b/src/shootergame/Main.java index ac62550..28722a5 100644 --- a/src/shootergame/Main.java +++ b/src/shootergame/Main.java @@ -25,6 +25,7 @@ import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec3d; import shootergame.world.World; import shootergame.world.chunk.ChunkEventHandler; +import shootergame.world.layer.layergen.LayerGenCaves; import shootergame.world.layer.layergen.LayerGenEarth; public class Main @@ -69,7 +70,7 @@ public class Main JoystickCallback.JOYSTICK_CALLBACK.init(); // Create the world - world = new World(new Random(), new LayerGenEarth()); + world = new World(new Random(), new LayerGenEarth(), new LayerGenCaves()); // Initialise the entities mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER); diff --git a/src/shootergame/Test.java b/src/shootergame/Test.java index 950766a..e8aa19d 100644 --- a/src/shootergame/Test.java +++ b/src/shootergame/Test.java @@ -57,7 +57,7 @@ public class Test alBufferData(bufferPointer, format, rawAudioBuffer, sampleRate); //Free the memory allocated by STB - free(rawAudioBuffer); + //free(rawAudioBuffer); while(true) { diff --git a/src/shootergame/audio/AudioObject.java b/src/shootergame/audio/AudioObject.java index 072b8e6..40a364f 100644 --- a/src/shootergame/audio/AudioObject.java +++ b/src/shootergame/audio/AudioObject.java @@ -69,8 +69,8 @@ public class AudioObject alBufferData(bufferPointer, format, audio, sample_rate); // Free some c buffers - LibCStdlib.free(audio); - LibCStdlib.free(resource_buffer); + //LibCStdlib.free(audio); + //LibCStdlib.free(resource_buffer); } public void play(Vec3d pos, double volume) @@ -78,11 +78,19 @@ public class AudioObject // Get the player pos Vec2d p_pos = Main.player.pos; - // Calculate the position - double x = ( pos.x - p_pos.x ) * Math.sin(Math.toRadians(Main.player.angle)); - double y = ( pos.y - p_pos.y ) * Math.cos(Math.toRadians(Main.player.angle)); + // Convert the angle to radians + double angle_r = Math.toRadians(Main.player.angle + 90); + + // Calculate the translation + double x = ( pos.x - p_pos.x ); + double y = ( pos.y - p_pos.y ); double z = pos.z; + // Calculate the rotation + Vec2d rotated = MathHelpers.rotate2(new Vec2d(x, y), angle_r); + x = rotated.x; + y = rotated.y; + // Play the sound with a new source int source = AudioSources.getSource(); alSourcei(source, AL_BUFFER, bufferPointer); diff --git a/src/shootergame/audio/AudioRandom.java b/src/shootergame/audio/AudioRandom.java new file mode 100644 index 0000000..9b60259 --- /dev/null +++ b/src/shootergame/audio/AudioRandom.java @@ -0,0 +1,29 @@ +package shootergame.audio; + +import java.util.Random; + +import shootergame.resources.Resource; +import shootergame.util.math.vec.Vec3d; + +public class AudioRandom extends AudioObject +{ + private AudioObject[] audioObjects; + private static Random rand = new Random(); + + public AudioRandom(AudioObject ... audioObjects) { + super(null); + + // Set the specified parameters + this.audioObjects = audioObjects; + } + + @Override + public void init() { + } + + @Override + public void play(Vec3d pos, double volume) { + audioObjects[(int)(rand.nextDouble()*audioObjects.length)].play(pos, volume); + } + +} diff --git a/src/shootergame/display/Camera.java b/src/shootergame/display/Camera.java index 3f82d1b..590d9ad 100644 --- a/src/shootergame/display/Camera.java +++ b/src/shootergame/display/Camera.java @@ -11,6 +11,8 @@ public class Camera public int renderDistance; public double cameraDistance; + public static Camera camera; + public Camera(Vec3d pos, Vec2d angle, double cameraDistance, int renderDistance) { this.angle = new Vec2d(angle.x, -angle.y); diff --git a/src/shootergame/display/DisplayRender.java b/src/shootergame/display/DisplayRender.java index 5c597c1..f449748 100644 --- a/src/shootergame/display/DisplayRender.java +++ b/src/shootergame/display/DisplayRender.java @@ -69,6 +69,7 @@ public class DisplayRender EntityPlayer player = Main.player; Camera camera = new Camera(new Vec3d(player.pos.x, player.pos.y, 0), new Vec2d(player.angle, 45), 10, 2); + Camera.camera = camera; //GlHelpers.translate(0, 0, -5); GlHelpers.rotate(camera.angle.y, 1, 0, 0); diff --git a/src/shootergame/display/transparent/ITransparentObject.java b/src/shootergame/display/transparent/ITransparentObject.java index fe627be..f8bbe0c 100644 --- a/src/shootergame/display/transparent/ITransparentObject.java +++ b/src/shootergame/display/transparent/ITransparentObject.java @@ -6,6 +6,6 @@ import shootergame.util.math.vec.Vec2d; public interface ITransparentObject { public boolean isOpaqueTile(); - public void render(Vec2d pos, Camera camera); + public void render(Vec2d pos, Camera camera, short meta); public Vec2d getRenderOffset(); } diff --git a/src/shootergame/display/transparent/TransparentObject.java b/src/shootergame/display/transparent/TransparentObject.java index 5da7c5d..c12e15a 100644 --- a/src/shootergame/display/transparent/TransparentObject.java +++ b/src/shootergame/display/transparent/TransparentObject.java @@ -9,11 +9,13 @@ class TransparentObject double distance; ITransparentObject object; Vec2d pos; + short meta; - TransparentObject(ITransparentObject object, Camera camera, Vec2d pos) { + TransparentObject(ITransparentObject object, Camera camera, Vec2d pos, short meta) { Vec2d offset = object.getRenderOffset(); this.distance = camera.pos.distance(new Vec3d(offset.x + pos.x, offset.y + pos.y, 0)); this.object = object; this.pos = pos; + this.meta = meta; } } \ No newline at end of file diff --git a/src/shootergame/display/transparent/TransparentObjects.java b/src/shootergame/display/transparent/TransparentObjects.java index e92765d..6fb235a 100644 --- a/src/shootergame/display/transparent/TransparentObjects.java +++ b/src/shootergame/display/transparent/TransparentObjects.java @@ -3,6 +3,7 @@ package shootergame.display.transparent; import java.util.ArrayList; import shootergame.display.Camera; +import shootergame.tiles.TileBlackened; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec3d; @@ -14,9 +15,9 @@ public class TransparentObjects objects.clear(); } - public static void register(ITransparentObject object, Camera camera, Vec2d pos) + public static void register(ITransparentObject object, Camera camera, Vec2d pos, short meta) { - TransparentObject r_to = new TransparentObject(object, camera, pos); + TransparentObject r_to = new TransparentObject(object, camera, pos, meta); ArrayList objects_n = new ArrayList(); boolean added = false; @@ -42,7 +43,7 @@ public class TransparentObjects { // Loop over the objects and render all of them for(TransparentObject to : objects) { - to.object.render(to.pos, camera); + to.object.render(to.pos, camera, to.meta); } } } diff --git a/src/shootergame/entity/Entity.java b/src/shootergame/entity/Entity.java index 6bd492e..b5b3701 100644 --- a/src/shootergame/entity/Entity.java +++ b/src/shootergame/entity/Entity.java @@ -9,6 +9,7 @@ import shootergame.display.transparent.TransparentObjects; import shootergame.init.Entities; import shootergame.tiles.Tile; import shootergame.util.math.MathHelpers; +import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec3d; @@ -24,6 +25,9 @@ public class Entity implements ITransparentObject public double hitbox = 1; public boolean isSolid = false; public Chunk chunk; + private double speed = 1; + private TileState tile_front; + private TileState tile_back; public Entity(Vec2d pos, double angle) { @@ -40,16 +44,35 @@ public class Entity implements ITransparentObject } public void tick(Chunk chunk, Layer layer) { + speed = 1; + angle = MathHelpers.floor(angle); + Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); + tile_back = layer.getBackTile(tpos); + tile_front = layer.getFrontTile(tpos); + + if(this.isSolid) + { + this.addSlowness(tile_back.tile.slowness); + this.addSlowness(tile_front.tile.slowness); + } + } + + public void addSlowness(double amount) { + speed *= (1 - amount); + } + + public void render(Vec2d pos, Camera camera) { } @Override - public void render(Vec2d pos, Camera camera) { + public void render(Vec2d pos, Camera camera, short meta) { + this.render(pos, camera); } public void doRender(Vec2d pos, Camera camera) { if(this.opaqueTile) { - TransparentObjects.register(this, camera, pos); + TransparentObjects.register(this, camera, pos, (short)0); } else { @@ -63,15 +86,25 @@ public class Entity implements ITransparentObject } public void moveForward(double speed) { - Vec2d pos = this.pos.add(MathHelpers.moveTowards2(speed, Math.toRadians(this.angle))); - 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; + this.moveTowards(0, speed); } public void moveBackward(double speed) { - Vec2d pos = this.pos.add(MathHelpers.moveTowards2(-speed, Math.toRadians(this.angle))); + this.moveTowards(0, -speed); + } + + public void moveTowards(double angle, double speed) + { + // Calculate the new position + speed *= this.speed; + Vec2d pos = this.pos.add(MathHelpers.moveTowards2(speed, Math.toRadians(this.angle + angle))); + + // 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(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 moveForward() { @@ -82,17 +115,43 @@ public class Entity implements ITransparentObject this.moveBackward(0.1); } + public void moveTowards(double angle) { + moveTowards(angle, 0.1); + } + public void kill() { chunk.killEntity(this); } - public void activateSteppedOnBlocks() + public void activateTile() { + // Get the tile position and the layer + Layer layer = Main.world.getLayer(); + Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); + + // Activate both tiles + tile_front.tile.onActivated(chunk, layer, tpos, this, tile_front.meta); + tile_back.tile.onActivated(chunk, layer, tpos, this, tile_back.meta); + } + + public void activateSteppedOnTile() + { + // Get the tile position and the layer + Layer layer = Main.world.getLayer(); + Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); + + // Activate both tiles + tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front.meta); + tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back.meta); } public boolean moveIsLegal(Vec2d pos) { + Vec2i t_pos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); + tile_back = Main.world.getLayer().getBackTile(t_pos); + tile_front = Main.world.getLayer().getFrontTile(t_pos); + // Is this entity solid if(isSolid) { @@ -104,17 +163,17 @@ public class Entity implements ITransparentObject { // Get the tile - Tile t = l.getBackTile(tpos); + Tile t = tile_back.tile; // Send false if the tile isn't walkable if(!t.tileWalkable) { return false; - } + } } { // Get the front tile - Tile t = l.getFrontTile(tpos); + Tile t = tile_front.tile; // Send false if the tile isn't walkable if(!t.tileWalkable) { diff --git a/src/shootergame/entity/EntityBullet.java b/src/shootergame/entity/EntityBullet.java index fb540f0..0d5b726 100644 --- a/src/shootergame/entity/EntityBullet.java +++ b/src/shootergame/entity/EntityBullet.java @@ -5,9 +5,11 @@ import java.util.Random; import shootergame.display.Camera; import shootergame.entity.particle.ParticleBlood; import shootergame.init.Sounds; +import shootergame.init.Tiles; import shootergame.tiles.Tile; import shootergame.util.gl.GlHelpers; import shootergame.util.math.MathHelpers; +import shootergame.util.math.TileState; import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; @@ -46,12 +48,19 @@ public class EntityBullet extends EntityParticle // Get the position of the tile the bullet is over Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); - // Get the foreground tile - Tile tile = chunk.getFrontTile(tpos); + // Get the foreground tile and the background tile + TileState tile_f = chunk.getFrontTile(tpos); + TileState tile_b = chunk.getBackTile(tpos); // Is the tile solid and has the bullet crashed into it - if(tile.tileSolid) { - if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile.tileHitbox) + if(tile_f.tile.tileSolid) { + if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_f.tile.tileHitbox) + { + // Delete the bullet + kill(); + } + } if(tile_b.tile.tileSolid) { + if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_b.tile.tileHitbox) { // Delete the bullet kill(); @@ -73,6 +82,9 @@ public class EntityBullet extends EntityParticle chunk.spawnEntity(new ParticleBlood(rand, pos.copy(), angle)); } + // Play the hit noise + Sounds.HIT.play(new Vec3d(pos.x, pos.y, 0.4), 1); + // Harm the entity ea.removeHealth(10); diff --git a/src/shootergame/entity/EntityParticle.java b/src/shootergame/entity/EntityParticle.java index c8f4f34..4b63c9e 100644 --- a/src/shootergame/entity/EntityParticle.java +++ b/src/shootergame/entity/EntityParticle.java @@ -1,8 +1,11 @@ package shootergame.entity; +import shootergame.Main; import shootergame.display.Camera; import shootergame.util.gl.GlHelpers; import shootergame.util.math.vec.Vec2d; +import shootergame.world.chunk.Chunk; +import shootergame.world.layer.Layer; public class EntityParticle extends Entity { @@ -21,6 +24,14 @@ public class EntityParticle extends Entity this.size = size; } + @Override + public void tick(Chunk chunk, Layer layer) { + 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(); + } + @Override public void render(Vec2d pos, Camera camera) { diff --git a/src/shootergame/entity/EntityTnt.java b/src/shootergame/entity/EntityTnt.java index 1ee34d2..e19caaf 100644 --- a/src/shootergame/entity/EntityTnt.java +++ b/src/shootergame/entity/EntityTnt.java @@ -1,6 +1,167 @@ package shootergame.entity; +import java.util.Random; + +import shootergame.Main; +import shootergame.display.Camera; +import shootergame.entity.particle.ParticleBlood; +import shootergame.entity.particle.ParticleSpark; +import shootergame.init.Textures; +import shootergame.init.Tiles; +import shootergame.tiles.TileBlackened; +import shootergame.tiles.TileStone; +import shootergame.util.gl.GlHelpers; +import shootergame.util.math.MathHelpers; +import shootergame.util.math.TileState; +import shootergame.util.math.vec.Vec2d; +import shootergame.util.math.vec.Vec2i; +import shootergame.util.math.vec.Vec3d; +import shootergame.world.chunk.Chunk; +import shootergame.world.layer.Layer; + public class EntityTnt extends EntityVertical { - + private double height = 0.4; + private Vec3d velocity; + private int explode_time; + private int explode_radius; + + private Random rand = new Random(); + + 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))); + this.pos = pos; + this.explode_radius = explode_radius; + + // Set to 2.5 seconds + this.explode_time = 250; + } + + @Override + 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; + + // Reduce the velocty + velocity.x /= 1.01; + velocity.y /= 1.01; + velocity.z /= 1.01; + + // Make the tnt bounce on the ground + if(height < 0) { + height = 0; + velocity.z = -velocity.z; + } + + // 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) + { + // Loop over the tiles around the tnt + for(int ex=-explode_radius;ex blackened_gradient) blackened_gradient = bts.meta; + } + + // Set the tiles + if(!bts.tile.unbreakable) l.setBackTile(new TileState(Tiles.STONE, + (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)); + } + } + } + + // Delete the entity + kill(); + return; + } + + // Create sparks + chunk.spawnEntity(new ParticleSpark(pos.copy(), height)); + } + + @Override + public void render(Vec2d pos, Camera camera) + { + // Render the tnt with the height + GlHelpers.pushMatrix(); + GlHelpers.translate(0, 0, height); + super.render(pos, camera); + 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 265fced..7809c4f 100644 --- a/src/shootergame/entity/EntityZombie.java +++ b/src/shootergame/entity/EntityZombie.java @@ -44,7 +44,7 @@ public class EntityZombie extends EntityVertical implements EntityAlive // Move forward towards the player this.angle = Math.toDegrees(angle) + 180; this.angle += noise_movement.eval(time, 0)*60; - this.moveForward(0.05); + this.moveForward(); if(noise_gun_fire.eval(time, 0) > 0) { @@ -64,7 +64,16 @@ public class EntityZombie extends EntityVertical implements EntityAlive // Increase time time += 0.001; - + } + + @Override + public void moveForward() { + this.moveForward(0.06); + } + + @Override + public void moveBackward(double speed) { + super.moveBackward(0.06); } @Override diff --git a/src/shootergame/entity/particle/ParticleSpark.java b/src/shootergame/entity/particle/ParticleSpark.java index d3bb730..04ffa93 100644 --- a/src/shootergame/entity/particle/ParticleSpark.java +++ b/src/shootergame/entity/particle/ParticleSpark.java @@ -9,10 +9,12 @@ import shootergame.world.layer.Layer; public class ParticleSpark extends EntityParticle { - private double size = 1; + private double size = 0.1; - public ParticleSpark(int height) { - super(1, height); + public ParticleSpark(Vec2d pos, double height) { + super(1, height+0.4); + this.pos = pos; + this.opaqueTile = false; } @Override @@ -20,7 +22,7 @@ public class ParticleSpark extends EntityParticle super.tick(chunk, layer); // Reduce the size - size -= 0.01; + size -= 0.004; setSize(size); // Is the size zero @@ -35,10 +37,12 @@ public class ParticleSpark extends EntityParticle public void render(Vec2d pos, Camera camera) { // Set some settings + GlHelpers.pushMatrix(); GlHelpers.color3(1, 1, 0); // Call super super.render(pos, camera); + GlHelpers.popMatrix(); } } diff --git a/src/shootergame/entity/particle/ParticleWater.java b/src/shootergame/entity/particle/ParticleWater.java new file mode 100644 index 0000000..4cd68f3 --- /dev/null +++ b/src/shootergame/entity/particle/ParticleWater.java @@ -0,0 +1,57 @@ +package shootergame.entity.particle; + +import java.util.Random; + +import shootergame.display.Camera; +import shootergame.entity.EntityParticle; +import shootergame.util.gl.GlHelpers; +import shootergame.util.math.MathHelpers; +import shootergame.util.math.random.RandomHelpers; +import shootergame.util.math.vec.Vec2d; +import shootergame.util.math.vec.Vec3d; +import shootergame.world.chunk.Chunk; +import shootergame.world.layer.Layer; + +public class ParticleWater extends EntityParticle +{ + private static Random rand = new Random(); + private Vec3d velocity; + private double height = 0; + + public ParticleWater(Vec2d pos) { + super(rand.nextDouble()/5, 0); + + // Set the velocity + velocity = MathHelpers.moveTowards3(0.1, new Vec2d(Math.toRadians( + RandomHelpers.randrange(rand, 360)), Math.toRadians(RandomHelpers.randrange(rand, 0, 45)))); + + this.pos = pos; + } + + @Override + public void tick(Chunk chunk, Layer layer) { + super.tick(chunk, layer); + + // Add the velocity + velocity.z -= 0.005; + pos.x += velocity.x; + pos.y += velocity.y; + height += velocity.z; + + // Is the height below 0; destroy this particle + if(height < 0) { + kill(); + } + } + + @Override + public void render(Vec2d pos, Camera camera) { + GlHelpers.pushMatrix(); + GlHelpers.translate(0, 0, height); + GlHelpers.color4(0, 0, 1, 0.4); + super.render(pos, camera); + GlHelpers.color4(1, 1, 1, 1); + GlHelpers.popMatrix(); + } + +} diff --git a/src/shootergame/entity/player/EntityPlayer.java b/src/shootergame/entity/player/EntityPlayer.java index 0bda498..fc4c54d 100644 --- a/src/shootergame/entity/player/EntityPlayer.java +++ b/src/shootergame/entity/player/EntityPlayer.java @@ -8,9 +8,11 @@ import shootergame.display.Camera; import shootergame.entity.Entity; import shootergame.entity.EntityAlive; import shootergame.entity.EntityBullet; +import shootergame.entity.EntityTnt; import shootergame.entity.EntityVertical; import shootergame.init.Sounds; import shootergame.init.Textures; +import shootergame.util.gl.GlHelpers; import shootergame.util.gl.texture.TextureReference; import shootergame.util.math.MathHelpers; import shootergame.util.math.vec.Vec2d; @@ -28,6 +30,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive public boolean GUN = false; public boolean moving = false; + public double height = 0; + private int bullet_frequency = 0; private Random rand; private double health_max = 1000; @@ -84,18 +88,35 @@ public class EntityPlayer extends EntityVertical implements EntityAlive } } + @Override + public void moveForward() { + this.moveForward(0.08); + } + + @Override + public void moveBackward(double speed) { + super.moveBackward(0.08); + } + @Override public void render(Vec2d pos, Camera camera) { // Don't render if the player is dead if(this.getHealth() < 0) return; + // Translation + GlHelpers.pushMatrix(); + GlHelpers.translate(0, 0, height); + // Moving if(MOVE_BACKWARD || MOVE_FORWARD || moving) super.render(pos, camera, Textures.ENTITY_PLAYER_MOVING, 1); // Standing still else super.render(pos, camera, Textures.ENTITY_PLAYER_STILL, 1); + + // Pop the matrix + GlHelpers.popMatrix(); } public void fireBullet(double angle) @@ -107,8 +128,16 @@ public class EntityPlayer extends EntityVertical implements EntityAlive { // Summon bullets at this angle relative to the player Main.world.getLayer().spawnEntity(new EntityBullet(rand, pos.copy(), this, angle + this.angle)); + //throwTnt(angle); } } + + private boolean throwTnt_last = false; + + public void throwTnt(double angle) + { + Main.world.getLayer().spawnEntity(new EntityTnt(pos.copy(), angle + this.angle, 10)); + } @Override public void addHealth(double amount) { diff --git a/src/shootergame/init/Resources.java b/src/shootergame/init/Resources.java index 76cf101..93c7a2c 100644 --- a/src/shootergame/init/Resources.java +++ b/src/shootergame/init/Resources.java @@ -7,9 +7,37 @@ public class Resources public static void loadResources() { TEXMAP_PNG.load(); - GUN_OGG.load(); + + GUN_OGG_0.load(); + GUN_OGG_1.load(); + GUN_OGG_2.load(); + GUN_OGG_3.load(); + GUN_OGG_4.load(); + GUN_OGG_5.load(); + GUN_OGG_6.load(); + GUN_OGG_7.load(); + GUN_OGG_8.load(); + GUN_OGG_9.load(); + + HIT_OGG_0.load(); + HIT_OGG_1.load(); + HIT_OGG_2.load(); } public static final Resource TEXMAP_PNG = new Resource("texmap.png"); - public static final Resource GUN_OGG = new Resource("sound/gun.ogg"); + + public static final Resource GUN_OGG_0 = new Resource("sound/gun0.ogg"); + public static final Resource GUN_OGG_1 = new Resource("sound/gun1.ogg"); + public static final Resource GUN_OGG_2 = new Resource("sound/gun2.ogg"); + public static final Resource GUN_OGG_3 = new Resource("sound/gun3.ogg"); + public static final Resource GUN_OGG_4 = new Resource("sound/gun4.ogg"); + public static final Resource GUN_OGG_5 = new Resource("sound/gun5.ogg"); + public static final Resource GUN_OGG_6 = new Resource("sound/gun6.ogg"); + public static final Resource GUN_OGG_7 = new Resource("sound/gun7.ogg"); + public static final Resource GUN_OGG_8 = new Resource("sound/gun8.ogg"); + public static final Resource GUN_OGG_9 = new Resource("sound/gun9.ogg"); + + public static final Resource HIT_OGG_0 = new Resource("sound/hit0.ogg"); + public static final Resource HIT_OGG_1 = new Resource("sound/hit1.ogg"); + public static final Resource HIT_OGG_2 = new Resource("sound/hit2.ogg"); } diff --git a/src/shootergame/init/Sounds.java b/src/shootergame/init/Sounds.java index 542ea46..b82c7b6 100644 --- a/src/shootergame/init/Sounds.java +++ b/src/shootergame/init/Sounds.java @@ -1,13 +1,47 @@ package shootergame.init; import shootergame.audio.AudioObject; +import shootergame.audio.AudioRandom; public class Sounds { public static void init() { - GUN.init(); + GUN_0.init(); + GUN_1.init(); + GUN_2.init(); + GUN_3.init(); + GUN_4.init(); + GUN_5.init(); + GUN_6.init(); + GUN_7.init(); + GUN_8.init(); + GUN_9.init(); + + HIT_0.init(); + HIT_1.init(); + HIT_2.init(); } - public static final AudioObject GUN = new AudioObject(Resources.GUN_OGG); + public static final AudioObject GUN_0 = new AudioObject(Resources.GUN_OGG_0); + public static final AudioObject GUN_1 = new AudioObject(Resources.GUN_OGG_1); + public static final AudioObject GUN_2 = new AudioObject(Resources.GUN_OGG_2); + public static final AudioObject GUN_3 = new AudioObject(Resources.GUN_OGG_3); + public static final AudioObject GUN_4 = new AudioObject(Resources.GUN_OGG_4); + public static final AudioObject GUN_5 = new AudioObject(Resources.GUN_OGG_5); + public static final AudioObject GUN_6 = new AudioObject(Resources.GUN_OGG_6); + public static final AudioObject GUN_7 = new AudioObject(Resources.GUN_OGG_7); + public static final AudioObject GUN_8 = new AudioObject(Resources.GUN_OGG_8); + public static final AudioObject GUN_9 = new AudioObject(Resources.GUN_OGG_9); + + public static final AudioObject GUN = new AudioRandom( + GUN_0,GUN_1,GUN_2,GUN_3,GUN_4, + GUN_5,GUN_6,GUN_7,GUN_8,GUN_9); + + public static final AudioObject HIT_0 = new AudioObject(Resources.HIT_OGG_0); + public static final AudioObject HIT_1 = new AudioObject(Resources.HIT_OGG_1); + public static final AudioObject HIT_2 = new AudioObject(Resources.HIT_OGG_2); + + public static final AudioObject HIT = new AudioRandom( + HIT_0, HIT_1, HIT_2); } diff --git a/src/shootergame/init/Textures.java b/src/shootergame/init/Textures.java index dbc9e19..70e9224 100644 --- a/src/shootergame/init/Textures.java +++ b/src/shootergame/init/Textures.java @@ -31,6 +31,11 @@ public class Textures public static final TextureReference TILE_DIRT = texmap.getTextureReference(3, 4, 0, 1); public static final TextureReference TILE_TREE = texmap.getTextureReference(4, 5, 0, 4); public static final TextureReference TILE_ROCK = texmap.getTextureReference(4, 5, 4, 5); + public static final TextureReference ENTITY_TNT = texmap.getTextureReference(4, 5, 5, 6); + public static final TextureReference TILE_LADDER = texmap.getTextureReference(3, 4, 4, 5); + public static final TextureReference TILE_PORTAL = texmap.getTextureReference(3, 4, 5, 6); + public static final TextureReference TILE_WALL = texmap.getTextureReference(2, 3, 5, 6); + public static final TextureReference TILE_LADDER_UP = texmap.getTextureReference(16, 17, 0, 16); // Fire public static final TextureReference TILE_FIRE_0 = texmap.getTextureReference(0, 1, 1, 2); @@ -58,7 +63,7 @@ public class Textures ); // Water - public static final TextureReference TILE_WATER = new AnimationReference(20, + public static final TextureReference TILE_WATER = new AnimationReference(10, texmap.getTextureReference(0, 1, 8, 9), texmap.getTextureReference(1, 2, 8, 9), texmap.getTextureReference(2, 3, 8, 9), @@ -78,7 +83,7 @@ public class Textures ); // Lava - public static final TextureReference TILE_LAVA = new AnimationReference(10, + public static final TextureReference TILE_LAVA = new AnimationReference(20, texmap.getTextureReference(0, 1, 6, 7), texmap.getTextureReference(1, 2, 6, 7), texmap.getTextureReference(2, 3, 6, 7), diff --git a/src/shootergame/init/Tiles.java b/src/shootergame/init/Tiles.java index 06f0586..e899194 100644 --- a/src/shootergame/init/Tiles.java +++ b/src/shootergame/init/Tiles.java @@ -1,16 +1,21 @@ package shootergame.init; import shootergame.tiles.Tile; +import shootergame.tiles.TileBlackened; import shootergame.tiles.TileDirt; import shootergame.tiles.TileFire; import shootergame.tiles.TileGrass; +import shootergame.tiles.TileLadder; +import shootergame.tiles.TileLadderUp; import shootergame.tiles.TileLava; import shootergame.tiles.TileLavaFlow; +import shootergame.tiles.TilePortalDown; import shootergame.tiles.TileRock; import shootergame.tiles.TileSand; import shootergame.tiles.TileStone; import shootergame.tiles.TileTree; import shootergame.tiles.TileVoid; +import shootergame.tiles.TileWall; import shootergame.tiles.TileWater; import shootergame.tiles.TileWaterFlow; @@ -28,4 +33,9 @@ public class Tiles public static final Tile WATER = new TileWater("water"); public static final Tile LAVA_FLOW = new TileLavaFlow("lava_flow"); public static final Tile WATER_FLOW = new TileWaterFlow("water_flow"); + public static final Tile BLACKENED = new TileBlackened("blackened"); + 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 final Tile LADDER_UP = new TileLadderUp("ladder_up"); } diff --git a/src/shootergame/input/JoystickCallback.java b/src/shootergame/input/JoystickCallback.java index 0ade695..4e2b29a 100644 --- a/src/shootergame/input/JoystickCallback.java +++ b/src/shootergame/input/JoystickCallback.java @@ -14,6 +14,9 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask { public static final JoystickCallback JOYSTICK_CALLBACK = new JoystickCallback(); private ArrayList connections = new ArrayList(); + + private static boolean throwTnt_last = false; + private static boolean activate_last = false; @Override public void invoke(int jid, int event) @@ -73,15 +76,13 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask private float combineJoystickAxis(float a, float b) { - if(b > 0.2 || b < -0.2) a += b; + if(b > 0.3 || b < -0.3) a += b; return a; } @Override public void MainLoopUpdate() { - - // Gamepad properties float left_x = 0; float left_y = 0; @@ -147,9 +148,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask double angle = Math.toDegrees(Math.atan2(left_y, left_x)) + 90; // Move the player in the left sticks angle - Main.player.angle += angle; - Main.player.moveForward(); - Main.player.angle -= angle; + Main.player.moveTowards(angle); // Set the players moving to true Main.player.moving = true; @@ -160,6 +159,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask // Is the right x axis stick moved into a position (camera stick) if(right_x > 0.3 || right_x < -0.3) { + System.out.println("Angle changed"); Main.player.angle += right_x; } @@ -168,6 +168,19 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask Main.player.fireBullet(0); } + // Tnt trigger + if(left_trigger > 0.3) { + if(!throwTnt_last) + { + throwTnt_last = true; + Main.player.throwTnt(0); + } + } + + else { + throwTnt_last = false; + } + if(dpad_up) { Main.player.fireBullet(0); } @@ -183,6 +196,18 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask if(dpad_right) { Main.player.fireBullet(90); } + + // Activate block + if(button_x) { + if(!activate_last) { + Main.player.activateTile(); + activate_last = true; + } + } + + else if(activate_last) { + activate_last = false; + } } } diff --git a/src/shootergame/tiles/Tile.java b/src/shootergame/tiles/Tile.java index 1b3b2c9..53ff6fb 100644 --- a/src/shootergame/tiles/Tile.java +++ b/src/shootergame/tiles/Tile.java @@ -5,6 +5,7 @@ import shootergame.display.transparent.ITransparentObject; import shootergame.display.transparent.TransparentObjects; import shootergame.entity.Entity; import shootergame.entity.player.EntityPlayer; +import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec3d; @@ -18,6 +19,8 @@ public class Tile implements ITransparentObject public boolean tileSolid = false; public boolean tileWalkable = true; public double tileHitbox = 0; + public double slowness = 0; + public boolean unbreakable = false; public Tile(String id) { this.id = id; @@ -28,17 +31,17 @@ public class Tile implements ITransparentObject } @Override - public void render(Vec2d pos, Camera camera) { + public void render(Vec2d pos, Camera camera, short meta) { } - public void doRender(Vec2d pos, Camera camera) + public void doRender(Vec2d pos, Camera camera, short meta) { if(this.opaqueTile) { - TransparentObjects.register(this, camera, pos); + TransparentObjects.register(this, camera, pos, meta); } else { - this.render(pos, camera); + this.render(pos, camera, meta); } } @@ -47,11 +50,18 @@ public class Tile implements ITransparentObject return this.opaqueTile; } - public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity) { + public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, short meta) { } @Override public Vec2d getRenderOffset() { return new Vec2d(0.5, 0.5); } + + public TileState getDefaultState() { + return new TileState(this, (short)0); + } + + public void onActivated(Chunk chunk, Layer layer, Vec2i tpos, Entity entity, short meta) { + } } diff --git a/src/shootergame/tiles/TileBlackened.java b/src/shootergame/tiles/TileBlackened.java new file mode 100644 index 0000000..ab29fdd --- /dev/null +++ b/src/shootergame/tiles/TileBlackened.java @@ -0,0 +1,39 @@ +package shootergame.tiles; + +import shootergame.display.Camera; +import shootergame.util.gl.GlHelpers; +import shootergame.util.gl.texture.TextureReference; +import shootergame.util.math.vec.Vec2d; + +public class TileBlackened extends Tile +{ + + public TileBlackened(String id) { + super(id); + //this.opaqueTile = true; + } + + @Override + public void render(Vec2d pos, Camera camera, short meta) + { + //System.out.println("META: "+ (int)meta); + + // Call super + super.render(pos, camera, meta); + + // Set the colour + GlHelpers.color4(0, 0, 0, ((double)meta) / Short.MAX_VALUE); + + // Draw the tile + GlHelpers.begin(); + GlHelpers.vertex3(pos.x+0, pos.y+0, 0.001); + GlHelpers.vertex3(pos.x+1, pos.y+0, 0.001); + GlHelpers.vertex3(pos.x+1, pos.y+1, 0.001); + GlHelpers.vertex3(pos.x+0, pos.y+1, 0.001); + GlHelpers.end(); + + // Reset the colour + GlHelpers.color4(1, 1, 1, 1); + } + +} diff --git a/src/shootergame/tiles/TileFlat.java b/src/shootergame/tiles/TileFlat.java index 9821c92..b1d2f2d 100644 --- a/src/shootergame/tiles/TileFlat.java +++ b/src/shootergame/tiles/TileFlat.java @@ -18,10 +18,10 @@ public class TileFlat extends Tile } @Override - public void render(Vec2d pos, Camera camera) + public void render(Vec2d pos, Camera camera, short meta) { // Call super - super.render(pos, camera); + super.render(pos, camera, meta); // Render the tile GlHelpers.begin(); diff --git a/src/shootergame/tiles/TileLadder.java b/src/shootergame/tiles/TileLadder.java new file mode 100644 index 0000000..001ac8c --- /dev/null +++ b/src/shootergame/tiles/TileLadder.java @@ -0,0 +1,18 @@ +package shootergame.tiles; + +import shootergame.init.Textures; +import shootergame.util.gl.texture.TextureReference; + +public class TileLadder extends TileVertical +{ + + public TileLadder(String id) { + super(id, Textures.TILE_LADDER, 1); + + this.opaqueTile = true; + this.tileSolid = true; + this.tileHitbox = 0.3; + this.unbreakable = true; + } + +} diff --git a/src/shootergame/tiles/TileLadderUp.java b/src/shootergame/tiles/TileLadderUp.java new file mode 100644 index 0000000..9cd1a30 --- /dev/null +++ b/src/shootergame/tiles/TileLadderUp.java @@ -0,0 +1,88 @@ +package shootergame.tiles; + +import mainloop.task.IMainloopTask; +import shootergame.Main; +import shootergame.entity.Entity; +import shootergame.entity.player.EntityPlayer; +import shootergame.init.Textures; +import shootergame.util.gl.texture.TextureReference; +import shootergame.util.math.vec.Vec2d; +import shootergame.util.math.vec.Vec2i; +import shootergame.world.chunk.Chunk; +import shootergame.world.layer.Layer; + +public class TileLadderUp extends TileVertical +{ + public TileLadderUp(String id) { + super(id, Textures.TILE_LADDER_UP, 16); + + this.opaqueTile = true; + this.tileSolid = true; + this.tileHitbox = 0.3; + this.unbreakable = true; + } + + @Override + public void onActivated(Chunk chunk, Layer layer, Vec2i pos, Entity entity, short meta) + { + // Call super + super.onWalkedOn(chunk, layer, pos, entity, meta); + + // Is the entity the player + if(entity == Main.player) + { + // Cast to player + EntityPlayer player = (EntityPlayer)entity; + double playerAngle = player.angle; + Vec2d playerPos = player.pos.copy(); + player.height = 0; + + // Register the animation + Main.mainloop.register(new IMainloopTask() { + + int movingPlayer = 0; + + @Override + public void MainLoopUpdate() + { + player.angle = playerAngle; + player.pos = playerPos.copy(); + player.moving = true; + + if(movingPlayer == 0) { + player.height += 0.04; + } + + if(movingPlayer == 1) { + player.height += 0.02; + } + + if(player.height >= 6 && movingPlayer == 0) + { + movingPlayer = 1; + Main.world.setLayerID(meta); + player.height = -1; + } + + if(player.height >= 0 && movingPlayer == 1) + { + movingPlayer = 2; + player.height = 0; + player.moving = false; + } + } + + @Override + public boolean MainLoopRepeat() { + return movingPlayer != 2; + } + + @Override + public boolean MainLoopDelay(long arg0) { + return arg0 > 10; + } + }); + } + } + +} diff --git a/src/shootergame/tiles/TileLava.java b/src/shootergame/tiles/TileLava.java index 28733dc..4033eb2 100644 --- a/src/shootergame/tiles/TileLava.java +++ b/src/shootergame/tiles/TileLava.java @@ -15,10 +15,10 @@ public class TileLava extends TileFlat } @Override - public void render(Vec2d pos, Camera camera) { + public void render(Vec2d pos, Camera camera, short meta) { GlHelpers.pushMatrix(); GlHelpers.translate(0, 0, 0.001); - super.render(pos, camera); + super.render(pos, camera, meta); GlHelpers.popMatrix(); } diff --git a/src/shootergame/tiles/TileLavaFlow.java b/src/shootergame/tiles/TileLavaFlow.java index 59c5dac..1d936be 100644 --- a/src/shootergame/tiles/TileLavaFlow.java +++ b/src/shootergame/tiles/TileLavaFlow.java @@ -13,10 +13,10 @@ public class TileLavaFlow extends TileFlat } @Override - public void render(Vec2d pos, Camera camera) { + public void render(Vec2d pos, Camera camera, short meta) { GlHelpers.pushMatrix(); GlHelpers.translate(0, 0, 0.001); - super.render(pos, camera); + super.render(pos, camera, meta); GlHelpers.popMatrix(); } diff --git a/src/shootergame/tiles/TilePortalDown.java b/src/shootergame/tiles/TilePortalDown.java new file mode 100644 index 0000000..c7ea609 --- /dev/null +++ b/src/shootergame/tiles/TilePortalDown.java @@ -0,0 +1,99 @@ +package shootergame.tiles; + +import mainloop.task.IMainloopTask; +import shootergame.Main; +import shootergame.entity.Entity; +import shootergame.entity.player.EntityPlayer; +import shootergame.init.Textures; +import shootergame.init.Tiles; +import shootergame.util.gl.texture.TextureReference; +import shootergame.util.math.vec.Vec2d; +import shootergame.util.math.vec.Vec2i; +import shootergame.world.chunk.Chunk; +import shootergame.world.layer.Layer; + +public class TilePortalDown extends TileFlat +{ + + public TilePortalDown(String id) { + super(id, Textures.TILE_PORTAL); + + this.unbreakable = true; + } + + @Override + public void onActivated(Chunk chunk, Layer layer, Vec2i pos, Entity entity, short meta) + { + // Call super + super.onWalkedOn(chunk, layer, pos, entity, meta); + + // Is the entity the player + if(entity == Main.player) + { + // Cast to player + EntityPlayer player = (EntityPlayer)entity; + double playerAngle = player.angle; + Vec2d playerPos = player.pos.copy(); + player.height = 0; + + // Register the animation + Main.mainloop.register(new IMainloopTask() { + + int movingPlayer = 0; + + @Override + public void MainLoopUpdate() + { + player.angle = playerAngle; + player.pos = playerPos.copy(); + player.moving = true; + + if(movingPlayer == 0) { + player.height -= 0.02; + } + + if(movingPlayer == 1) { + player.height -= 0.04; + } + + if(player.height < -1 && movingPlayer == 0) + { + movingPlayer = 1; + Main.world.setLayerID(meta); + player.height = 6; + } + + if(player.height < 0 && movingPlayer == 1) + { + movingPlayer = 2; + player.height = 0; + player.moving = false; + + Layer layer = Main.world.getLayer(); + for(int i=0;i<=16;i++) { + if(layer.getBackTile(new Vec2i(pos.x+i, pos.y)).tile != Tiles.STONE) + layer.setBackTile(Tiles.STONE.getDefaultState(), new Vec2i(pos.x+i, pos.y)); + if(layer.getBackTile(new Vec2i(pos.x-i, pos.y)).tile != Tiles.STONE) + layer.setBackTile(Tiles.STONE.getDefaultState(), new Vec2i(pos.x-i, pos.y)); + if(layer.getBackTile(new Vec2i(pos.x, pos.y+i)).tile != Tiles.STONE) + layer.setBackTile(Tiles.STONE.getDefaultState(), new Vec2i(pos.x, pos.y+i)); + if(layer.getBackTile(new Vec2i(pos.x, pos.y-i)).tile != Tiles.STONE) + layer.setBackTile(Tiles.STONE.getDefaultState(), new Vec2i(pos.x, pos.y-i)); + } + } + } + + @Override + public boolean MainLoopRepeat() { + return movingPlayer != 2; + } + + @Override + public boolean MainLoopDelay(long arg0) { + return arg0 > 10; + } + }); + } + } + +} diff --git a/src/shootergame/tiles/TileStone.java b/src/shootergame/tiles/TileStone.java index bd38935..62af1d0 100644 --- a/src/shootergame/tiles/TileStone.java +++ b/src/shootergame/tiles/TileStone.java @@ -1,6 +1,9 @@ package shootergame.tiles; +import shootergame.display.Camera; import shootergame.init.Textures; +import shootergame.util.gl.GlHelpers; +import shootergame.util.math.vec.Vec2d; public class TileStone extends TileFlat { @@ -8,5 +11,12 @@ public class TileStone extends TileFlat public TileStone(String id) { super(id, Textures.TILE_STONE); } + + @Override + public void render(Vec2d pos, Camera camera, short meta) { + GlHelpers.color4(1, 1, 1, (Short.MAX_VALUE - (double)meta) / Short.MAX_VALUE); + super.render(pos, camera, meta); + GlHelpers.color4(1, 1, 1, 1); + } } diff --git a/src/shootergame/tiles/TileVertical.java b/src/shootergame/tiles/TileVertical.java index 5a5d2f9..1b6657d 100644 --- a/src/shootergame/tiles/TileVertical.java +++ b/src/shootergame/tiles/TileVertical.java @@ -23,8 +23,8 @@ public class TileVertical extends Tile } @Override - public void render(Vec2d pos, Camera camera) { - super.render(pos, camera); + public void render(Vec2d pos, Camera camera, short meta) { + super.render(pos, camera, meta); VerticalRender.render(pos, camera, tex, h); } diff --git a/src/shootergame/tiles/TileWall.java b/src/shootergame/tiles/TileWall.java new file mode 100644 index 0000000..b6364aa --- /dev/null +++ b/src/shootergame/tiles/TileWall.java @@ -0,0 +1,17 @@ +package shootergame.tiles; + +import shootergame.init.Textures; +import shootergame.util.gl.texture.TextureReference; + +public class TileWall extends TileFlat +{ + + public TileWall(String id) { + super(id, Textures.TILE_WALL); + + this.tileWalkable = false; + this.tileSolid = true; + this.tileHitbox = 1; + } + +} diff --git a/src/shootergame/tiles/TileWater.java b/src/shootergame/tiles/TileWater.java index e55e570..bed882e 100644 --- a/src/shootergame/tiles/TileWater.java +++ b/src/shootergame/tiles/TileWater.java @@ -1,25 +1,41 @@ package shootergame.tiles; import shootergame.display.Camera; +import shootergame.entity.Entity; +import shootergame.entity.particle.ParticleWater; import shootergame.init.Textures; import shootergame.util.gl.GlHelpers; import shootergame.util.math.vec.Vec2d; +import shootergame.util.math.vec.Vec2i; +import shootergame.world.chunk.Chunk; +import shootergame.world.layer.Layer; public class TileWater extends TileFlat { public TileWater(String id) { super(id, Textures.TILE_WATER); - - this.tileWalkable = false; + this.slowness = 0.5; } @Override - public void render(Vec2d pos, Camera camera) { + public void render(Vec2d pos, Camera camera, short meta) { GlHelpers.pushMatrix(); GlHelpers.translate(0, 0, 0.001); - super.render(pos, camera); + super.render(pos, camera, meta); GlHelpers.popMatrix(); } + + @Override + public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, short meta) + { + // Call super + super.onWalkedOn(chunk, layer, pos, entity, meta); + + // Spawn some water particles + for(int i=0;i<4;i++) { + layer.spawnEntity(new ParticleWater(entity.pos.copy())); + } + } } diff --git a/src/shootergame/tiles/TileWaterFlow.java b/src/shootergame/tiles/TileWaterFlow.java index e73c4b3..3095abf 100644 --- a/src/shootergame/tiles/TileWaterFlow.java +++ b/src/shootergame/tiles/TileWaterFlow.java @@ -13,10 +13,10 @@ public class TileWaterFlow extends TileFlat } @Override - public void render(Vec2d pos, Camera camera) { + public void render(Vec2d pos, Camera camera, short meta) { GlHelpers.pushMatrix(); GlHelpers.translate(0, 0, 0.001); - super.render(pos, camera); + super.render(pos, camera, meta); GlHelpers.popMatrix(); } diff --git a/src/shootergame/util/math/MathHelpers.java b/src/shootergame/util/math/MathHelpers.java index f4f3ecf..93563c5 100644 --- a/src/shootergame/util/math/MathHelpers.java +++ b/src/shootergame/util/math/MathHelpers.java @@ -83,4 +83,16 @@ public class MathHelpers if(a < 0) return -a; else return a; } + + public static Vec2d rotate2(Vec2d pos, double angle) + { + // Get the angle and the distance from the centre to the point + double p_angle = Math.atan2(pos.y, pos.x); + double p_distance = Math.sqrt(pos.y*pos.y + pos.x*pos.x); + + // Return and calculate the new positions + return new Vec2d( + p_distance * Math.sin(angle - p_angle), + p_distance * Math.cos(angle - p_angle)); + } } diff --git a/src/shootergame/util/math/TileState.java b/src/shootergame/util/math/TileState.java new file mode 100644 index 0000000..2206b71 --- /dev/null +++ b/src/shootergame/util/math/TileState.java @@ -0,0 +1,21 @@ +package shootergame.util.math; + +import shootergame.init.Tiles; +import shootergame.tiles.Tile; + +public class TileState +{ + public static final TileState EMPTY = new TileState(Tiles.VOID, (short)0); + + public Tile tile; + public short meta; + + public TileState(Tile tile, short meta) { + this.tile = tile; + this.meta = meta; + } + + public TileState withMeta(short meta) { + return new TileState(tile, meta); + } +} diff --git a/src/shootergame/world/World.java b/src/shootergame/world/World.java index aae786f..03c9ea4 100644 --- a/src/shootergame/world/World.java +++ b/src/shootergame/world/World.java @@ -15,11 +15,13 @@ public class World public World(Random rand, LayerGen ... layergen) { + long seed = rand.nextLong(); + // Loop over the layer generators for(LayerGen lg : layergen) { // Create new layers - layers.add(new Layer(rand, lg)); + layers.add(new Layer(new Random(seed), lg)); } // Set the current layer @@ -44,6 +46,7 @@ public class World public void setLayerID(int id) { layer_id = id; + layer = layers.get(layer_id); } public Layer getLayer() { diff --git a/src/shootergame/world/chunk/Chunk.java b/src/shootergame/world/chunk/Chunk.java index 8c7d42b..2ee8fdb 100644 --- a/src/shootergame/world/chunk/Chunk.java +++ b/src/shootergame/world/chunk/Chunk.java @@ -9,6 +9,7 @@ import shootergame.entity.EntityAlive; import shootergame.init.Tiles; import shootergame.tiles.Tile; import shootergame.util.math.MathHelpers; +import shootergame.util.math.TileState; import shootergame.util.math.range.Range2i; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; @@ -23,6 +24,8 @@ public class Chunk private Tile tiles_back[] = new Tile[CHUNK_INDEX]; private Tile tiles_front[] = new Tile[CHUNK_INDEX]; + private short tiles_front_meta[] = new short[CHUNK_INDEX]; + private short tiles_back_meta[] = new short[CHUNK_INDEX]; public ArrayList entities = new ArrayList(); private Random rand; private Layer layer; @@ -53,8 +56,8 @@ public class Chunk Vec2i t_pos = Vec2i.fromId(CHUNK_SIZE, i); // Render the tiles - tiles_back[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera); - tiles_front[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera); + tiles_back[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera, tiles_back_meta[i]); + tiles_front[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera, tiles_front_meta[i]); } // Render all the entities @@ -116,7 +119,7 @@ public class Chunk } } - public void setBackTile(Tile tile, Vec2i pos) + public void setBackTile(TileState tile, Vec2i pos) { // Get the id Vec2i cpos = new Vec2i(0, 0); @@ -125,10 +128,11 @@ public class Chunk int id = cpos.getId(CHUNK_SIZE); // Set the back tile - this.tiles_back[id] = tile; + this.tiles_back[id] = tile.tile; + this.tiles_back_meta[id] = tile.meta; } - public void setFrontTile(Tile tile, Vec2i pos) + public void setFrontTile(TileState tile, Vec2i pos) { // Get the id Vec2i cpos = new Vec2i(0, 0); @@ -137,10 +141,11 @@ public class Chunk int id = cpos.getId(CHUNK_SIZE); // Set the front tile - this.tiles_front[id] = tile; + this.tiles_front[id] = tile.tile; + this.tiles_front_meta[id] = tile.meta; } - public Tile getBackTile(Vec2i pos) + public TileState getBackTile(Vec2i pos) { // Get the id Vec2i cpos = new Vec2i(0, 0); @@ -149,10 +154,10 @@ public class Chunk int id = cpos.getId(CHUNK_SIZE); // Send back the back tile - return this.tiles_back[id]; + return new TileState(this.tiles_back[id], this.tiles_back_meta[id]); } - public Tile getFrontTile(Vec2i pos) + public TileState getFrontTile(Vec2i pos) { // Get the id Vec2i cpos = new Vec2i(0, 0); @@ -161,7 +166,7 @@ public class Chunk int id = cpos.getId(CHUNK_SIZE); // Send back the front tile - return this.tiles_front[id]; + return new TileState(this.tiles_front[id], this.tiles_front_meta[id]); } public void killEntity(Entity e) { diff --git a/src/shootergame/world/chunk/ChunkEmpty.java b/src/shootergame/world/chunk/ChunkEmpty.java index 49f0802..ff05024 100644 --- a/src/shootergame/world/chunk/ChunkEmpty.java +++ b/src/shootergame/world/chunk/ChunkEmpty.java @@ -6,6 +6,7 @@ import shootergame.display.Camera; import shootergame.entity.Entity; import shootergame.init.Tiles; import shootergame.tiles.Tile; +import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; @@ -27,20 +28,20 @@ public class ChunkEmpty extends Chunk public void spawnEntity(Entity e) {} @Override - public Tile getBackTile(Vec2i pos) { - return Tiles.VOID; + public TileState getBackTile(Vec2i pos) { + return TileState.EMPTY; } @Override - public Tile getFrontTile(Vec2i pos) { - return Tiles.VOID; + public TileState getFrontTile(Vec2i pos) { + return TileState.EMPTY; } @Override - public void setBackTile(Tile tile, Vec2i pos) {} + public void setBackTile(TileState tile, Vec2i pos) {} @Override - public void setFrontTile(Tile tile, Vec2i pos) {} + public void setFrontTile(TileState tile, Vec2i pos) {} @Override public void checkEntities() {} diff --git a/src/shootergame/world/layer/Layer.java b/src/shootergame/world/layer/Layer.java index 821f769..01cd885 100644 --- a/src/shootergame/world/layer/Layer.java +++ b/src/shootergame/world/layer/Layer.java @@ -8,6 +8,7 @@ import shootergame.display.Camera; import shootergame.entity.Entity; import shootergame.tiles.Tile; import shootergame.util.math.MathHelpers; +import shootergame.util.math.TileState; import shootergame.util.math.map.Map2D; import shootergame.util.math.map.Map2DElement; import shootergame.util.math.vec.Vec2d; @@ -65,7 +66,7 @@ public class Layer this.layergen.spawnEntities(this, rand); } - public void setBackTile(Tile tile, Vec2i pos) + public void setBackTile(TileState tile, Vec2i pos) { // Get the chunk pos Vec2i c_pos = getChunkPosFromPos(pos); @@ -74,7 +75,7 @@ public class Layer chunks.get(c_pos).setBackTile(tile, pos); } - public void setFrontTile(Tile tile, Vec2i pos) + public void setFrontTile(TileState tile, Vec2i pos) { // Get the chunk pos Vec2i c_pos = getChunkPosFromPos(pos); @@ -83,7 +84,7 @@ public class Layer chunks.get(c_pos).setFrontTile(tile, pos); } - public Tile getBackTile(Vec2i pos) + public TileState getBackTile(Vec2i pos) { // Get the chunk pos Vec2i c_pos = getChunkPosFromPos(pos); @@ -102,7 +103,7 @@ public class Layer MathHelpers.floor(pos.y / (double)Chunk.CHUNK_SIZE.my)); } - public Tile getFrontTile(Vec2i pos) + public TileState getFrontTile(Vec2i pos) { // Get the chunk pos Vec2i c_pos = getChunkPosFromPos(pos); diff --git a/src/shootergame/world/layer/layergen/LayerGenCaves.java b/src/shootergame/world/layer/layergen/LayerGenCaves.java new file mode 100644 index 0000000..caac5a6 --- /dev/null +++ b/src/shootergame/world/layer/layergen/LayerGenCaves.java @@ -0,0 +1,71 @@ +package shootergame.world.layer.layergen; + +import java.util.Random; + +import org.lwjgl.stb.STBPerlin; + +import shootergame.init.Tiles; +import shootergame.util.math.TileState; +import shootergame.util.math.random.OpenSimplexNoise; +import shootergame.util.math.random.RandomHelpers; +import shootergame.util.math.vec.Vec2i; +import shootergame.world.chunk.Chunk; +import shootergame.world.layer.Layer; + +public class LayerGenCaves extends LayerGen +{ + + @Override + public Chunk generateChunk(Layer layer, long seed, Random rand, Vec2i c_pos) + { + // Create a new chunk + Chunk chunk = new Chunk(layer, c_pos, rand); + + // Is there going to be a portal in this chunk + boolean portal = RandomHelpers.randrange(rand, 10) == 0; + Vec2i portal_pos = null; + if(portal) portal_pos = new Vec2i( + RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), + RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); + + // Get some noise generators + OpenSimplexNoise noisegen_n = new OpenSimplexNoise(seed); + + // Loop over the chunk + for(int x=0;x 60) { + chunk.setBackTile(Tiles.STONE.getDefaultState(), pos); + } + + else { + chunk.setBackTile(Tiles.WALL.getDefaultState(), pos); + } + + if(portal) { + chunk.setFrontTile(new TileState(Tiles.LADDER_UP, (short)0), portal_pos); + } + } + } + + // Send the chunk back + return chunk; + } + + @Override + public void spawnEntities(Layer layer, Random rand) + { + // TODO Auto-generated method stub + + } + +} diff --git a/src/shootergame/world/layer/layergen/LayerGenEarth.java b/src/shootergame/world/layer/layergen/LayerGenEarth.java index 08e2788..5183640 100644 --- a/src/shootergame/world/layer/layergen/LayerGenEarth.java +++ b/src/shootergame/world/layer/layergen/LayerGenEarth.java @@ -8,6 +8,7 @@ import shootergame.entity.EntityBullet; import shootergame.entity.EntityZombie; import shootergame.init.Tiles; import shootergame.tiles.Tile; +import shootergame.util.math.TileState; import shootergame.util.math.random.OpenSimplexNoise; import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.range.Range2i; @@ -25,6 +26,13 @@ public class LayerGenEarth extends LayerGen // Create the new chunk Chunk chunk = new Chunk(layer, c_pos, rand); + // Is there going to be a portal in this chunk + boolean portal = RandomHelpers.randrange(rand, 10) == 0; + Vec2i portal_pos = null; + if(portal) portal_pos = new Vec2i( + RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), + RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); + // Get the noise generator OpenSimplexNoise noisegen_n = new OpenSimplexNoise(seed); @@ -41,18 +49,23 @@ public class LayerGenEarth extends LayerGen Vec2i pos = new Vec2i(x, y); // Tree and rock generation - if(rand.nextDouble() > 0.9) chunk.setFrontTile(Tiles.TREE, pos); - else if(rand.nextDouble() > 0.99) chunk.setFrontTile(Tiles.ROCK, pos); - else chunk.setFrontTile(Tiles.VOID, pos); + if(rand.nextDouble() > 0.9) chunk.setFrontTile(Tiles.TREE.getDefaultState(), pos); + else if(rand.nextDouble() > 0.99) chunk.setFrontTile(Tiles.ROCK.getDefaultState(), pos); + else chunk.setFrontTile(Tiles.VOID.getDefaultState(), pos); // Terrain generation if(noise_n < 40) { - chunk.setFrontTile(Tiles.WATER, pos); - chunk.setBackTile(Tiles.DIRT, pos); + chunk.setFrontTile(Tiles.WATER.getDefaultState(), pos); + chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos); + } + else if(noise_n < 70) chunk.setBackTile(Tiles.GRASS.getDefaultState(), pos); + else if(noise_n < 90) chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos); + else chunk.setBackTile(Tiles.STONE.getDefaultState(), pos); + + if(portal) { + chunk.setBackTile(new TileState(Tiles.PORTAL_DOWN, (short)1), portal_pos); + chunk.setFrontTile(Tiles.LADDER.getDefaultState(), portal_pos); } - else if(noise_n < 70) chunk.setBackTile(Tiles.GRASS, pos); - else if(noise_n < 90) chunk.setBackTile(Tiles.DIRT, pos); - else chunk.setBackTile(Tiles.STONE, pos); } }