/// <summary>
 /// Moves the Invisible Projectile
 /// </summary>
 void Move()
 {
     vEntityPosition -= MainMap.GetDiffTileMapPosition() - vDirection / 5 * iVelocity;
 }
 /// <summary>
 /// Updates the Invisible Projectile
 /// </summary>
 public void Update()
 {
     StartPosition -= MainMap.GetDiffTileMapPosition();
     Move();
     cShape.Position = vEntityPosition;
 }
Beispiel #3
0
        /// <summary>
        /// Updates PathFinder Logic of the Archer.
        /// Moves the Enemy to the Player once the Pathfinding Algorithm was initiated.
        /// The Archer follows the created nodes, but still respects Collisions with Tiles.
        /// </summary>
        protected void PathfinderLogic()
        {
            bool MovingUp    = false;
            bool MovingDown  = false;
            bool MovingRight = false;
            bool MovingLeft  = false;

            if (MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X - 1) / 50), (int)(vEntityPosition.Y / 50)) ||
                MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X - 1) / 50), (int)((vEntityPosition.Y + 25) / 50)) ||
                MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X - 1) / 50), (int)((vEntityPosition.Y + 49) / 50)))
            {
                MovingLeft = true;
            }

            if (MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X + 50) / 50), (int)(vEntityPosition.Y / 50)) ||
                MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X + 50) / 50), (int)((vEntityPosition.Y + 25) / 50)) ||
                MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X + 50) / 50), (int)((vEntityPosition.Y + 49) / 50)))
            {
                MovingRight = true;
            }

            if (MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X) / 50), (int)((vEntityPosition.Y - 1) / 50)) ||
                MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X + 25) / 50), (int)((vEntityPosition.Y - 1) / 50)) ||
                MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X + 49) / 50), (int)((vEntityPosition.Y - 1) / 50)))
            {
                MovingUp = true;
            }

            if (MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X) / 50), (int)((vEntityPosition.Y + 50) / 50)) ||
                MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X + 25) / 50), (int)((vEntityPosition.Y + 50) / 50)) ||
                MainMap.GetTileManager().GetCollisionAt(((int)(vEntityPosition.X + 49) / 50), (int)((vEntityPosition.Y + 50) / 50)))
            {
                MovingDown = true;
            }

            if (Path.Count - 1 >= 0)
            {
                CurrentGoal       = (Vector2i)Path[Path.Count - 1].vPosition + (Vector2i)MainMap.GetTileMapPosition() + new Vector2i(25, 25);
                CurrentGoalOrigin = CurrentGoal - (Vector2i)sEntity.Position;
                float MovementX = (CurrentGoalOrigin.X / Utilities.MakePositive(Utilities.DistanceToVectorFromOrigin(new Vector2f(CurrentGoalOrigin.X, 0))));
                float MovementY = (CurrentGoalOrigin.Y / Utilities.MakePositive(Utilities.DistanceToVectorFromOrigin(new Vector2f(0, CurrentGoalOrigin.Y))));


                int PositionX1 = (int)((vEntityPosition.X + MovementX) / 50);
                int PositionY1 = (int)((vEntityPosition.Y + MovementY) / 50);

                int PositionX = (int)((vEntityPosition.X) / 50);
                int PositionY = (int)((vEntityPosition.Y) / 50);

                if (!MovementX.Equals(0 / Zero))
                {
                    if (CurrentGoalOrigin.X > 0 && !MovingRight)
                    {
                        vEntityPosition.X += fSpeed;
                    }
                    if (CurrentGoalOrigin.X < 0 && !MovingLeft)
                    {
                        vEntityPosition.X -= fSpeed;
                    }
                }

                if (!MovementY.Equals(0 / Zero))
                {
                    if (CurrentGoalOrigin.Y > 0 && !MovingDown)
                    {
                        vEntityPosition.Y += fSpeed;
                    }
                    if (CurrentGoalOrigin.Y < 0 && !MovingUp)
                    {
                        vEntityPosition.Y -= fSpeed;
                    }
                }

                if (sEntity.Position.X - 15 <= CurrentGoal.X && sEntity.Position.X + 15 >= CurrentGoal.X &&
                    sEntity.Position.Y - 15 <= CurrentGoal.Y && sEntity.Position.Y + 15 >= CurrentGoal.Y)
                {
                    Path.RemoveAt(Path.Count - 1);
                }

                RotateEnemy(ref fAngle, vRegisteredPlayerPosition + MainMap.GetTileMapPosition() + (vEnemyDirection - sEntity.Position));
            }
        }
