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 50eea05b..c145084f 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; @@ -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, r.getBounces())); } - output.add(new SoundRay(r.getU(), endPoint, r.getBounces())); } return output; } 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 5a5d4622..1fee1b4f 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 World 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);