コード例 #1
0
        public virtual void CreateUnit()
        {
            DefenderWorld.Instance.SpawnHealth = 100 + (mThisWave * 10);
            int     value  = 1;
            Vector2 offset = new Vector2(mRand.Next(mMaxX), mRand.Next(mMaxY));

            mUnits.Add(new Unit(mSpawningPoint, offset, Vector2.Zero, 0.5f, mSpawningPoint.Tier, DefenderWorld.Instance.texUnit, DefenderWorld.Instance.texUnitDead, value, DefenderWorld.Instance.SpawnHealth));
            DefenderWorld.Instance.Status.Created++;
            mToCreate--;
        }
コード例 #2
0
        public virtual UnitList GetTargets(Vector2 Distance, int Range)
        {
            UnitList units = new UnitList();

            for (int i = 0; i < mUnits.Count; i++)
            {
                if (mUnits[i].Dead || mUnits[i].GetDistance(Distance) > Range)
                {
                    continue;
                }
                units.Add(mUnits[i]);
            }

            return(units);
        }
コード例 #3
0
        public virtual void Update(GameTime gameTime)
        {
            for (int i = 0; i < mUnits.Count; i++)
            {
                if (mUnits[i].Lost)
                {
                    mUnits.RemoveAt(i);
                    i--;
                }
                else if (mUnits[i].Dead)
                {
                    DefenderWorld.Instance.Status.AddKill(mUnits[i].Money);
                    mUnits[i].Color = new Color(255, 255, 255, 64);                         // dead color
                    mDeadUnits.Add(mUnits[i]);
                    mUnits.RemoveAt(i);
                    i--;
                }
                else
                {
                    mUnits[i].Update(gameTime);
                }
            }

            if (mDeadUnits.Count > DefenderWorld.MaxCorpses)
            {
                mDeadUnits.RemoveAt(0);
            }

            if (mUnits.Count == 0 && mToCreate == 0)
            {
                mFinished = true;
                return;
            }

            if (mToCreate == 0)
            {
                return;
            }

            mTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (mTimer <= mInterval)
            {
                return;
            }

            CreateUnit();
            mTimer = 0f;
        }
コード例 #4
0
        public virtual Unit GetRandomTarget(Vector2 Distance, int Range)
        {
            UnitList randUnits = new UnitList();

            for (int i = 0; i < mUnits.Count; i++)
            {
                if (mUnits[i].Dead || mUnits[i].GetDistance(Distance) > Range)
                {
                    continue;
                }
                randUnits.Add(mUnits[i]);
            }

            if (randUnits.Count == 0)
            {
                return(null);
            }
            return(randUnits[mRand.Next(randUnits.Count)]);
        }
コード例 #5
0
ファイル: UnitWaveList.cs プロジェクト: hakanaku2009/svn-dump
        public Unit GetClosestTarget(Vector2 Distance, int Range)
        {
            Unit     u;
            UnitList units = new UnitList();

            for (int i = 0; i < Count; i++)
            {
                if ((u = this[i].GetClosestTarget(Distance, Range)) != null)
                {
                    units.Add(u);
                }
            }

            if (units.Count == 0)
            {
                return(null);
            }

            float closestSoFar = Range;
            float currentRange = units[0].GetDistance(Distance);

            u = units[0];

            for (int i = 0; i < units.Count; i++)
            {
                if (currentRange >= closestSoFar)
                {
                    continue;
                }

                closestSoFar = currentRange;
                u            = units[i];
            }

            return(u);
        }