Beispiel #4
0
        // DECLARING METHODS: MOVEMENT

        /// <summary>
        /// Moves Archer Randomly, but always to a Position within the DetectionRadius and respecting Collision with Tiles. The Archer doesn't psush the Player around.
        /// </summary>
        protected override void Move()
        {
            bCollisionUp    = false;
            bCollisionDown  = false;
            bCollisionRight = false;
            bCollisionLeft  = false;
            bool nearright = false;
            bool nearleft  = false;
            bool nearup    = false;
            bool neardown  = false;


            bool bRepeat    = false;
            int  iRepeating = 0;

            Vector2f vCharacterPositionEnemyOrigin = MainMap.GetStartCharacterPosition() + new Vector2f(25, 25) - sEntity.Position;

            CollisionDetection(ref vEntityPosition, ref bCollisionUp, ref bCollisionDown, ref bCollisionRight, ref bCollisionLeft, tEntity.Size.X, tEntity.Size.Y);
            EnemyEnemyCollision(ref vEntityPosition, ref bCollisionUp, ref bCollisionDown, ref bCollisionRight, ref bCollisionLeft);

            tMoving = cMoving.ElapsedTime;

            if (tMoving.AsMilliseconds() > 500)
            {
                iRandomNumber = rRandom.Next(0, 4);
                cMoving.Restart();
            }

            // Enemy does not Push the Player around
            if (Utilities.MakePositive(MainMap.GetStartCharacterPosition().X + 25 - vEnemyDirection.X + fSpeed) < 50 &&
                Utilities.MakePositive(MainMap.GetStartCharacterPosition().Y + 25 - vEnemyDirection.Y) < 50)
            {
                bCollisionLeft = true;
            }

            if (Utilities.MakePositive(MainMap.GetStartCharacterPosition().X + 25 - vEnemyDirection.X - fSpeed) < 50 &&
                Utilities.MakePositive(MainMap.GetStartCharacterPosition().Y + 25 - vEnemyDirection.Y) < 50)
            {
                bCollisionRight = true;
            }

            if (Utilities.MakePositive(MainMap.GetStartCharacterPosition().X + 25 - vEnemyDirection.X) < 50 &&
                Utilities.MakePositive(MainMap.GetStartCharacterPosition().Y + 25 - vEnemyDirection.Y + fSpeed) < 50)
            {
                bCollisionUp = true;
            }

            if (Utilities.MakePositive(MainMap.GetStartCharacterPosition().X + 25 - vEnemyDirection.X) < 50 &&
                Utilities.MakePositive(MainMap.GetStartCharacterPosition().Y + 25 - vEnemyDirection.Y - fSpeed) < 50)
            {
                bCollisionDown = true;
            }


            float CharacterPosEnemyOriginX = MainMap.GetVirtualCharacterPosition().X - vEntityPosition.X;
            float CharacterPosEnemyOriginY = MainMap.GetVirtualCharacterPosition().Y - vEntityPosition.Y;

            // Enemy does not accidently hide behind Tiles with Collision
            if (CharacterPosEnemyOriginX > 0 &&
                DisposingInvisibleListLeft && !DisposingInvisibleListRight ||

                CharacterPosEnemyOriginX < 0 &&
                !DisposingInvisibleListLeft && DisposingInvisibleListRight)
            {
                bCollisionDown = true;
            }

            else if (CharacterPosEnemyOriginX > 0 &&
                     !DisposingInvisibleListLeft && DisposingInvisibleListRight ||
                     CharacterPosEnemyOriginX < 0 &&
                     DisposingInvisibleListLeft && !DisposingInvisibleListRight)
            {
                bCollisionUp = true;
            }

            if (CharacterPosEnemyOriginY > 0 &&
                DisposingInvisibleListLeft && !DisposingInvisibleListRight ||
                CharacterPosEnemyOriginY < 0 &&
                !DisposingInvisibleListLeft && DisposingInvisibleListRight)
            {
                bCollisionLeft = true;
            }

            else if (CharacterPosEnemyOriginY > 0 &&
                     !DisposingInvisibleListLeft && DisposingInvisibleListRight ||
                     CharacterPosEnemyOriginY < 0 &&
                     DisposingInvisibleListLeft && !DisposingInvisibleListRight)
            {
                bCollisionRight = true;
            }


            // Enemy does not go outside a specific range of the Player
            if (vCharacterPositionEnemyOrigin.X > (-iDistanceDetection / 2) ||
                vCharacterPositionEnemyOrigin.X < (iDistanceDetection / 2))
            {
                if (vCharacterPositionEnemyOrigin.Y < (iDistanceDetection / 2))
                {
                    nearup = true;
                }
                if (vCharacterPositionEnemyOrigin.Y > (-iDistanceDetection / 2))
                {
                    neardown = true;
                }
            }

            if (vCharacterPositionEnemyOrigin.Y < (iDistanceDetection / 2) ||
                vCharacterPositionEnemyOrigin.Y > (-iDistanceDetection / 2))
            {
                if (vCharacterPositionEnemyOrigin.X > (-iDistanceDetection / 2))
                {
                    nearright = true;
                }
                if (vCharacterPositionEnemyOrigin.X < (iDistanceDetection / 2))
                {
                    nearleft = true;
                }
            }


            do
            {
                if (bRepeat)
                {
                    bRepeat       = false;
                    iRandomNumber = rRandom.Next(0, 4);
                    iRepeating++;
                }

                switch (iRandomNumber)
                {
                case (0):
                    if (nearup && !bCollisionUp)
                    {
                        MoveUp();
                    }
                    else
                    {
                        bRepeat = true;
                    }
                    break;

                case (1):
                    if (neardown && !bCollisionDown)
                    {
                        MoveDown();
                    }
                    else
                    {
                        bRepeat = true;
                    }
                    break;

                case (2):
                    if (nearright && !bCollisionRight)
                    {
                        MoveRight();
                    }
                    else
                    {
                        bRepeat = true;
                    }
                    break;

                case (3):
                    if (nearleft && !bCollisionLeft)
                    {
                        MoveLeft();
                    }
                    else
                    {
                        bRepeat = true;
                    }
                    break;
                }
            }while (bRepeat && iRepeating <= 2);
        }
 /// <summary>
 /// Moves the PlayerProjectile
 /// </summary>
 void Move()
 {
     vEntityPosition -= vDirection * 5 + MainMap.GetDiffTileMapPosition() + vPlayerMovement;
 }
