Example #1
0
 public void DrawGameOver(SpriteBatch spriteBatch)
 {
     base.Draw(spriteBatch);
     spriteBatch.Draw(EngineAnimation, Position, new Rectangle(Frame * FrameWidth, 0, FrameWidth, FrameHeight), Color.White, Direction, new Vector2(Texture.Width / 2, Texture.Height / 2), Size, SpriteEffects.None, Depth - 0.1f);
     spriteBatch.DrawString(TextureManager.SpriteFont20, "Killer", new Vector2(500, 160), Color.White);
     ShipShield.DrawInventory(spriteBatch, new Vector2(564, 300));
     ShipHull.DrawInventory(spriteBatch, new Vector2(628, 300));
     Health.Draw(spriteBatch);
     for (int i = 0; i < Weapons.Count(); i++)
     {
         Weapons[i].DrawInventory(spriteBatch, new Vector2(692 + i * 64, 300));
     }
 }
Example #2
0
 /// <summary>
 /// Equips a new weapon.
 /// </summary>
 public void EquipWeapon(Weapon newWeapon)
 {
     //Already have a weapon of this type so replace the old one.
     if (Weapons.Contains(newWeapon.WeaponData.WeaponType))
     {
         ReplaceWeapon(Weapons[newWeapon.WeaponData.WeaponType], newWeapon);
     }
     //Full of weapons, so drop your currently equipped one.
     else if (Weapons.Count() >= Capacity)
     {
         ReplaceWeapon(Weapons[CurrentWeapon.WeaponData.WeaponType], newWeapon);
     }
     //Regular, just add it.
     else
     {
         Weapons.Add(newWeapon);
     }
     _CurrentWeaponIndex = Weapons.Count() - 1;
 }
Example #3
0
        /// <summary>
        /// Switch which weapon to use.
        /// </summary>
        public void SwitchWeapon(bool getPrev)
        {
            if (Weapons.Count() == 1)
            {
                return;
            }

            _CurrentWeaponIndex += (getPrev) ? -1: 1;
            if (_CurrentWeaponIndex < 0)
            {
                _CurrentWeaponIndex = Weapons.Count() - 1;
            }
            else if (_CurrentWeaponIndex == Weapons.Count())
            {
                _CurrentWeaponIndex = 0;
            }

            CorvEngine.AudioManager.PlaySoundEffect("WeaponSwitch");
        }
Example #4
0
        public void ShowInventory()
        {
            for (var i = 0; i < Weapons.Count(); i++)
            {
                Console.WriteLine($"W{i} - Name: {Weapons[i].Name} / Original Value: {Weapons[i].OriginalValue}");
                buyProducts.Add($"W{i}", Weapons[i]);
            }
            for (var i = 0; i < Armors.Count(); i++)
            {
                Console.WriteLine($"A{i} - Name: {Armors[i].Name} / Original Value: {Armors[i].OriginalValue}");
                buyProducts.Add($"A{i}", Armors[i]);
            }
            for (var i = 0; i < Potions.Count(); i++)
            {
                Console.WriteLine($"P{i} - Name: {Potions[i].Name} / Original Value: {Potions[i].OriginalValue}");
                buyProducts.Add($"P{i}", Potions[i]);
            }
            Console.WriteLine("Buy item or return to menu");
            Console.WriteLine("If you want to buy item, type the b");
            Console.WriteLine("If you want to return to menu, type the r");

            var choose = Console.ReadLine();

            if (choose == "b")
            {
                Sell();
            }
            else if (choose == "r")
            {
                Menu();
            }
            else
            {
                Console.WriteLine("You type wrong letter. Please enter correct letter.");
                Console.WriteLine("");
                Menu();
            }
        }
