Exemple #1
0
 public Environment(eAnimation animation, Vector2 location)
 {
     EntityID           = Engine.RetrieveNextEntityID();
     Animation          = AnimationFactory.Create(animation, out m_AABB);
     Animation.Location = location;
     Animation.RandomizeStartFrame();
     FeetLoc = location + new Vector2(AABB.X + AABB.Width / 2, AABB.Bottom);
 }
Exemple #2
0
        public void Initialize(int id)
        {
            RunnerStruct rs = DataStructs.Runners.Find(r => r.ID == id);

            HP = new HitPoints(rs.HP, rs.HP, 0);
            HPBar.Percentage = 100;
            HPRegen = rs.HPRegen;
            Velocity = rs.Velocity;
            IsMelee = rs.IsMelee;
            IsGround = rs.IsGround;
            Recycles = rs.Recycles;
            Bounty = rs.Bounty;
            FinishDmg = rs.FinishDamage;

            ImmuneStun = rs.ImmuneStun;
            ImmuneSlow = rs.ImmuneSlow;
            ImmuneArmorReduction = rs.ImmuneArmorReduction;
            ImmuneRooted = rs.ImmuneRooted;

            Animation = AnimationFactory.Create(rs.AnimationType, out RelativeAABB);
            HPBar.BarDrawRect = new Rectangle(HPBar.BarDrawRect.X, HPBar.BarDrawRect.Y, Animation.FrameSize.X, HPBar.BarDrawRect.Height);
            Animation.DrawColor = rs.DrawColor;
            CenterLocOffset = new Vector2(Animation.FrameSize.X / 2, Animation.FrameSize.Y / 2);
            FeetLocOffset = new Vector2(Animation.FrameSize.X / 2, Animation.FrameSize.Y);
            Armor = rs.Armor;
            m_AABB = RelativeAABB;

            IsFightingWithDefenders = new List<ITargetable>();
            TargettedByDefenders = new List<ITargetable>();

            #region Weapons
            Weapons = new List<BaseWeapon>();
            ShortestWeaponRange = int.MaxValue;
            HasRangedWeapon = false;
            RangedWpnRange = int.MaxValue;
            foreach (WeaponStruct ws in rs.Weapons)
            {
                BaseWeapon w = new BaseWeapon(Common.InvalidVector2, ws, this);
                Weapons.Add(w);
                if (w.IsRanged)
                {
                    HasRangedWeapon = true;
                    if (RangedWpnRange > ws.Range)
                        RangedWpnRange = ws.Range;
                }
                if (ShortestWeaponRange > ws.Range)
                    ShortestWeaponRange = ws.Range;
            }
            #endregion
            HasWeapons = Weapons.Count > 0;

            IsFightingRanged = false;
        }
