fix access modifiers, start and update functions

This commit is contained in:
Xevion
2020-05-16 11:35:53 -05:00
parent 13808b8120
commit 5b049f2f24
2 changed files with 12 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ public class Boid {
private Vector2 _position;
private Vector2 _velocity;
Boid(Vector2 position, Vector2 velocity) {
public Boid(Vector2 position, Vector2 velocity) {
_position = position;
_velocity = velocity;
}
@@ -20,7 +20,7 @@ public class Boid {
}
// Returns the next position the Boid will be moving to
Vector2 NextPosition(List<Boid> boids, float[] magnitudes) {
public Vector2 NextPosition(List<Boid> boids, float[] magnitudes) {
// Find the local flock
List<Boid> flock = GetFlock(boids, 5);

View File

@@ -18,11 +18,17 @@ public class BoidController : MonoBehaviour {
private List<Boid> _boids = new List<Boid>();
void Start() {
for(int i = 0; i < boidCount; i++)
_boids.Add(new Boid(Vector2.zero, new Vector2(1, 1)));
}
void Update()
{
void Update() {
float[] magnitudes = new float[] {cohesionBias, separationBias, alignmentBias};
// Update all Boid positions
foreach (Boid boid in _boids) {
boid.SetPosition(boid.NextPosition(_boids, magnitudes));
}
}
}