Example #1
0
        /// <summary>
        /// Alerts other Enemys in a determined Radius if Player is detected
        /// </summary>
        protected void Alert()
        {
            List <Enemy> lEnemy = MainMap.GetEnemies();

            for (int x = 0; x < lEnemy.Count; x++)
            {
                if (lEnemy[x].uID == uID || Utilities.DistanceBetweenVectors(lEnemy[x].GetVirtualPosition(), vEntityPosition) > iDistanceDetection / 2 || lEnemy[x].vRegisteredPlayerPosition != new Vector2f())
                {
                    continue;
                }

                lEnemy[x].vRegisteredPlayerPosition = MainMap.GetVirtualCharacterPosition();
            }
        }
Example #2
0
        /// <summary>
        /// Reduces Health of the Enemy if hit by PlayerProjectile
        /// </summary>
        /// <param name="iProjectile">Projectile that Collision with Enemy is checked</param>
        /// <param name="Damage">Damage inflicted to the Enemy if hit</param>
        /// <returns></returns>
        protected bool EnemyProjectileCollision(PlayerProjectile iProjectile, uint Damage)
        {
            List <Enemy> lEnemy;

            lEnemy = MainMap.GetEnemies();

            for (int x = 0; x < lEnemy.Count; x++)
            {
                Vector2f b = lEnemy[x].sEntity.Position;

                if (Utilities.DistanceBetweenVectors(iProjectile.vEntityPosition, b) <= 25)
                {
                    lEnemy[x].ReduceHealth(Damage, iProjectile.GetDirection());
                    return(true);
                }
            }
            return(false);
        }
Example #3
0
        /// <summary>
        /// Detects Collision between Enemies and returns Collision direction
        /// </summary>
        /// <param name="vEntityPosition">Position of the Enemy if Player would be moving, not the Map</param>
        /// <param name="up">Bool that prohibites Up-Movement of the Enemy if true</param>
        /// <param name="down">Bool that prohibites Down-Movement of the Enemy if true</param>
        /// <param name="right">Bool that prohibites Right-Movement of the Enemy if true</param>
        /// <param name="left">Bool that prohibites Left-Movement of the Enemy if true</param>
        protected void EnemyEnemyCollision(ref Vector2f vEntityPosition, ref bool up, ref bool down, ref bool right, ref bool left)
        {
            List <Enemy> lEnemy;

            lEnemy = MainMap.GetEnemies();


            for (int x = 0; x < lEnemy.Count; x++)
            {
                if (lEnemy[x].uID == uID)
                {
                    continue;
                }

                bEnemyPlayerCollision = false;

                Vector2f Entity2Position = lEnemy[x].vEntityPosition;

                if (((vEntityPosition.Y < Entity2Position.Y + 50 && vEntityPosition.Y > Entity2Position.Y - 1) ||
                     (vEntityPosition.Y < Entity2Position.Y && vEntityPosition.Y > Entity2Position.Y - 50)))
                {
                    if (vEntityPosition.X <= Entity2Position.X + 50 && vEntityPosition.X >= Entity2Position.X)
                    {
                        left = true;
                        vChracterPositionSpace.X = Entity2Position.X + 50;
                        bEnemyPlayerCollision    = true;
                    }

                    else if (vEntityPosition.X + 50 >= Entity2Position.X && vEntityPosition.X + 50 <= Entity2Position.X + 50)
                    {
                        right = true;
                        vChracterPositionSpace.X = Entity2Position.X - 50;
                        bEnemyPlayerCollision    = true;
                    }
                }


                if (((vEntityPosition.X < Entity2Position.X + 50 && vEntityPosition.X > Entity2Position.X - 1) ||
                     (vEntityPosition.X + 50 > Entity2Position.X && vEntityPosition.X + 50 < Entity2Position.X + 50)))
                {
                    if (vEntityPosition.Y <= Entity2Position.Y + 50 && vEntityPosition.Y >= Entity2Position.Y)
                    {
                        up = true;
                        vChracterPositionSpace.Y = Entity2Position.Y + 50;
                        bEnemyPlayerCollision    = true;
                    }


                    else if (vEntityPosition.Y + 50 >= Entity2Position.Y && vEntityPosition.Y + 50 <= Entity2Position.Y + 50)
                    {
                        down = true;
                        vChracterPositionSpace.Y = Entity2Position.Y - 50;
                        bEnemyPlayerCollision    = true;
                    }
                }


                //REPLACEMENT OF PLAYERLOCATION IN CASE OF CROSSING BORDER OF OBJECT

                if (bEnemyPlayerCollision)
                {
                    if (up && right)
                    {
                        if (vEntityPosition.X - vChracterPositionSpace.X < vChracterPositionSpace.Y - vEntityPosition.Y)
                        {
                            vEntityPosition.X = vChracterPositionSpace.X;
                        }

                        else
                        {
                            vEntityPosition.Y = vChracterPositionSpace.Y;
                        }
                    }


                    if (up && left)
                    {
                        if (vChracterPositionSpace.X - vEntityPosition.X < vChracterPositionSpace.Y - vEntityPosition.Y)
                        {
                            vEntityPosition.X = vChracterPositionSpace.X;
                        }
                        else
                        {
                            vEntityPosition.Y = vChracterPositionSpace.Y;
                        }
                    }


                    if (down && left)
                    {
                        if (vChracterPositionSpace.X - vEntityPosition.X < vEntityPosition.Y - vChracterPositionSpace.Y)
                        {
                            vEntityPosition.X = vChracterPositionSpace.X;
                        }
                        else
                        {
                            vEntityPosition.Y = vChracterPositionSpace.Y;
                        }
                    }


                    if (down && right)
                    {
                        if (vEntityPosition.X - vChracterPositionSpace.X < vEntityPosition.Y - vChracterPositionSpace.Y)
                        {
                            vEntityPosition.X = vChracterPositionSpace.X;
                        }
                        else
                        {
                            vEntityPosition.Y = vChracterPositionSpace.Y;
                        }
                    }
                }
            }
        }