Beispiel #6
0
        /// <summary>
        /// Detects the Entity Collision
        /// Returns 0 if no Collision
        /// </summary>
        protected int CollisionDetection(Vector2f vEntityPosition, uint uLength, uint uHeight)
        {
            Vector2f vEntityPos = vEntityPosition - MainMap.GetTileMapPosition();

            vEntityPositionBottomLeft.Y = vEntityPos.Y + uHeight;
            vEntityPositionTopRight.X   = vEntityPos.X + uLength;

            int iTileNearY = (int)vEntityPos.Y / 50;
            int iTileNearX = (int)vEntityPos.X / 50;

            if (iTileNearY < 0)
            {
                iTileNearY++;
            }

            if (iTileNearX < 0)
            {
                iTileNearX++;
            }

            for (int y = iTileNearY; y < iTileNearY + 2; y++)
            {
                for (int x = iTileNearX; x < iTileNearX + 2; x++)
                {
                    // COLLISIONDETECTION ON ENTITY BORDER

                    if (TileArrayCreation.CollisionReturner(x, y))
                    {
                        if (((vEntityPos.Y < (y + 1) * 50 && vEntityPos.Y > y * 50 - 1) ||
                             (vEntityPos.Y < y * 50 && vEntityPos.Y > (y - 1) * 50)))
                        {
                            if (vEntityPos.X <= (x + 1) * 50 && vEntityPos.X >= x * 50)
                            {
                                return(1);
                            }

                            else if (vEntityPositionTopRight.X >= x * 50 && vEntityPositionTopRight.X <= (x + 1) * 50)
                            {
                                return(2);
                            }
                        }


                        if (((vEntityPos.X < (x + 1) * 50 && vEntityPos.X > x * 50 - 1) ||
                             (vEntityPositionTopRight.X > x * 50 && vEntityPositionTopRight.X < (x + 1) * 50)))
                        {
                            if (vEntityPos.Y <= (y + 1) * 50 && vEntityPos.Y >= y * 50)
                            {
                                return(3);
                            }


                            else if (vEntityPositionBottomLeft.Y >= y * 50 && vEntityPositionBottomLeft.Y <= (y + 1) * 50)
                            {
                                return(4);
                            }
                        }
                    }
                }
            }
            return(0);
        }