Beispiel #1
0
        public int?Move()
        {
            // iedere pod bepaalt zijn actie
            foreach (IPodBrain podbrain in _podBrains)
            {
                podbrain.GetAction();
            }

            // draai en stel throttle in
            foreach (Pod pod in _pods)
            {
                pod.Rotate();
                pod.Thrust();
            }
            // bereken de botsingen

            List <Collision> collisions = new List <Collision>();

            for (int i = 0; i < _pods.Length - 1; i++)
            {
                for (int j = i + 1; j < _pods.Length; j++)
                {
                    Collision collision = GameUnit.GetCollisionData(_pods[i], _pods[j]);
                    if (collision != null)
                    {
                        collisions.Add(collision);
                    }
                }
            }

            foreach (Collision c in collisions)
            {
                c.Bounce();
            }

            // plaats pods op nieuwe locaties
            for (int i = 0; i < _pods.Length; i++)
            {
                Pod pod = _pods[i];
                pod.Move();
                // bepaal of pod checkpoint heeft bereikt

                if ((_raceInfo.Checkpoints[pod.NextCheckPointId].Position - pod.Position).Size < 600)
                {
                    pod.NextCheckPointId = (pod.NextCheckPointId + 1) % _raceInfo.CheckpointCount;
                    if (pod.Lap > _raceInfo.LapCount)
                    {
                        return(i);
                    }
                }
            }
            return(null);
        }