Beispiel #1
0
        private Hostile FindClosestTarget()
        {
            Hostile result = null;
            int     smallestHeursticValue = 0;

            foreach (GameObject gameObject in source.map.gameObjectList)
            {
                Hostile hostile = gameObject as Hostile;
                if (hostile != null && hostile != source)
                {
                    smallestHeursticValue = aStarCalculator.FindHeuristicValue(hostile.position, position);
                    result = hostile;
                    break;
                }
            }
            foreach (GameObject gameObject in source.map.gameObjectList)
            {
                Hostile hostile = gameObject as Hostile;
                if (hostile != null && hostile != source)
                {
                    int heursticValue = aStarCalculator.FindHeuristicValue(gameObject.position, position);
                    if (heursticValue < smallestHeursticValue)
                    {
                        smallestHeursticValue = heursticValue;
                        result = hostile;
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        public void RemoveObject(GameObject gameObject)
        {
            //hostile list
            Hostile hostile = gameObject as Hostile;

            if (hostile != null)
            {
                hostilesList.Remove(hostile);
                foreach (GameObject gameObject2 in gameObjectList)
                {
                    Enemy enemy = gameObject2 as Enemy;
                    if (enemy != null)
                    {
                        enemy.hostilesList = hostilesList;
                    }
                }
            }


            if (gameObject.getLightSource != null)
            {
                lightsList.Remove(gameObject.getLightSource);
            }

            Player player = gameObject as Player;

            if (player != null)
            {
            }

            gameObjectList.Remove(gameObject);
        }
Beispiel #3
0
        public void AddObject(GameObject gameObject)
        {
            //hostile list
            Enemy enemy = gameObject as Enemy;

            if (enemy != null)
            {
                enemy.hostilesList = hostilesList;
            }
            else
            {
                Hostile hostile = gameObject as Hostile;
                if (hostile != null)
                {
                    hostilesList.Add(hostile);
                    foreach (GameObject gameObject2 in gameObjectList)
                    {
                        Enemy enemy2 = gameObject2 as Enemy;
                        if (enemy2 != null)
                        {
                            enemy2.hostilesList = hostilesList;
                        }
                    }
                }
            }

            IntializeMapVariables(gameObject);

            if (gameObject.getLightSource != null)
            {
                lightsList.Add(gameObject.getLightSource);
            }

            gameObjectList.Add(gameObject);
        }
Beispiel #4
0
        public HostileHUD(Hostile hostile)
        {
            //intialize player
            this.hostile = hostile;

            //intialize hearts list
            CreateHearts();
        }
Beispiel #5
0
 public void Colide(Hostile target)
 {
     if (hitSound != null)
     {
         hitSound.Play();
     }
     target.DealDamage(source, sourceDamage, strength);
     Kill();
 }
Beispiel #6
0
        public ChooseSkill(Player player)
        {
            this.player = player;

            currentBranch = player.skillTree.skillBranches[player.stats.level - 1];
            window        = new Window(player.map, Game.content.Load <Texture2D>("Textures\\Windows\\windowskin"), new Vector2(20), 920, 500);
            Text    skillText1    = new Text(Game.content.Load <SpriteFont>("Fonts\\medival1"), Vector2.Zero, currentBranch.skill1.color, currentBranch.skill1.name, window, new Vector2(2, 5));
            Text    skillText2    = new Text(Game.content.Load <SpriteFont>("Fonts\\medival1"), Vector2.Zero, currentBranch.skill2.color, currentBranch.skill2.name, window, new Vector2(2, 5));
            Picture skillPicture1 = new Picture(currentBranch.skill1.choosePicture, Vector2.Zero, window);
            Picture skillPicture2 = new Picture(currentBranch.skill2.choosePicture, Vector2.Zero, window);

            skillPicture1.position.X += 100;
            skillPicture1.position.Y += 60;

            skillPicture2.position.X  = window.bounds.Width - skillPicture2.bounds.Width - 100;
            skillPicture2.position.Y += 60;



            skillText1.position.X = skillPicture1.position.X + skillPicture1.bounds.Width / 2 - skillText1.bounds.Width / 2;
            skillText1.position.Y = skillPicture1.position.Y + skillPicture1.bounds.Height;

            skillText2.position.X = skillPicture2.position.X + skillPicture2.bounds.Width / 2 - skillText2.bounds.Width / 2;
            skillText2.position.Y = skillPicture2.position.Y + skillPicture2.bounds.Height;

            List <Hostile.Stat> statsList = Hostile.StatsToStatList(currentBranch.changeStats1);

            for (int i = 0; i < statsList.Count; i++)
            {
                Color color = Color.DimGray;
                if (statsList[i].value > 0)
                {
                    color = Color.LightBlue;
                }
                Text text = new Text(Game.content.Load <SpriteFont>("Fonts\\medival small"), new Vector2(0, 320), color, statsList[i].name + ": " + statsList[i].value, window);
                text.position.X  = skillPicture1.position.X + skillPicture1.bounds.Width / 2 - text.bounds.Width / 2;
                text.position.Y += i * text.bounds.Height + 10;
            }

            statsList = Hostile.StatsToStatList(currentBranch.changeStats2);
            for (int i = 0; i < statsList.Count; i++)
            {
                Color color = Color.DimGray;
                if (statsList[i].value > 0)
                {
                    color = Color.LightBlue;
                }
                Text text = new Text(Game.content.Load <SpriteFont>("Fonts\\medival small"), new Vector2(0, 320), color, statsList[i].name + ": " + statsList[i].value, window);
                text.position.X  = skillPicture2.position.X + skillPicture2.bounds.Width / 2 - text.bounds.Width / 2;
                text.position.Y += i * text.bounds.Height + 10;
            }

            selector = new Selector(player, new List <WindowItem>()
            {
                skillText1, skillText2
            }, HandleItemChoice, new Vector2(), 10, 2, window);
        }
Beispiel #7
0
        protected override void UpdateEnemy()
        {
            //update movement

            /*
             * the enemy has 3 modes:
             * chill mode: the enemy is ba chill.
             * search mode: the enemy is searching for a target.
             * hunt mode: the enemy hunts his pray until his pray dies or runs away.
             */

            switch (enemyIA)
            {
            case EnemyAI.hunt:
                if (reConstructWayToTargetTimer.result)
                {
                    MoveToTarget(currentTarget);
                    reConstructWayToTargetTimer.Reset();
                }
                if (!raduis.Intersects(currentTarget.core) || !currentTarget.alive)
                {
                    enemyIA = EnemyAI.chill;
                    destinationsList.Clear();
                }
                break;

            case EnemyAI.search:

                break;

            case EnemyAI.chill:
                int targetsNotInRaduis = 0;
                foreach (Hostile target in hostilesList)
                {
                    if (raduis.Intersects(target.core) && target.alive)
                    {
                        currentTarget = target;
                        enemyIA       = EnemyAI.hunt;
                    }
                    else
                    {
                        targetsNotInRaduis++;
                    }
                }
                if (targetsNotInRaduis == hostilesList.Count)
                {
                    enemyIA = EnemyAI.chill;
                }
                autoMovement = MovementManager.Auto.random;
                break;
            }
        }
Beispiel #8
0
 public void DrawWindows(SpriteBatch spriteBatch)
 {
     if (player.alive)
     {
         player.DrawPlayerItems(spriteBatch, mapRect);
         foreach (GameObject gameObject in player.map.gameObjectList)
         {
             Hostile hostile = gameObject as Hostile;
             if (hostile != null)
             {
                 hostile.DrawDmg(spriteBatch, mapRect);
             }
         }
     }
 }
Beispiel #9
0
        private static void UpdateMineCollision(GameObject gameObject, GameObject colidedWith)
        {
            //mine and hostile
            Hostile hostile = colidedWith as Hostile;

            if (hostile != null)
            {
                Mine mine = gameObject as Mine;
                if (CollisionManager.GameObjectCollision(hostile, mine, false) && hostile != mine.source)
                {
                    hostile.DealDamage(mine.source, false, mine.strength);
                    mine.Kill();
                }
            }
        }
Beispiel #10
0
        private void MoveToTarget(Hostile target)
        {
            MovingState  = MovementManager.MovingState.walking;
            autoMovement = MovementManager.Auto.off;
            movementManager.HighlightWayTo(new Vector2(core.X, core.Y), new Vector2(target.core.X, target.core.Y), raduis);
            List <Vector2> way = movementManager.WayTo(new Vector2(core.X, core.Y), new Vector2(target.core.X, target.core.Y), raduis);

            if (way != null)
            {
                destinationsList = way;
            }
            //MovingState = MovementManager.MovingState.walking;
            //autoMovement = MovementManager.Auto.off;
            //direction = MovementManager.DirectionToGameObject(this, target);
            //movementManager.MoveActor(this, direction, (int)speed);
        }
Beispiel #11
0
        protected override void UpdateProjectile()
        {
            //-update movement
            switch (movingType)
            {
            case MovingState.straight:
                if (!wayAssigned)
                {
                    StartAnimation(direction);
                    wayAssigned = true;
                }
                movementManager.MoveToDirection(this, direction, (int)this.speed);
                pathTravelled += (int)speed;
                if (pathTravelled - pathDestination >= 0 && pathTravelled - pathDestination < speed)
                {
                    Finish();
                }
                break;

            case MovingState.homing:
                if (wayAssigned)
                {
                    if (destinationsList.Count == 0)
                    {
                        Finish();
                    }
                }
                else
                {
                    StartAnimation(direction);
                    Hostile target = FindClosestTarget();
                    destinationsList = movementManager.WayTo(new Vector2(core.X, core.Y), new Vector2(target.core.X, target.core.Y));
                    wayAssigned      = true;
                }
                break;
            }
        }
Beispiel #12
0
        public void DealDamage(Hostile source, bool sourceDamage = true, int damage = 0, bool showDamage = true)
        {
            if (cooldownTimer.result || cooldownTimer.counter == 0)
            {
                //set new health
                bool   noDamage     = false;
                bool   defending    = false;
                int    oldHealth    = stats.health;
                int    newHealth    = stats.health;
                Player thisAsPlayer = this as Player;
                if (thisAsPlayer != null)
                {
                    if (thisAsPlayer.defendingTimer.Counting)
                    {
                        defending = true;
                    }
                    else
                    {
                        if (damage == 0) // new health by stats
                        {
                            newHealth += stats.defence - source.stats.strength;
                        }
                        if (!sourceDamage) //new health by number
                        {
                            newHealth += stats.defence - damage;
                        }
                    }
                }
                else
                {
                    if (damage == 0) // new health by stats
                    {
                        newHealth += stats.defence - source.stats.strength;
                    }
                    if (!sourceDamage) //new health by number
                    {
                        newHealth += stats.defence - damage;
                    }
                }

                //limit damage to more than zero
                if (oldHealth - newHealth > -1)
                {
                    // limit health to zero
                    if (newHealth > 0)
                    {
                        stats.health = newHealth;
                    }
                    else
                    {
                        stats.health = 0;
                        Player sourceAsPlayer = source as Player;
                        if (sourceAsPlayer != null)
                        {
                            sourceAsPlayer.AddExp(stats.exp);
                        }
                        fade = true;
                        Kill();
                    }
                }
                else
                {
                    noDamage = true;
                }

                //knockback
                MovementManager.Knockback(this, source.direction, source.stats.knockback);

                //durability
                for (int counter = 0; counter < equipmentList.Count; counter++)
                {
                    Armor armor = equipmentList[counter];
                    if (armor.armorType != Armor.ArmorType.oneHanded && armor.armorType != Armor.ArmorType.twoHanded)
                    {
                        armor.Durability--;
                    }
                }

                //update player hud and menu
                if (thisAsPlayer != null)
                {
                    thisAsPlayer.HandleHit(oldHealth - newHealth);
                }

                //timer
                cooldownTimer.Reset();

                //show damage
                if (showDamage)
                {
                    string text;
                    Color  color;
                    if (defending)
                    {
                        text  = "Defending";
                        color = Color.DimGray;
                    }
                    else if (noDamage)
                    {
                        text  = "0";
                        color = Color.DimGray;
                    }
                    else
                    {
                        text  = "" + (oldHealth - newHealth);
                        color = Color.Red;
                    }
                    dmgText = new Text(Game.content.Load <SpriteFont>("Fonts\\medival1"), Vector2.Zero, color, text, null, new Vector2(10, 10));

                    dmgText.position    = position;
                    dmgText.position.X += bounds.Width / 2 - dmgText.bounds.Width / 2;
                    dmgText.position.Y -= dmgText.bounds.Height - 20;

                    dmgTextTimer.Active();
                }
            }
        }
Beispiel #13
0
        public void SubItem(Item item)
        {
            if (item.amount > 1)
            {
                Text result = null;
                foreach (Item item2 in items)
                {
                    foreach (Text amount in representation.amountTexts)
                    {
                        if (item.icon.position == amount.position)
                        {
                            result = amount;
                        }
                    }
                }
                if (result != null)
                {
                    if (item.amount == 2)
                    {
                        representation.RemoveWindowItem(result, true, true);
                        representation.amountTexts.Remove(result);
                    }
                    else
                    {
                        result.text = item.amount - 1 + "X";
                    }
                }
                item.amount--;
                UpdatePlayerWeight(false);
                return;
            }

            if (representation.alive)
            {
                //remove price
                ShopInventory shopInventory = representation as ShopInventory;
                if (shopInventory != null)
                {
                    shopInventory.SubPrice(item.icon);
                }

                //remove window item
                representation.RemoveWindowItem(item.icon, true);
            }

            //check if the item is equiped
            Hostile hostile = source as Hostile;

            if (hostile != null)
            {
                Armor armor = item as Armor;
                if (armor != null)
                {
                    List <Armor> identicalArmorsList = new List <Armor>();
                    foreach (Armor armor2 in hostile.equipmentList)
                    {
                        if (armor.iconID == armor2.iconID)
                        {
                            identicalArmorsList.Add(armor2);
                        }
                    }
                    if (identicalArmorsList.Count == 1)
                    {
                        hostile.UnEquip(identicalArmorsList[0]);
                    }
                }
            }

            //remove item
            items.Remove(item);
            UpdatePlayerWeight(false);
        }