Example #5
0
        private static List <(int cost, int armor, int damage)> GetCombinations()
        {
            var combinations = new List <(int, int, int)>();
            var count        = 0;

            for (int weaponIndex = 0; weaponIndex < Weapons.Count(); weaponIndex++)
            {
                for (int gearIndex = 0; gearIndex < Gear.Count(); gearIndex++)
                {
                    for (int firstRingIndex = 0; firstRingIndex < Rings.Count(); firstRingIndex++)
                    {
                        for (int secondRingIndex = firstRingIndex + 1; secondRingIndex < Rings.Count(); secondRingIndex++)
                        {
                            count++;
                            var combination = GetCombinationStats(weaponIndex, gearIndex, firstRingIndex, secondRingIndex);
                            combinations.Add(combination);
                        }
                    }
                }
            }

            return(combinations);
        }
Example #6
0
        /// <summary>
        /// Removes all the weapons from the player and gives them the default weapon.
        /// </summary>
        public void RemoveWeapons()
        {
            //Default weapon is the currently equiped one so do nothing.
            if (Weapons.Count() == 1 && CurrentWeapon.WeaponData.SystemName == DefaultWeaponName)
            {
                return;
            }
            Random rand      = new Random();
            float  launchMod = 1f;
            var    wlist     = Weapons.Take(Weapons.Count);

            foreach (Weapon w in Weapons.Reverse())
            {
                //drop the weapon except for the default one.
                if (w.WeaponData.SystemName != DefaultWeaponName)
                {
                    DropWeapon(w.WeaponData.SystemName, launchMod);
                }
                Weapons.Remove(w);
                launchMod += 0.25f;
            }
            _CurrentWeaponIndex = 0;
            Weapons.Add(_DefaultWeapon);
        }
Example #7
0
        public override void UpdateLevel(Level level)
        {
            base.UpdateLevel(level);

            // Move to normal position after knockback
            Position = new Vector2(Position.X, (float)MathHelper.Lerp(Position.Y, Texture.Height + 40, 0.1f));

            if (level.Started)
            {
                // Shoot
                ShootTimer--;
                if (ShootTimer < 0 && ShipLocation == level.Player.ShipLocation && Weapons[SelectedWeapon].Disabled < 0)
                {
                    ShootTimer = 180;
                    KnockBack  = -3;
                    Weapons[SelectedWeapon].Method(this, Weapons[SelectedWeapon], 0, level, false);
                }

                // Change weapon if not easy difficulty
                if (EnemyDifficulty != Difficulty.Easy && CurrentWeapon.Disabled > 0 && Globals.Randomizer.Next(0, 101) < 2)
                {
                    for (int i = 0; i < Weapons.Count(); i++)
                    {
                        if (Weapons[i].Disabled <= 0)
                        {
                            SelectedWeapon = i;
                        }
                    }
                }

                // Dodge if hard difficulty
                dodgeCooldown--;
                if (EnemyDifficulty == Difficulty.Hard && dodgeCooldown < 0 && (Health.Value / Health.MaxValue) < 0.7)
                {
                    foreach (Shot shot in level.GameObjects.Where(item => item is Shot))
                    {
                        if (shot.Direction > Math.PI)
                        {
                            shot.Direction -= (float)Math.PI * 2f;
                        }
                        if (Globals.Distance(Position, shot.Position) < 100 && Math.Abs(Math.Atan2(Position.Y - shot.Position.Y, Position.X - shot.Position.X) - shot.Direction) < 0.3f)
                        {
                            dodgeCooldown = 180;
                            if (Globals.Randomizer.Next(0, 101) < 30)
                            {
                                if (ShipLocation == Location.left)
                                {
                                    ShipLocation = Location.middle;
                                }
                                else if (ShipLocation == Location.middle)
                                {
                                    ShipLocation = Location.left;
                                }
                                else
                                {
                                    ShipLocation = Location.middle;
                                }
                            }
                        }
                    }
                }

                // Move
                MoveTimer -= 1;
                if (Globals.Randomizer.Next(0, 1001) < 3 + (Health.Value / Health.MaxValue) * 5 && MoveTimer < 0)
                {
                    if (ShipLocation < level.Player.ShipLocation)
                    {
                        ShipLocation++;
                        DirectionSpeed = -0.0005f;
                        ShootTimer     = 60;
                    }
                    else if (ShipLocation > level.Player.ShipLocation)
                    {
                        ShipLocation--;
                        DirectionSpeed = 0.0005f;
                        ShootTimer     = 60;
                    }
                }

                // Die
                if (Health.Value <= 0)
                {
                    Dead = true;
                    SoundManager.explosion.Play();
                    // Pieces
                    level.CreatePieces(Position, Texture);
                }
            }
        }
