public Boid InstantiateBoid(Vector3 position, bool isFish = false)
        {
            Boid boid = Instantiate(boidPrefab, position, Quaternion.identity, boidsParent).GetComponent <Boid>();

            Boids.Add(boid);
            boid.Index  = Boids.IndexOf(boid);
            boid.IsFish = isFish;
            return(boid);
        }
    // Spawns Scalable Boids
    protected void SpawnBoid()
    {
        Vector3    size     = BoidSpawner.transform.localScale;
        Vector3    position = BoidSpawner.transform.position + new Vector3(Random.Range(-size.x / 2, size.x / 2), Random.Range(-size.y / 2, size.y / 2), 0);
        GameObject temp     = Instantiate(BoidPrefab, position, BoidSpawner.transform.rotation);

        temp.GetComponent <PathFollow>().path = Path.GetComponent <PathPlacer>().path;
        Boids.Add(temp);
    }
Esempio n. 3
0
    // Spawns Scalable Boids
    protected void SpawnBoid()
    {
        Vector3    size     = BoidSpawner.transform.localScale;
        Vector3    position = BoidSpawner.transform.position + new Vector3(Random.Range(-size.x / 2, size.x / 2), Random.Range(-size.y / 2, size.y / 2), 0);
        GameObject temp     = Instantiate(BoidPrefab, position, BoidSpawner.transform.rotation);

        temp.GetComponent <PathFollow>().path = Path.GetComponent <PathPlacer>().path;
        foreach (GameObject Boid in Boids)
        {
            Boid.GetComponent <Separate>().targets.Add(temp.GetComponent <NPCController>());
            temp.GetComponent <Separate>().targets.Add(Boid.GetComponent <NPCController>());
        }
        Boids.Add(temp);
    }
Esempio n. 4
0
        private void Init()
        {
            ResourceManager.LoadShader("shaders/textured.vert", "shaders/textured.frag", "textured");
            ResourceManager.LoadShader("shaders/normal.vert", "shaders/normal.frag", "normal");
            ResourceManager.LoadShader("shaders/normal2.vert", "shaders/normal2.frag", "normal2");
            ResourceManager.LoadShader("shaders/light.vert", "shaders/light.frag", "light");
            ResourceManager.LoadShader("shaders/shadow.vert", "shaders/shadow.frag", "shadow");

            List <Model> boidModels = new List <Model>();

            for (int i = 10; i < 50; i++)
            {
                boidModels.Add(ResourceManager.LoadModel("resources/objects/fish/fish_0000" + i + ".obj", "fish_0000" + i));
            }

            Model towerModel = ResourceManager.LoadModel("resources/objects/ship/ship.obj", "tower");
            Model floorModel = ResourceManager.LoadModel("resources/objects/floor/floor.obj", "floor");
            Model sunModel   = ResourceManager.LoadModel("resources/objects/other/sphere.obj", "sun");
            Model weedModel  = ResourceManager.LoadModel("resources/objects/weed/weed.obj", "weed");

            Renderer3D = new Renderer3D();

            Tower = new Tower(towerModel, Vector3.Zero, 1, 2);

            Floor = new EngineObject()
            {
                Model    = floorModel,
                Position = new Vector3(Vector3.Zero)
                {
                    Y = GroundLevel
                },
                Size = new Vector3(GroundSize, 1, GroundSize)
            };

            Sun = new EngineObject()
            {
                Model    = sunModel,
                Position = new Vector3(200, 1.5f * MaxHeight, -1100),
                Size     = Vector3.One * 200
            };

            Tower.Position += new Vector3(0, Tower.Size.Y + GroundLevel, 0);


            EngineObjects.Add(Tower);
            EngineObjects.Add(Floor);

            LeaderBoid = new Boid(boidModels[0], GetRandomPosition(), Vector3.One * 30, GetRandomPosition());

            EngineObjects.Add(LeaderBoid);

            for (int i = 0; i < 50; i++)
            {
                Boids.Add(new Boid(boidModels[0], GetRandomPosition(), Vector3.One * Utils.Random.Next(10, 16), GetRandomDir()));
            }

            for (int i = 0; i < 100; i++)
            {
                var size = new Vector3(30000, Utils.Random.Next(20, 50) * 1000, 30000);
                var weed = new EngineObject()
                {
                    Model    = weedModel,
                    Size     = size,
                    Position = new Vector3(GetRandomPosition(GroundSize))
                    {
                        Y = GroundLevel
                    }
                };
                EngineObjects.Add(weed);
            }

            UpdateFlockMiddle();

            EngineObjects.AddRange(Boids);

            Camera = new Camera(GetRandomPosition());

            var underwater = ResourceManager.LoadSound("resources/sounds/underwater.mp3", "underwater", true);

            SoundEngine.Instance.PlaySound(underwater);
        }
