/// <summary>
 /// Pool constructor
 /// </summary>
 internal Visual()
 {
     Animation = new SimpleASprite(Common.InvalidVector2, Explosion01Tex, 64, 64, 16, 1, 64)
     {
         LoopOnce = true
     };
 }
示例#2
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);
 }
 public void UpgradeDefensiveTier()
 {
     if (Owner.DefensiveTier < Player.MAX_DEFENSIVE_TIER)
     {
         Owner.DefensiveTier++;
         MaxNuclearCnt++;
         MaxShield      += 25;
         MaxShieldRegen += 0.1f;
         ShieldSprite    = ShieldSpriteT2;
     }
 }
示例#4
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;
        }
示例#5
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
        }
示例#6
0
        public static SimpleASprite Create(eAnimation animationType, out SimpleASprite run, out SimpleASprite attack, out SimpleASprite die, out Rectangle relativeAABB, out Texture2D icon)
        {
            run = attack = die = null;
            SimpleASprite result = null;

            icon = null;
            switch (animationType)
            {
            case eAnimation.Smoke1:
                result       = new SimpleASprite(Common.InvalidVector2, SpritePath + "smoke1_96x48_12", 96, 48, 12, 1, 32);
                relativeAABB = new Rectangle(0, 0, 96, 48);
                break;

            case eAnimation.Tree1:
                result       = new SimpleASprite(Common.InvalidVector2, SpritePath + "tree1_128px_8", 128, 128, 8, 1, int.MaxValue);
                relativeAABB = new Rectangle(0, 0, 128, 128);
                break;

            case eAnimation.Tree2:
                result       = new SimpleASprite(Common.InvalidVector2, SpritePath + "tree2_128px_8", 128, 128, 8, 1, int.MaxValue);
                relativeAABB = new Rectangle(0, 0, 128, 128);
                break;

            case eAnimation.Tree3:
                result       = new SimpleASprite(Common.InvalidVector2, SpritePath + "tree3_128px_8", 128, 128, 8, 1, int.MaxValue);
                relativeAABB = new Rectangle(0, 0, 128, 128);
                break;

            case eAnimation.Castle1:
                string tex = "castle1a_192x256";
                if (Maths.Chance(50))
                {
                    tex = "castle1b_192x256";
                }
                result = new SimpleASprite(Common.InvalidVector2, SpritePath + tex, 192, 256, 1, 1, int.MaxValue);
                result.ExtraDrawOffset = new Vector2(0, -96);
                relativeAABB           = new Rectangle(0, 96, 192, 192);
                break;

            case eAnimation.WindMill1:
                result       = new SimpleASprite(Common.InvalidVector2, SpritePath + "windmill128px", 128, 128, 1, 1, int.MaxValue);
                relativeAABB = new Rectangle(0, 0, 128, 128);
                break;

            case eAnimation.WindMill2:
                result       = new SimpleASprite(Common.InvalidVector2, SpritePath + "windmill192px", 192, 192, 1, 1, int.MaxValue);
                relativeAABB = new Rectangle(0, 0, 192, 192);
                break;

            case eAnimation.PileOfGold:
                result       = new SimpleASprite(Common.InvalidVector2, SpritePath + "pileOfGold", 64, 64, 1, 1, int.MaxValue);
                relativeAABB = new Rectangle(0, 0, 64, 64);
                break;

            case eAnimation.Crocy:
                run    = new SimpleASprite(Common.InvalidVector2, SpritePath + "CrocyRun128px_8", 128, 128, 8, 1, 128);
                attack = new SimpleASprite(Common.InvalidVector2, SpritePath + "CrocyAttack128px_11", 128, 128, 11, 1, 128);
                die    = new SimpleASprite(Common.InvalidVector2, SpritePath + "CrocyDie128px_11", 128, 128, 11, 1, 128)
                {
                    LoopOnce = true
                };
                relativeAABB = new Rectangle(32, 32, 64, 64);
                break;

            case eAnimation.Soldier01:
                run    = new SimpleASprite(Common.InvalidVector2, SpritePath + "soldier01Run128px_8", 128, 128, 8, 1, 128);
                attack = new SimpleASprite(Common.InvalidVector2, SpritePath + "soldier01Attack128px_13", 128, 128, 13, 1, 128);
                die    = new SimpleASprite(Common.InvalidVector2, SpritePath + "soldier01Die128px_8", 128, 128, 8, 1, 128)
                {
                    LoopOnce = true
                };
                relativeAABB = new Rectangle(32, 32, 64, 64);
                icon         = Common.str2Tex("Icons/soldier1");
                break;

            case eAnimation.Test1:
                result       = new SimpleASprite(Common.InvalidVector2, SpritePath + "luziaWalk64xpx_8", 64, 64, 8, 1, 96);
                relativeAABB = new Rectangle(0, 8, 64, 48);
                break;

            case eAnimation.Tower1:
                result = new SimpleASprite(Common.InvalidVector2, SpritePath + "tower", 63, 128, 1, 1, int.MaxValue);
                result.ExtraDrawOffset = new Vector2(0, -64);
                relativeAABB           = new Rectangle(0, 0, 64, 128);
                break;

            default:
                throw new CaseStatementMissingException();
            }

            return(result);
        }
示例#7
0
 void SwitchAnimation(SimpleASprite newAnimation)
 {
     newAnimation.Location       = Animation.Location;
     newAnimation.CurrentFrame.Y = Animation.CurrentFrame.Y; // Direction
     Animation = newAnimation;
 }
示例#8
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
        }