Example #8
0
        public override void UpdateLevel(Level level)
        {
            if (!Move)
            {
                // Die
                if (Health.Value <= 0)
                {
                    Move = true;
                    Dead = true;
                    SoundManager.die.Play();
                }

                Position = new Vector2(Position.X, (float)MathHelper.Lerp(Position.Y, Globals.ScreenSize.Y - Texture.Height, 0.1f));
                base.UpdateLevel(level);
                // Select weapon
                for (int i = 0; i < Weapons.Count(); i++)
                {
                    if (Weapons[i].Pressed())
                    {
                        SelectedWeapon = i;
                        SoundManager.swapItem.Play();
                        break;
                    }
                }
                if (Globals.KState.IsKeyDown(Keys.D1) && Globals.PrevKState.IsKeyUp(Keys.D1))
                {
                    SelectedWeapon = 0;
                    SoundManager.swapItem.Play();
                }
                else if (Globals.KState.IsKeyDown(Keys.D2) && Globals.PrevKState.IsKeyUp(Keys.D2) && Weapons.Count >= 2)
                {
                    SelectedWeapon = 1;
                    SoundManager.swapItem.Play();
                }
                else if (Globals.KState.IsKeyDown(Keys.D3) && Globals.PrevKState.IsKeyUp(Keys.D3) && Weapons.Count >= 3)
                {
                    SelectedWeapon = 2;
                    SoundManager.swapItem.Play();
                }

                // Right
                if (MoveRight > 0)
                {
                    MoveRight--;
                    if (Globals.KState.IsKeyDown(Keys.D) && Globals.PrevKState.IsKeyUp(Keys.D) && ShipLocation != Location.right)
                    {
                        DirectionSpeed = 0.0005f;
                        ShipLocation++;
                        MoveRight = 0;
                        if (level.GameObjects.Any(item => item is Enemy))
                        {
                            Enemy enemy = (Enemy)level.GameObjects.First(item => item is Enemy);
                            enemy.ShootTimer = 90;
                            enemy.MoveTimer  = 30;
                        }
                    }
                }

                // Left
                if (MoveLeft > 0)
                {
                    MoveLeft--;
                    if (Globals.KState.IsKeyDown(Keys.A) && Globals.PrevKState.IsKeyUp(Keys.A) && ShipLocation != Location.left)
                    {
                        DirectionSpeed = -0.0005f;
                        ShipLocation--;
                        MoveLeft = 0;
                        if (level.GameObjects.Any(item => item is Enemy))
                        {
                            Enemy enemy = (Enemy)level.GameObjects.First(item => item is Enemy);
                            enemy.ShootTimer = 90;
                            enemy.MoveTimer  = 30;
                        }
                    }
                }
            }
            else
            {
                Animation();
                Direction = MathHelper.Lerp(Direction, (float)Math.PI, 0.03f);
                Speed    += 0.1f;
                Position += new Vector2((float)Math.Cos(Direction) * Speed, (float)Math.Sin(Direction) * Speed);

                if (Dead == true)
                {
                    Speed     -= 0.06f;
                    Direction += MathHelper.Lerp(-0.15f, 0.15f, (float)Globals.Randomizer.NextDouble());
                    for (int i = 0; i < Globals.Randomizer.Next(1, 2); i++)
                    {
                        level.ToAdd.Add(new Piece(new Vector2(Position.X + Globals.Randomizer.Next(-20, 20), Position.Y + Globals.Randomizer.Next(-20, 20)), Texture, 60, 0.5f));
                        level.ToAdd.Add(new Piece(new Vector2(Position.X + Globals.Randomizer.Next(-20, 20), Position.Y + Globals.Randomizer.Next(-20, 20)), TextureManager.explosion, 60, 1.5f));
                    }
                }
            }
        }
