Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Adds sound when agents move at a decay rate of 0.5 #296

Merged
merged 3 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/app/controller/GameEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/app/controller/soundEngine/SoundEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/app/controller/soundEngine/SoundSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/app/model/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/app/model/agents/AgentImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AgentImp implements Agent
@Getter protected ArrayList<SoundVector> heard;
@Getter protected VectorSet seen;
@Getter protected AgentView agentViewWindow;
protected final boolean DRAW_HEARD = false;

@Getter @Setter protected static MemoryGraph<GraphCell, DefaultWeightedEdge> world;

Expand Down Expand Up @@ -103,7 +104,8 @@ public void updateView(ArrayList<Ray> 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);
Expand Down