diff --git a/src/shootergame/entity/EntityBullet.java b/src/shootergame/entity/EntityBullet.java index 85bae85..45a0e51 100644 --- a/src/shootergame/entity/EntityBullet.java +++ b/src/shootergame/entity/EntityBullet.java @@ -23,6 +23,7 @@ public class EntityBullet extends EntityParticle private double height = 0.2; private double height_angle = 0; + private Vec3d velocity; public EntityBullet(Vec2d pos, Entity parent, double angle, double damage, int breakchance, int despawn_time) { super(pos, 0.2, 0.4); @@ -34,6 +35,10 @@ public class EntityBullet extends EntityParticle this.breakchance = breakchance; this.time = despawn_time; + // Calculate the velocity vector + this.velocity = MathHelpers.moveTowards3(0.2, new Vec2d( + Math.toRadians(this.angle), Math.toRadians(this.height_angle))); + // Play the gun sound Sounds.GUN.play(new Vec3d(pos.x, pos.y, 0.4), 2); } @@ -41,6 +46,8 @@ public class EntityBullet extends EntityParticle public EntityBullet withHeight(double angle, double height) { this.height_angle = angle; this.height = height; + this.velocity = MathHelpers.moveTowards3(0.2, new Vec2d( + Math.toRadians(this.angle), Math.toRadians(this.height_angle))); return this; } @@ -49,9 +56,7 @@ public class EntityBullet extends EntityParticle super.tick(chunk, layer); // Move forward in the bullets angle, very quickly - Vec3d pos3 = MathHelpers.moveTowards3(0.2, new Vec2d(Math.toRadians(this.angle), - Math.toRadians(this.height_angle))).add( - new Vec3d(pos.x, pos.y, height)); + Vec3d pos3 = velocity.add(new Vec3d(pos.x, pos.y, height)); height = pos3.z; if(moveIsLegal(new Vec2d(pos3.x, pos.y))) { diff --git a/src/shootergame/entity/particle/ParticleBlood.java b/src/shootergame/entity/particle/ParticleBlood.java index e668a8e..eb21a49 100644 --- a/src/shootergame/entity/particle/ParticleBlood.java +++ b/src/shootergame/entity/particle/ParticleBlood.java @@ -2,6 +2,7 @@ package shootergame.entity.particle; import java.util.Random; +import shootergame.Main; import shootergame.display.Camera; import shootergame.entity.EntityParticle; import shootergame.util.gl.GlHelpers; @@ -9,27 +10,27 @@ import shootergame.util.math.MathHelpers; import shootergame.util.math.random.RandomHelpers; 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 ParticleBlood extends EntityParticle { private double r_color; - private double speed = 0.1; private double time = 1000; private double height = 0; - private double height_velocity = 0; + private Vec3d velocity; + private double angle_height; public ParticleBlood(Random rand, Vec2d pos, double angle) { super(pos, rand.nextDouble() / 5, 0); this.angle = angle + RandomHelpers.randrange(rand, -100, 100); - this.speed = rand.nextDouble() / 10; + this.angle_height = RandomHelpers.randrange(rand, 9000, 18000) / 100; this.height = rand.nextDouble(); - this.height_velocity = rand.nextDouble() / 10; - this.pos.x += 0.5; - this.pos.y += 0.5; r_color = RandomHelpers.randrange(rand, 200, 800) / 1000.0; + velocity = MathHelpers.moveTowards3(0.1, + new Vec2d(Math.toRadians(this.angle), Math.toRadians(angle_height))); } @Override @@ -38,14 +39,18 @@ public class ParticleBlood extends EntityParticle // Call super super.tick(chunk, layer); + Main.player.setHealth(100); + // Move in the velocity and remove some of it - moveBackward(speed); - height += height_velocity; - speed /= 1.05; - height_velocity -= 0.001; + pos.x += velocity.x; + pos.y += velocity.y; + height += velocity.z; + velocity.x /= 1.05; + velocity.y /= 1.05; + velocity.z -= 0.001; if(height < 0) { height = 0; - height_velocity = 0; + velocity.z = 0; } // Remove some time diff --git a/src/shootergame/entity/particle/ParticleBreak.java b/src/shootergame/entity/particle/ParticleBreak.java index 768a65b..d6595cd 100644 --- a/src/shootergame/entity/particle/ParticleBreak.java +++ b/src/shootergame/entity/particle/ParticleBreak.java @@ -11,13 +11,14 @@ import shootergame.util.math.TileState; import shootergame.util.math.random.RandomHelpers; 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 ParticleBreak extends EntityVertical { private double height = 0; - private double height_speed; + private Vec3d velocity; private int time = 1000; private static TextureReference getTexture(TileState ts) @@ -39,7 +40,11 @@ public class ParticleBreak extends EntityVertical super(pos, getTexture(ts), new Vec2d(1/4.0, 1/4.0)); this.opaqueTile = ts.tile.opaqueTile; this.angle = RandomHelpers.randrange(rand, 360); - height_speed = RandomHelpers.randrange(rand, 10000) / 200000.0; + + Vec2d side_v = MathHelpers.moveTowards2(0.01, Math.toRadians(angle)); + velocity = new Vec3d( + side_v.x, side_v.y, + RandomHelpers.randrange(rand, 10000) / 200000.0); } @Override @@ -53,15 +58,16 @@ public class ParticleBreak extends EntityVertical time -= 1; - height += height_speed; - height_speed -= 0.001; + height += velocity.z; + velocity.z -= 0.001; if(height <= 0) { - height_speed = 0; + velocity.z = 0; } else { - moveForward(0.01); + pos.x += velocity.x; + pos.y += velocity.y; } } diff --git a/src/shootergame/entity/particle/ParticleSmoke.java b/src/shootergame/entity/particle/ParticleSmoke.java index 1c15a6e..6c57107 100644 --- a/src/shootergame/entity/particle/ParticleSmoke.java +++ b/src/shootergame/entity/particle/ParticleSmoke.java @@ -47,7 +47,7 @@ public class ParticleSmoke extends EntityVertical public void tick(Chunk chunk, Layer layer) { super.tick(chunk, layer); - if(pos.squareDistance(Main.player.pos) > 32 || opacity <= 0) { + if(pos.squareDistance(Main.player.pos) > 32 || opacity <= 0 || height > 16) { kill(); } diff --git a/src/shootergame/input/JoystickCallback.java b/src/shootergame/input/JoystickCallback.java index e978c91..d45d150 100644 --- a/src/shootergame/input/JoystickCallback.java +++ b/src/shootergame/input/JoystickCallback.java @@ -1,5 +1,6 @@ package shootergame.input; +import java.io.IOException; import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.util.ArrayList; @@ -32,20 +33,9 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask // Gamepad disconnect else if(event == GLFW.GLFW_DISCONNECTED) { - // Log the event + // Log the event and remove the connection System.out.println("Gamepad "+jid+" disconnected"); - - // Loop over the connections - for(int i=0;i