Example #1
0
File: Fish.cs Project: atarng/JAMMM
        public Fish()
            : base(0, 0, 32, 32, 16, 10)
        {
            randomX = rnd.NextDouble() * 6.28;
            randomY = rnd.NextDouble() * 6.28;

            this.MaxVel = 200;
            this.MaxAcc = 300;

            this.isSchooling = false;
            this.isLeader = false;
            this.partner = null;
            this.isPoweredUp = false;

            schoolingBounds = Rectangle.Empty;

            this.gettingIntoSchoolRange = false;

            boundsChecker = new Circle(0, 0, 0);
        }
Example #2
0
File: Fish.cs Project: atarng/JAMMM
 /// <summary>
 /// Just reset all schooling variables.
 /// </summary>
 private void resetSchooling()
 {
     this.gettingIntoSchoolRange = false;
     this.partner                = null;
     this.isSchooling            = false;
     this.isLeader               = false;
 }
Example #3
0
File: Fish.cs Project: atarng/JAMMM
        public override void spawnAt(Vector2 position)
        {
            base.spawnAt(position);

            this.isColorCoded = false;
            this.powerup     = null;
            this.isPoweredUp = false;
            this.MaxVel      = 300;
            this.MaxAcc      = 300;

            changeState(state.Moving);

            randomX = rnd.NextDouble() * 2 - rnd.NextDouble();
            randomY = rnd.NextDouble() * 2 - rnd.NextDouble();

            this.isSchooling = false;
            this.isLeader = false;
            this.partner = null;
            this.gettingIntoSchoolRange = false;
        }
Example #4
0
File: Fish.cs Project: atarng/JAMMM
        /// <summary>
        /// If there is a nearby leader in range, follow it.
        /// Otherwise, find the nearest fish. If it is in range,
        /// we're not following it or our partner is dead, and
        /// we're not a leader, then follow it. If that nearest
        /// fish is a delinquent, then make it a leader.
        /// </summary>
        public void TryToSchool(List<Fish> fishPool)
        {
            if (this.CurrState == state.Dying) return;
            if (this.isPoweredUp) return;

            float distToNearestLeader = 0.0f;
            Fish nearestLeader = getNearestFish(fishPool, ref distToNearestLeader, true);

            float distToNearestFish = 0.0f;
            Fish nearestFish = getNearestFish(fishPool, ref distToNearestFish, false);

            // if there is a nearby leader to follow and we're not already following it
            // and it is within range, then follow it. If we're a leader, then
            // we are now a follower
            if (nearestLeader != null
            && this.partner != nearestLeader
            && Actor.DistanceBetween(this, nearestLeader) < LEADER_RANGE)
            {
                this.isLeader = false;

                this.partner = nearestLeader;

                this.isSchooling = true;

                this.acceleration =
                    Math.Abs(SCHOOLING_RANGE - distToNearestLeader) * this.DirectionTo(nearestLeader);

                this.gettingIntoSchoolRange = true;
            }
            // otherwise, if there is another fish to follow that we're not already following
            // or our partner is dead and we're not a leader and it is in range, then follow it.
            // If it is a delinquent, make it a leader.
            else if (nearestFish != null
                && (this.partner == null ||
                (this.partner != null && (!this.partner.IsAlive || this.partner.CurrState == state.Dying)))
                && !this.isLeader  && !nearestFish.isLeader
                && !nearestFish.IsSchooling
                && Actor.DistanceBetween(this, nearestFish) < SCHOOLING_RANGE)
            {
                this.partner = nearestFish;

                this.isSchooling = true;

                this.acceleration =
                    (SCHOOLING_RANGE - distToNearestFish) * this.DirectionTo(nearestFish);

                this.gettingIntoSchoolRange = true;
                nearestFish.IsLeader = true;
            }
        }
Example #5
0
File: Fish.cs Project: atarng/JAMMM
        public void spawnAt(Vector2 position, Powerup p, bool isColorCoded)
        {
            base.spawnAt(position);

            this.isColorCoded = isColorCoded;

            this.powerup = p;
            this.isPoweredUp = true;
            this.MaxVel = 666;
            this.MaxAcc = 700;

            changeState(state.Moving);

            randomX = rnd.NextDouble() * 2 - rnd.NextDouble();
            randomY = rnd.NextDouble() * 2 - rnd.NextDouble();

            this.isSchooling = false;
            this.isLeader = false;
            this.partner = null;
            this.gettingIntoSchoolRange = false;
        }