Esempio n. 5
0
        protected override void OnKeyDown(KeyboardKeyEventArgs e)
        {
            base.OnKeyDown(e);

            // Move the camera when in free mode
            if (e.Key == Key.I)
            {
                Camera.ProcessKeyboard(CameraMovement.FORWARD, deltaTime);
            }
            if (e.Key == Key.K)
            {
                Camera.ProcessKeyboard(CameraMovement.BACKWARD, deltaTime);
            }
            if (e.Key == Key.J)
            {
                Camera.ProcessKeyboard(CameraMovement.LEFT, deltaTime);
            }
            if (e.Key == Key.L)
            {
                Camera.ProcessKeyboard(CameraMovement.RIGHT, deltaTime);
            }

            // change camera type
            if (e.Key == Key.Number1)
            {
                Camera.SetCameraType(CameraType.Behind);
            }
            if (e.Key == Key.Number2)
            {
                Camera.SetCameraType(CameraType.Parallel);
            }
            if (e.Key == Key.Number3)
            {
                Camera.SetCameraType(CameraType.Tower);
            }
            if (e.Key == Key.Number4)
            {
                Camera.SetCameraType(CameraType.Free);
            }

            // add boids/increase boid speed
            if (e.Key == Key.Plus)
            {
                if (e.Shift)
                {
                    Boid.MAX_SPEED = Math.Min(800, Boid.MAX_SPEED + 10);                     // keeping max speed sane
                    if (!autoPilot)
                    {
                        LeaderBoid.Velocity = LeaderBoid.Velocity.Normalized() * Boid.MAX_SPEED;
                    }
                }
                else
                {
                    Boid b = new Boid(ResourceManager.GetModel("fish_000010"), GetRandomPosition(), Vector3.One * Utils.Random.Next(10, 16), GetRandomDir());
                    Boids.Add(b);
                    EngineObjects.Add(b);
                }
            }

            //remove boids/decrease boid speed
            if (e.Key == Key.Minus)
            {
                if (e.Shift)
                {
                    Boid.MAX_SPEED = Math.Max(50, Boid.MAX_SPEED - 10);                     // speeds lower than 50 start to get weird
                    if (!autoPilot)
                    {
                        LeaderBoid.Velocity = LeaderBoid.Velocity.Normalized() * Boid.MAX_SPEED;
                    }
                }
                else if (Boids.Count > 3)
                {
                    int          i = Utils.Random.Next(Boids.Count);
                    EngineObject b = Boids[i];
                    Boids.Remove(b);
                    EngineObjects.Remove(b);
                }
            }

            // toggle light mode
            // can mess up with shadows
            if (e.Key == Key.T)
            {
                directionalLight = !directionalLight;
            }

            // enable/disable fog
            if (e.Key == Key.F)
            {
                fogEnabled = !fogEnabled;
            }

            // move light source, mostly for testing
            if (e.Key == Key.Left)
            {
                Sun.Position -= Vector3.UnitZ * 50;
            }
            if (e.Key == Key.Right)
            {
                Sun.Position += Vector3.UnitZ * 50;
            }
            if (e.Key == Key.Down)
            {
                Sun.Position -= Vector3.UnitY * 50;
            }
            if (e.Key == Key.Up)
            {
                Sun.Position += Vector3.UnitY * 50;
            }

            // enable/disable boid movement rules
            if (e.Key == Key.F1)
            {
                Boid.Sep = !Boid.Sep;
            }
            if (e.Key == Key.F2)
            {
                Boid.Coh = !Boid.Coh;
            }
            if (e.Key == Key.F3)
            {
                Boid.Ali = !Boid.Ali;
            }
            if (e.Key == Key.F4)
            {
                Boid.Goal = !Boid.Goal;
            }

            // move leader boid when autopilot is disabled
            if (!autoPilot)
            {
                if (e.Key == Key.W)
                {
                    LeaderBoid.Velocity += LeaderBoid.Up * (Boid.MAX_SPEED / 20);
                }
                if (e.Key == Key.S)
                {
                    LeaderBoid.Velocity -= LeaderBoid.Up * (Boid.MAX_SPEED / 20);
                }
                if (e.Key == Key.A)
                {
                    LeaderBoid.Velocity -= LeaderBoid.Right * (Boid.MAX_SPEED / 20);
                }
                if (e.Key == Key.D)
                {
                    LeaderBoid.Velocity += LeaderBoid.Right * (Boid.MAX_SPEED / 20);
                }
            }

            if (e.Key == Key.P)
            {
                // toggle auto/manual leader control
                if (e.Shift)
                {
                    autoPilot = !autoPilot;
                }
                else
                {
                    // pause/unpause
                    if (State == GameState.Active)
                    {
                        State = GameState.Paused;
                    }
                    else
                    {
                        State = GameState.Active;
                    }
                }
            }

            // quit
            if (e.Key == Key.Q || e.Key == Key.Escape)
            {
                Close();
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Adds a new randomized ship of type MovingObject.
 /// </summary>
 public void AddNewShip(Vector3 position)
 {
     Boids.Add(ShipFactory.Instance.GetAShipAroundLocation(position));
 }