Exemple #3
0
        public void Initialize(int id)
        {
            #warning the struct below is copied and thus is allocates memory. should be done differently like find the index with linq instead and access it by index.
            TowerStruct ts = DataStructs.Towers.Find(t => t.ID == id);

            ID                     = id;
            Name                   = new StringBuilder(ts.Name, ts.Name.Length);
            Desc                   = new StringBuilder(ts.Desc, ts.Desc.Length);
            TotalValue             = Cost = ts.Cost;
            BuildSize              = ts.BuildSize;
            BuildTimeInMS          = ts.BuildTimeInMS;
            MaxRallyPointRange     = ts.MaxRallyPointRange;
            RallyPointPersuitRange = ts.RallyPointPersuitRange;

            OccupiedGridIndices = new List <Point>(ts.BuildSize.X * ts.BuildSize.Y);
            OccupyRect          = Rectangle.Empty;

            if (ts.SupplyCost > 0)
            {
                SupplyCost = ts.SupplyCost;
                SupplyGive = 0;
                Level.Instance.Player.Supply += ts.SupplyCost;
            }
            else
            {
                SupplyCost = 0;
                SupplyGive = ts.SupplyCost * -1;
                Level.Instance.Player.MaxSupply += SupplyGive;
            }

            m_HasFocus = false;

            #region Income
            if (ts.IncomeTickDelayInMS != 0)
            {
                IncomeTickDelayTimer = new SimpleTimer(ts.IncomeTickDelayInMS);
            }
            else
            {
                IncomeTickDelayTimer = null;
            }
            IncomePerTick = ts.IncomePerTick;
            IncomePerWave = ts.IncomePerWave;
            #endregion

            Animation           = AnimationFactory.Create(ts.AnimationType, out RelativeAABB);
            Animation.DrawColor = ts.DrawColor;
            DrawColor           = Color.White;

            #region Weapons
            Weapons = new List <BaseWeapon>();
            if (ts.Weapons.Count > 0)
            {
                foreach (WeaponStruct ws in ts.Weapons)
                {
                    Weapons.Add(new BaseWeapon(m_CenterLoc, ws, this));
                }
            }
            #endregion

            Vector2 btnOffset = Vector2.Zero;
            #region Spawns
            if (SpawnUpgradeButtons != null)
            {
                foreach (Button sbtn in SpawnUpgradeButtons)
                {
                    sbtn.Click -= new Button.OnClick(spawnUpgBtn_Click);
                }
            }
            SpawnUpgradeButtons = new List <Button>();

            if (ts.Defenders.Count == 0)
            {
                Defenders = new List <BaseDefender>(0);
            }
            else
            {
                Defenders = new List <BaseDefender>(MAX_DEFENDERS);
                foreach (DefenderSpawnStruct dss in ts.Defenders)
                {
                    int maxDefenders      = dss.Max;
                    int currentInitialCnt = 0;

                    for (int i = 0; i < dss.Max; i++)
                    {
                        BaseDefender bd = new BaseDefender();
                        bd.Initialize(dss.ID);
                        bd.SetRallyPoint(RallyPoint, MaxRallyPointRange, RallyPointPersuitRange);
                        Defenders.Add(bd);
                        if (currentInitialCnt < dss.InitialAmount)
                        {
                            bd.Spawn();
                            currentInitialCnt++;
                        }
                    }

                    if (dss.InitialAmount < dss.Max)
                    {
                        Button spawnUpgBtn = new Button(SpawnUpgradeBtnsLoc + btnOffset, "GUI/btnEmpty", "GUI/btnEmptyHover", null)
                        {
                            OverlayTexture = Common.str2Tex("Icons/soldier1"), Tag = dss
                        };
                        spawnUpgBtn.Click += new Button.OnClick(spawnUpgBtn_Click);
                        btnOffset.Y       += 50;
                        SpawnUpgradeButtons.Add(spawnUpgBtn);
                    }
                }
            }
            #endregion

            #region Tower Upgrades
            if (TowerUpgradeButtons != null)
            {
                foreach (Button tbtn in TowerUpgradeButtons)
                {
                    tbtn.Click -= new Button.OnClick(TowerUpgBtn_Click);
                }
            }
            TowerUpgradeButtons = new List <Button>();

            foreach (TowerUpgrade twrUpg in ts.Upgrades)
            {
                Button newTowerUpgBtn = new Button(TowerUpgradeBtnsLoc + btnOffset, "GUI/btnTowerUpgEmpty", "GUI/btnTowerUpgEmptyHover", null)
                {
                    OverlayTexture = twrUpg.Icon, Tag = twrUpg
                };
                btnOffset.Y          += 50;
                newTowerUpgBtn.Click += new Button.OnClick(TowerUpgBtn_Click);
                TowerUpgradeButtons.Add(newTowerUpgBtn);
            }
            #endregion
        }
Exemple #4
0
        public void Initialize(int id)
        {
            DefenderStruct ds = DataStructs.Defenders.Find(d => d.ID == id);

            ID = id;
            HP = new HitPoints(ds.HP, ds.HP, 0);
            HPBar.Percentage = 100;
            HPRegen          = ds.HPRegen;
            Velocity         = ds.Velocity;
            IsMelee          = ds.IsMelee;
            IsGround         = ds.IsGround;
            MeleeSightRange  = ds.MeleeSightRange;
            State            = eState.Running;
            Armor            = ds.ArmorType;

            IsAlive      = true;
            IsSpawned    = false;
            RespawnTimer = new SimpleTimer(ds.SpawnDelay);

            #region Weapons
            Weapons             = new List <BaseWeapon>();
            ShortestWeaponRange = int.MaxValue;
            foreach (WeaponStruct ws in ds.Weapons)
            {
                BaseWeapon w = new BaseWeapon(Common.InvalidVector2, ws, this);
                Weapons.Add(w);
                if (ShortestWeaponRange > ws.Range)
                {
                    ShortestWeaponRange = ws.Range;
                }
            }
            if (Weapons.Count == 0)
            {
                throw new Exception("A defender must at least have one weapon.");
            }
            #endregion

            AnimationFactory.Create(ds.AnimationType, out RunAni, out AtkAni, out DieAni, out RelativeAABB, out Icon);
            Animation = RunAni;

            HPBar.BarDrawRect   = new Rectangle(HPBar.BarDrawRect.X, HPBar.BarDrawRect.Y, Animation.FrameSize.X, HPBar.BarDrawRect.Height);
            Animation.DrawColor = ds.DrawColor;
            CenterLocOffset     = new Vector2(Animation.FrameSize.X / 2, Animation.FrameSize.Y / 2);
            m_AABB = RelativeAABB;

            #region Feetoffset
            Vector2 extraFeetOffset = Vector2.Zero;
            switch (ds.AnimationType)
            {
            case eAnimation.Soldier01:
                extraFeetOffset = new Vector2(0, -32);
                break;

            case eAnimation.Crocy:
                extraFeetOffset = new Vector2(0, -32);
                break;

            default:
                throw new CaseStatementMissingException("This animation was not added to the BaseDefender.Initialize() or it was not set (None).");
            }
            FeetLocOffset = new Vector2(Animation.FrameSize.X / 2, Animation.FrameSize.Y) + extraFeetOffset;
            #endregion
        }