Example #9
0
        public void UpdateInventory()
        {
            // Crafting
            if (currentlyCrafting > 0)
            {
                for (int i = 0; i < Globals.Randomizer.Next(5, 10); i++)
                {
                    SceneManager.GameObjects.Add(new Piece(new Vector2(864, 350), TextureManager.explosion, 90, 1.5f));
                }
            }

            craft.Update();
            currentlyCrafting--;
            if (CanCraft() && currentlyCrafting < 0)
            {
                if (craft.Press())
                {
                    currentlyCrafting = 60;
                    SoundManager.craft.Play();
                }
            }
            if (currentlyCrafting == 0)
            {
                SoundManager.explosion.Play();
                int itemLevel = (int)((Inventory[0, 6].ItemLevel + Inventory[1, 6].ItemLevel + Inventory[2, 6].ItemLevel) / 3 + MathHelper.Lerp(-0.2f, 0.2f, (float)Globals.Randomizer.NextDouble()));
                Inventory[0, 6] = new Item(Globals.Nothing);
                Inventory[1, 6] = new Item(Globals.Nothing);
                Inventory[2, 6] = new Item(Globals.Nothing);
                if (Inventory[3, 6].Type != ItemType.nothing)
                {
                    AddItem(Inventory[3, 6]);
                }
                int random = Globals.Randomizer.Next(0, 3);
                if (random == 0)
                {
                    Inventory[3, 6] = new Weapon(this, Globals.Randomizer.Next(0, Weapon.ListOfMethods().Count()), itemLevel);
                }
                else if (random == 1)
                {
                    Inventory[3, 6] = new Hull(this, Globals.Randomizer.Next(0, Hull.ListOfHullMethods().Count()), itemLevel);
                }
                else if (random == 2)
                {
                    Inventory[3, 6] = new Shield(new Vector2(200, Globals.ScreenSize.Y - 35), 100, 20, 60 + itemLevel * 20 + Globals.Randomizer.Next(-5, 15), Globals.Randomizer.Next(0, Shield.ListOfShieldMethods().Count()), itemLevel);
                }
            }

            for (int i = 0; i < Inventory.GetLength(0); i++)
            {
                for (int j = 0; j < Inventory.GetLength(1); j++)
                {
                    if (Inventory[i, j].Pressed() && Inventory[i, j].Type != ItemType.nothing)
                    {
                        selectedItem = Inventory[i, j];
                        selectedItemArrayPosition = new Point(i, j);
                    }

                    // Right click
                    if (Inventory[i, j].PressedRight() && Inventory[i, j].Type != ItemType.nothing)
                    {
                        Inventory[i, j].UseItem(this, Inventory[i, j]);
                    }
                }
            }

            if (Globals.MState.LeftButton == ButtonState.Released)
            {
                if (selectedItem != null)
                {
                    // Move item in inventory
                    for (int i = 0; i < Inventory.GetLength(0); i++)
                    {
                        for (int j = 0; j < Inventory.GetLength(1); j++)
                        {
                            if (Inventory[i, j].HoverOver())
                            {
                                if ((i == 0 && j == 5) || (selectedItemArrayPosition.X == 0 && selectedItemArrayPosition.Y == 5)) // shield
                                {
                                    if (selectedItem.Type == ItemType.shield && Inventory[i, j].Type == ItemType.shield)
                                    {
                                        SwapItem(new Point(i, j));
                                        break;
                                    }
                                }
                                else if ((i == 1 && j == 5) || (selectedItemArrayPosition.X == 1 && selectedItemArrayPosition.Y == 5)) // hull
                                {
                                    if (selectedItem.Type == ItemType.hull && Inventory[i, j].Type == ItemType.hull)
                                    {
                                        SwapItem(new Point(i, j));
                                        break;
                                    }
                                }
                                else if ((i > 1 && j == 5) || (selectedItemArrayPosition.X > 1 && selectedItemArrayPosition.Y == 5)) // weapons
                                {
                                    if ((((selectedItem.Type == ItemType.weapon || Inventory[i, j].Type == ItemType.weapon) && Inventory[i, j].Type == ItemType.nothing) && (Weapons.Count > 1 || !Weapons.Any(item => item == selectedItem)) || (selectedItem.Type == ItemType.weapon && Inventory[i, j].Type == ItemType.weapon)))
                                    {
                                        int numberOfWeapons = Weapons.Count();
                                        SwapItem(new Point(i, j));
                                        if (numberOfWeapons > Weapons.Count())
                                        {
                                            SelectedWeapon = 0;
                                        }
                                        break;
                                    }
                                }
                                else if (!(i > 2 && j == 6)) // inventory
                                {
                                    SwapItem(new Point(i, j));
                                    break;
                                }
                            }
                        }
                    }
                }

                selectedItem = null;
                selectedItemArrayPosition = new Point(0, 0);

                // remove
                for (int i = Inventory.GetLength(0) - 1; i >= 0; i--)
                {
                    for (int j = Inventory.GetLength(1) - 1; j >= 0; j--)
                    {
                        if (Inventory[i, j].Dead)
                        {
                            Inventory[i, j] = new Item(Item.Nothing, ItemType.nothing, TextureManager.none, "", "");
                        }
                    }
                }
            }
        }
