From bb13aaa09fb559ebcc1b5dfd76ba301088f832e7 Mon Sep 17 00:00:00 2001 From: josua Date: Thu, 29 Aug 2019 09:44:07 +1000 Subject: [PATCH] Added ammo --- src/shootergame/display/DisplayRenderUI.java | 15 ++++++++++++--- src/shootergame/entity/EntityInventory.java | 5 +++++ src/shootergame/entity/player/EntityPlayer.java | 9 +++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/shootergame/entity/EntityInventory.java diff --git a/src/shootergame/display/DisplayRenderUI.java b/src/shootergame/display/DisplayRenderUI.java index 5b3457a..9df9446 100644 --- a/src/shootergame/display/DisplayRenderUI.java +++ b/src/shootergame/display/DisplayRenderUI.java @@ -21,15 +21,18 @@ public class DisplayRenderUI // Disable some opengl options GlHelpers.disableDepthTest(); + // Get some text settings + Vec2d text_size = new Vec2d(0.5, 0.2); + // Render the fps and the position GlHelpers.pushMatrix(); GlHelpers.translate(-9.5, 9.5, 0); GlHelpers.color3(1, 1, 0); - Text.render("FPS: " + DisplayStatsEventHandler.fps, new Vec2d(0.5, 0.2)); + Text.render("FPS: " + DisplayStatsEventHandler.fps, text_size); GlHelpers.translate(0, -0.5, 0); - Text.render("x: " + (int) player.pos.x + ", y: " + (int) player.pos.y, new Vec2d(0.5, 0.2)); + Text.render("x: " + (int) player.pos.x + ", y: " + (int) player.pos.y, text_size); GlHelpers.translate(0, -0.5, 0); - Text.render("AL Sound Source: "+AudioSources.upto, new Vec2d(0.5, 0.2)); + Text.render("AL Sound Source: "+AudioSources.upto, text_size); GlHelpers.color3(1, 1, 1); GlHelpers.popMatrix(); @@ -51,5 +54,11 @@ public class DisplayRenderUI health_fg.texCoord(1-a, 0); GlHelpers.vertex2(2.5-a*5, -9.0); GlHelpers.end(); + + // Display the amount of ammo left + GlHelpers.pushMatrix(); + GlHelpers.translate(-9.5, -9.5, 0); + Text.render("Ammo: "+player.ammo, text_size); + GlHelpers.popMatrix(); } } diff --git a/src/shootergame/entity/EntityInventory.java b/src/shootergame/entity/EntityInventory.java new file mode 100644 index 0000000..f285a3b --- /dev/null +++ b/src/shootergame/entity/EntityInventory.java @@ -0,0 +1,5 @@ +package shootergame.entity; + +public interface EntityInventory { + +} diff --git a/src/shootergame/entity/player/EntityPlayer.java b/src/shootergame/entity/player/EntityPlayer.java index fd62ce0..4d4ae0f 100644 --- a/src/shootergame/entity/player/EntityPlayer.java +++ b/src/shootergame/entity/player/EntityPlayer.java @@ -39,6 +39,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive public boolean dead = false; public boolean in_animation = false; + public int ammo = 1000; + public EntityPlayer() { this.angle = 45; rand = new Random(); @@ -154,11 +156,14 @@ public class EntityPlayer extends EntityVertical implements EntityAlive bullet_frequency += 1; bullet_frequency %= 10; - if(bullet_frequency == 0) + // Is there enough ammo and are the bullets at the right frequency + if(bullet_frequency == 0 && ammo > 0) { + // Remove some ammo + ammo -= 1; + // Summon bullets at this angle relative to the player Main.world.getLayer().spawnEntity(new EntityBullet(rand, pos.copy(), this, angle + this.angle)); - //throwTnt(angle); } }