From 6f955c7ece2f101f8aa70d8a7590ee1dac829fbd Mon Sep 17 00:00:00 2001 From: S010MON Date: Sat, 7 May 2022 11:43:00 +0200 Subject: [PATCH 1/2] Feat: Adds sound when agents move at a decay rate of 0.5 --- src/main/java/app/controller/GameEngine.java | 6 +++++- .../java/app/controller/soundEngine/SoundEngine.java | 2 +- .../java/app/controller/soundEngine/SoundSource.java | 2 +- src/main/java/app/model/Map.java | 9 +++++++++ src/main/java/app/model/agents/AgentImp.java | 4 +++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/app/controller/GameEngine.java b/src/main/java/app/controller/GameEngine.java index ca40ca69..64deb1f5 100644 --- a/src/main/java/app/controller/GameEngine.java +++ b/src/main/java/app/controller/GameEngine.java @@ -42,7 +42,7 @@ public GameEngine(Map map, Renderer renderer) public void tick() { map.getSoundSources().forEach(s -> s.setRays(SoundEngine.buildTree(map, s))); - // map.getSoundSources().forEach(s -> s.decay()); + map.getSoundSources().forEach(s -> s.decay()); for(Agent agent: map.getAgents()) { agent.clearHeard(); @@ -73,6 +73,10 @@ else if (legalMove(startPoint, endPoint) && legalMove(a, endPoint) && legalMove(a, startPoint) && legalMove(a, startPoint, endPoint)) { + if(!a.getPosition().equals(endPoint)) + { + map.addSoundSource(endPoint, a.getType()); + } a.updateLocation(endPoint); a.setDirection(move.getEndDir()); a.setMoveFailed(false); diff --git a/src/main/java/app/controller/soundEngine/SoundEngine.java b/src/main/java/app/controller/soundEngine/SoundEngine.java index db834731..3820a5a9 100644 --- a/src/main/java/app/controller/soundEngine/SoundEngine.java +++ b/src/main/java/app/controller/soundEngine/SoundEngine.java @@ -9,7 +9,7 @@ public class SoundEngine { - final static int noOfRays = 10; + final static int noOfRays = 4; final static int noOfBounces = 2; final static int maxDist = 1000; diff --git a/src/main/java/app/controller/soundEngine/SoundSource.java b/src/main/java/app/controller/soundEngine/SoundSource.java index e4511f93..f8392041 100644 --- a/src/main/java/app/controller/soundEngine/SoundSource.java +++ b/src/main/java/app/controller/soundEngine/SoundSource.java @@ -62,7 +62,7 @@ public void draw(GraphicsContext gc) public void decay() { - amplitude = amplitude * 0.9; + amplitude = amplitude * 0.5; } private double collectDistances(SoundRay ray, Agent agent) diff --git a/src/main/java/app/model/Map.java b/src/main/java/app/model/Map.java index 207bc132..794dd7f3 100644 --- a/src/main/java/app/model/Map.java +++ b/src/main/java/app/model/Map.java @@ -243,6 +243,15 @@ public Type objectAt(Vector v) } + public void addSoundSource(Vector position, Type team) + { + if(team == Type.GUARD) + soundSources.add(new SoundSource(position, 200, 1000)); + else if(team == Type.INTRUDER) + soundSources.add(new SoundSource(position, 200, 2000)); + } + + public void garbageCollection() { for(Agent a: deletion) diff --git a/src/main/java/app/model/agents/AgentImp.java b/src/main/java/app/model/agents/AgentImp.java index 7bad6d3c..1d963713 100644 --- a/src/main/java/app/model/agents/AgentImp.java +++ b/src/main/java/app/model/agents/AgentImp.java @@ -33,6 +33,7 @@ public class AgentImp implements Agent @Getter protected ArrayList heard; @Getter protected VectorSet seen; @Getter protected AgentView agentViewWindow; + protected final boolean DRAW_HEARD = false; @Getter @Setter protected static MemoryGraph world; @@ -103,7 +104,8 @@ public void updateView(ArrayList view) @Override public void draw(GraphicsContext gc) { - heard.forEach(h -> h.draw(gc, this.position)); + if(DRAW_HEARD) + heard.forEach(h -> h.draw(gc, this.position)); gc.setStroke(Color.BLACK); gc.setLineWidth(3.0); From 99e50e42d1e053331b94dc6d3930656e6a287bf9 Mon Sep 17 00:00:00 2001 From: S010MON Date: Sun, 8 May 2022 18:53:18 +0200 Subject: [PATCH 2/2] Fix: patches null pointer exception --- .../java/app/controller/soundEngine/SoundEngine.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/app/controller/soundEngine/SoundEngine.java b/src/main/java/app/controller/soundEngine/SoundEngine.java index 3820a5a9..6486ad32 100644 --- a/src/main/java/app/controller/soundEngine/SoundEngine.java +++ b/src/main/java/app/controller/soundEngine/SoundEngine.java @@ -36,13 +36,15 @@ else if(agentIntersection != null) else if(bdyIntersection != null) endPoint = bdyIntersection; - - if(r.getBounces() > 0 && endPoint.dist(r.getU()) > 0.01) + if( endPoint != null) { - Vector new_origin = bouncePoint(endPoint, r.getU()); - stack.addAll(SoundRayScatter.angle360(new_origin, noOfRays, maxDist, r.getBounces())); + if(r.getBounces() > 0 && endPoint.dist(r.getU()) > 0.01) + { + Vector new_origin = bouncePoint(endPoint, r.getU()); + stack.addAll(SoundRayScatter.angle360(new_origin, noOfRays, maxDist, r.getBounces())); + } + output.add(new SoundRay(r.getU(), endPoint)); } - output.add(new SoundRay(r.getU(), endPoint)); } return output; }