Exemplo n.º 1
0
        public static List <GameObjectBase> SelectionSortList(List <GameObjectBase> listToSort)
        {
            int min_index = 0;

            for (int i = 0; i < listToSort.Count - 1; i++)
            {
                min_index = i;

                for (int j = i + 1; j < listToSort.Count; j++)
                {
                    if (listToSort[j].Depth < listToSort[min_index].Depth)
                    {
                        min_index = j;
                    }
                }

                GameObjectBase a = listToSort[i];
                GameObjectBase b = listToSort[min_index];

                listToSort[i]         = b;
                listToSort[min_index] = a;
            }

            return(listToSort);
        }
Exemplo n.º 2
0
        private static void Swap(ref GameObjectBase a, ref GameObjectBase b)
        {
            GameObjectBase temp = a;

            a = b;
            b = temp;
        }
Exemplo n.º 3
0
        public void OnCollisionWithEntity(GameObjectBase entity)
        {
            MouseState state = Mouse.GetState();

            if (entity != null && state.LeftButton == ButtonState.Pressed)
            {
                EnemyGameObject enemy = entity as EnemyGameObject;

                if (enemy != null)
                {
                    if (enemy.IsAlive)
                    {
                        player.CanAttack = true;
                        player.target    = enemy;
                    }
                    return;
                }

                PotionGameObject potion = entity as PotionGameObject;

                if (potion != null)
                {
                    player.target       = potion;
                    player.retrieveItem = true;
                    return;
                }
                //SelectEnemy?.Invoke((object)enemy, new CollisionEventArgs(enemy.Position));
            }
        }
        public EnemyGameObject(Vector2 position, GameObjectBase player, int health, int maxHealth)
        {
            this.health    = health;
            this.maxHealth = maxHealth;

            Position    = position;
            this.target = player;
        }
Exemplo n.º 5
0
        public override void Update(GameTime gameTime)
        {
            this.gameTime = gameTime;

            isDying = (health <= 0);

            //if there is a selected target, make sure the target is alive before attacking.
            if (target != null)
            {
                targetPosition = target.Position;

                //if the target is an enemy and is no longer alive, set it to null, switch off canAttack, and set velocity to 0 to stop moving.
                if (target != null)
                {
                    EnemyGameObject enemy = target as EnemyGameObject;

                    if (enemy != null)
                    {
                        if (!enemy.IsAlive)
                        {
                            canAttack = false;
                            target    = null;
                            Velocity  = Vector2.Zero;
                        }
                    }
                }
            }

            if (!isDying)
            {
                if (state == PlayerState.Attack)
                {
                    sprite.PlayAnimation(attackAnimation);
                }
                else if (state == PlayerState.Walk || state == PlayerState.Chase)
                {
                    sprite.PlayAnimation(walkAnimation);
                }

                if (Vector2.Distance(lastMouseLocation, Position) < stoppingDistance)
                {
                    velocity = Vector2.Zero;
                }
                else
                {
                    Position += Velocity;
                }

                BoundingBox = BoundingRectangle;
            }
            else
            {
                sprite.PlayAnimation(death);
            }

            fsm.Update(gameTime);
        }
Exemplo n.º 6
0
        public void MoveTowardEntity(GameObjectBase obj, GameTime gameTime)
        {
            if (obj != null)
            {
                float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

                Vector2 directionToChase = obj.Position - Position;

                directionToChase.Normalize();
                Velocity = directionToChase * speed * elapsedTime;
            }
        }
        //Setting this to the base object allows an enemy to be set to chase an NPC, for example.
        public void MoveToward(GameObjectBase obj, GameTime gameTime)
        {
            if (sprite.Animation != idleAnimation)
            {
                sprite.PlayAnimation(idleAnimation);
            }

            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Vector2 directionToChase = obj.Position - Position;

            directionToChase.Normalize();
            Velocity  = directionToChase * speed * elapsedTime;
            direction = directionToChase;
        }