Example #10
0
        public UnitCalculation(Unit unit, int repairers, SharkyUnitData sharkyUnitData, SharkyOptions sharkyOptions, UnitDataService unitDataService, int frame)
        {
            TargetPriorityCalculation = new TargetPriorityCalculation();
            oneSecondInFrames         = sharkyOptions.FramesPerSecond;

            //PreviousUnits = new Dictionary<int, Unit>();
            //PreviousUnits[frame] = unit;
            PreviousUnit = unit;
            Unit         = unit;
            UnitTypeData = sharkyUnitData.UnitData[(UnitTypes)unit.UnitType];

            Velocity        = 0;
            AverageVelocity = 0;
            Vector          = Vector2.Zero;
            AverageVector   = Vector2.Zero;
            Position        = new Vector2(unit.Pos.X, unit.Pos.Y);

            FrameLastSeen = frame;

            var unitRange = unitDataService.GetRange(unit);

            if (unitRange == 0)
            {
                Range = 0;
            }
            else
            {
                Range = unitRange + unit.Radius;
            }

            Start = new Vector2(unit.Pos.X, unit.Pos.Y);

            if (unit.UnitType == (uint)UnitTypes.PROTOSS_COLOSSUS || unit.UnitType == (uint)UnitTypes.PROTOSS_IMMORTAL || unit.UnitType == (uint)UnitTypes.PROTOSS_PHOTONCANNON || unit.UnitType == (uint)UnitTypes.PROTOSS_MOTHERSHIP ||
                unit.UnitType == (uint)UnitTypes.TERRAN_MISSILETURRET ||
                unit.UnitType == (uint)UnitTypes.ZERG_SPORECRAWLER || unit.UnitType == (uint)UnitTypes.ZERG_SPINECRAWLER)
            {
                End = Start; // facing is always 0 for these units, can't calculate where they're aiming
            }
            else
            {
                var endX = (float)(Range * Math.Sin(unit.Facing + (Math.PI / 2)));
                var endY = (float)(Range * Math.Cos(unit.Facing + (Math.PI / 2)));
                End = new Vector2(endX + unit.Pos.X, unit.Pos.Y - endY);
            }

            DamageRadius      = 1; // TODO: get damage radius
            EstimatedCooldown = 0; // TODO: get estimated cooldown

            DamageAir = false;
            if (unitDataService.CanAttackAir((UnitTypes)unit.UnitType))
            {
                DamageAir = true;
            }
            DamageGround = false;
            if (unitDataService.CanAttackGround((UnitTypes)unit.UnitType))
            {
                DamageGround = true;
            }
            Damage  = unitDataService.GetDamage(unit);
            Dps     = unitDataService.GetDps(unit);
            Weapon  = unitDataService.GetWeapon(unit);
            Weapons = UnitTypeData.Weapons.ToList();
            if (Weapons == null || Weapons.Count() == 0)
            {
                Weapons = new List <Weapon>();
                if (Weapon != null)
                {
                    Weapons.Add(Weapon);
                }
            }

            SimulatedHitpoints = Unit.Health + Unit.Shield;
            if (Unit.BuffIds.Contains((uint)Buffs.IMMORTALOVERLOAD))
            {
                SimulatedHitpoints += 100;
            }
            if (unit.UnitType == (uint)UnitTypes.PROTOSS_WARPPRISM)
            {
                SimulatedHitpoints += 500;
            }

            if (sharkyUnitData.ZergTypes.Contains((UnitTypes)Unit.UnitType))
            {
                SimulatedHealPerSecond = 0.38f;
            }
            else if (repairers > 0 && UnitTypeData.Attributes.Contains(SC2APIProtocol.Attribute.Mechanical))
            {
                SimulatedHealPerSecond = (float)(unit.HealthMax / (UnitTypeData.BuildTime / sharkyOptions.FramesPerSecond)) * repairers;
            }
            else if (Unit.UnitType == (uint)UnitTypes.TERRAN_MEDIVAC && Unit.Energy > 10)
            {
                SimulatedHealPerSecond = 12.6f;
            }
            else if (Unit.UnitType == (uint)UnitTypes.ZERG_QUEEN && Unit.Energy >= 50)
            {
                SimulatedHealPerSecond = 20;
            }
            else
            {
                SimulatedHealPerSecond = 0;
            }

            if (Unit.UnitType == (uint)UnitTypes.TERRAN_BUNKER && Unit.BuildProgress == 1) // assume 4 marines
            {
                Range        = 6;
                DamageAir    = true;
                DamageGround = true;
                Damage       = 6;
                Dps          = Damage * 4 / 0.61f;
            }

            Attributes = UnitTypeData.Attributes;

            UnitClassifications = new List <UnitClassification>();
            if (UnitTypeData.Attributes.Contains(SC2APIProtocol.Attribute.Structure))
            {
                if (sharkyUnitData.ResourceCenterTypes.Contains((UnitTypes)unit.UnitType))
                {
                    UnitClassifications.Add(UnitClassification.ResourceCenter);
                    UnitClassifications.Add(UnitClassification.ProductionStructure);
                }
                if (sharkyUnitData.DefensiveStructureTypes.Contains((UnitTypes)unit.UnitType))
                {
                    UnitClassifications.Add(UnitClassification.DefensiveStructure);
                }
            }
            else if (unit.UnitType == (uint)UnitTypes.TERRAN_SCV || unit.UnitType == (uint)UnitTypes.PROTOSS_PROBE || unit.UnitType == (uint)UnitTypes.ZERG_DRONE)
            {
                UnitClassifications.Add(UnitClassification.Worker);
            }
            else if (unit.UnitType == (uint)UnitTypes.ZERG_QUEEN || unit.UnitType == (uint)UnitTypes.TERRAN_MULE || unit.UnitType == (uint)UnitTypes.ZERG_OVERLORD || unit.UnitType == (uint)UnitTypes.ZERG_LARVA || unit.UnitType == (uint)UnitTypes.ZERG_EGG)
            {
            }
            else
            {
                UnitClassifications.Add(UnitClassification.ArmyUnit);
            }

            if (sharkyUnitData.DetectionTypes.Contains((UnitTypes)unit.UnitType))
            {
                UnitClassifications.Add(UnitClassification.Detector);
            }
            if (sharkyUnitData.AbilityDetectionTypes.Contains((UnitTypes)unit.UnitType))
            {
                UnitClassifications.Add(UnitClassification.DetectionCaster);
            }
            if (sharkyUnitData.CloakableAttackers.Contains((UnitTypes)unit.UnitType))
            {
                UnitClassifications.Add(UnitClassification.Cloakable);
            }

            EnemiesInRange   = new List <UnitCalculation>();
            EnemiesInRangeOf = new List <UnitCalculation>();
            NearbyAllies     = new List <UnitCalculation>();
            NearbyEnemies    = new List <UnitCalculation>();
            Attackers        = new List <UnitCalculation>();
            IncomingDamage   = 0;
        }