Skip to content

Commit

Permalink
Merge pull request #38 from S010MON/agent-movement
Browse files Browse the repository at this point in the history
agent-movement
  • Loading branch information
S010MON authored Feb 6, 2022
2 parents 47b6fba + 13d5f29 commit 8189429
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/main/java/app/controller/AgentImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import javafx.scene.paint.Color;

import java.util.ArrayList;
import java.util.Random;
import java.util.random.RandomGenerator;

public class AgentImp implements Agent
{
Expand All @@ -27,7 +29,14 @@ public AgentImp(Vector position, Vector direction, double radius)
@Override
public void move()
{
// Null
double x = Math.random() * MAX_WALK;
if(Math.random() > 0.5)
x = x * -1;
double y = Math.random() * MAX_WALK;
if(Math.random() > 0.5)
y = y * -1;

position = position.add(new Vector(x, y));
}

@Override
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/app/controller/Clock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Clock implements ActionListener
{
private GameEngine ge;

public Clock(GameEngine ge)
{
this.ge = ge;
}

@Override
public void actionPerformed(ActionEvent e)
{
ge.tick();
}
}
15 changes: 14 additions & 1 deletion src/main/java/app/controller/GameEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,37 @@
import app.model.MapTemp;
import app.view.Renderer;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GameEngine
{
private MapTemp map;
private Renderer renderer;
private GraphicsEngine graphicsEngine;
private Timer clock;
private int delay = 100;

public GameEngine(MapTemp map, Renderer renderer)
{
this.map = map;
this.renderer = renderer;
this.graphicsEngine = new RayTracing();
tick();
clock = new Timer(delay, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tick();
}
});
clock.start();
}

public void tick()
{
for(Agent a: map.getAgents())
{
a.move();
a.updateView(graphicsEngine.compute(map, a));
}
renderer.render();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/app/controller/ManualAgent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.controller;

public class ManualAgent extends AgentImp
{
public ManualAgent(Vector position, Vector direction, double radius)
{
super(position, direction, radius);
}

@Override
public void move()
{

}
}
4 changes: 2 additions & 2 deletions src/main/java/app/controller/RayTracing.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

public class RayTracing implements GraphicsEngine
{
private int noOfRays = 3600;
private double angle = 0.1;
private int noOfRays = 360;
private double angle = 1;

public ArrayList<Beam> compute(MapTemp map, Agent agent)
{
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/app/view/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import app.model.Placeable;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

public class Renderer extends Canvas
{
Expand All @@ -21,6 +22,9 @@ public void render()
{
GraphicsContext gc = this.getGraphicsContext2D();

gc.setFill(Color.WHITE);
gc.fillRect(0,0,getWidth(), getHeight());

for(Placeable p: map.getObjects())
{
p.draw(gc);
Expand Down

0 comments on commit 8189429

Please sign in to comment.