Esempio n. 1
0
        public EnemyUpDown(Vector2 position, int distance = 100,
                           EnemyMoveDirection direction   = EnemyMoveDirection.Right) :
            base(position)
        {
            this.distance  = distance;
            enemyDirection = direction;

            if (enemyDirection == EnemyMoveDirection.Left)
            {
                startPoint = Position.X - distance;
                endPoint   = Position.X;
            }
            else
            {
                startPoint = Position.X;
                endPoint   = Position.X + distance;
            }

            this.Tag((int)GameTags.EnemyUpDown);
            texture       = Engine.Instance.Content.Load <Texture2D>("Enemy");
            arrow         = Engine.Instance.Content.Load <Texture2D>("Arrow");
            this.Collider = new Hitbox((float)20.0f, (float)10.0f, 0.0f, 0.0f);
            this.Visible  = true;

            gravity     = 0.3f;
            fallspeed   = 1.0f;
            climbspeed  = 2.5f;
            GravityTime = 3000.0f;

            Direction = GravityDirection.Down;
        }
Esempio n. 2
0
        public Enemy()
        {
            Array values = Enum.GetValues(typeof(EnemyMoveDirection));
            Random random = new Random();
            EnemyMoveDirection randomDirection = (EnemyMoveDirection)values.GetValue(random.Next(values.Length));
            this.moveDirection = randomDirection;

            //this.moveDirection = EnemyMoveDirection.downRight;
        }
Esempio n. 3
0
        private void EnemyAI()
        {
            if (startPoint == endPoint)
            {
                return;
            }

            if (Direction == GravityDirection.Left || Direction == GravityDirection.Right)
            {
                return;
            }

            if (GravitySwitch == true || isOnGround == false)
            {
                velocity.X = 0f;
                return;
            }

            if (startPoint == Position.X && enemyDirection != EnemyMoveDirection.Follow)
            {
                velocity.X     = 0;
                aggroSwitch    = false;
                enemyDirection = EnemyMoveDirection.Right;
            }
            if (Position.X == endPoint && enemyDirection != EnemyMoveDirection.Follow)
            {
                velocity.X     = 0;
                enemyDirection = EnemyMoveDirection.Left;
            }

            Vector2 playerDistance = level.Player.Position - Position;

            float distance = 0.0f;

            if (aggroSwitch == false)
            {
                distance = playerDistance.Length();
            }
            else
            {
                distance = 2000.0f;
            }

            if (distance < distancetoAggro)
            {
                if (enemyDirection != EnemyMoveDirection.Follow)
                {
                    prevEnemyDirection = enemyDirection;
                }

                enemyDirection = EnemyMoveDirection.Follow;
            }
            else if (distance > distancetoAggro && enemyDirection == EnemyMoveDirection.Follow)
            {
                enemyDirection = prevEnemyDirection;
            }


            if ((isAtEdge == true || hitsObject == true) == true && isOnGround == true &&
                (enemyDirection == EnemyMoveDirection.Right) && counters.Check("switchTimer") == false)
            {
                aggroSwitch = true;

                enemyDirection          = EnemyMoveDirection.Left;
                counters["switchTimer"] = 50.0f;
            }
            else if ((isAtEdge == true || hitsObject == true) && isOnGround == true &&
                     (enemyDirection == EnemyMoveDirection.Left) && counters.Check("switchTimer") == false)
            {
                aggroSwitch = true;

                enemyDirection          = EnemyMoveDirection.Right;
                counters["switchTimer"] = 50.0f;
            }
            else if (enemyDirection != EnemyMoveDirection.Follow)
            {
                if (Position.X > endPoint)
                {
                    enemyDirection = EnemyMoveDirection.Left;
                }
                else if (Position.X < startPoint)
                {
                    enemyDirection = EnemyMoveDirection.Right;
                }
            }


            if (enemyDirection == EnemyMoveDirection.Right)
            {
                velocity.X = travelSpeed;
            }
            if (enemyDirection == EnemyMoveDirection.Left)
            {
                velocity.X = -travelSpeed;
            }

            if (enemyDirection == EnemyMoveDirection.Follow && isAtEdge == true)
            {
                if (velocity.X != 0)
                {
                    previousDirection = Math.Sign(velocity.X);
                    velocity.X        = 0.0f;
                }

                if (Math.Sign(playerDistance.X) != previousDirection)
                {
                    velocity.X = 1.0f * Math.Sign(playerDistance.X);
                }
            }
            if (enemyDirection == EnemyMoveDirection.Follow && isAtEdge == false)
            {
                playerDistance.Normalize();
                velocity.X = (playerDistance.X * travelSpeed);
            }
        }
Esempio n. 4
0
        public void LoadLevel(string levelName)
        {
            LoadContent();

            levelData = Engine.Instance.Content.Load <LevelData>(levelName);
            tile.LoadContent(levelData);

            collisionInfoSolid = LevelTiler.TileConverison(tile.CollisionLayer, 73);
            tilesSolid         = new LevelTilesSolid(collisionInfoSolid);
            this.Add(tilesSolid);

            collisionInfoEmpty = LevelTiler.TileConverison(tile.CollisionLayer, 0);
            tilesEmpty         = new LevelTilesEmpty(collisionInfoEmpty);
            this.Add(tilesEmpty);

            foreach (var entity in tile.Entites)
            {
                if (entity.Type == "GravityBox")
                {
                    GravityBox = new GravityBoxMediumCombo(entity.Position);
                    GravityItemList.Add(GravityBox);
                    this.Add(GravityBox);
                    GravityBox.Added(this);
                }

                if (entity.Type == "GravityBoxLeftRight")
                {
                    GravityBoxLeftRight = new GravityBoxMediumLeftRight(entity.Position);
                    GravityItemList.Add(GravityBoxLeftRight);
                    this.Add(GravityBoxLeftRight);
                    GravityBoxLeftRight.Added(this);
                }

                if (entity.Type == "GravityBoxUpDown")
                {
                    GravityBoxUpDown = new GravityBoxMediumUpDown(entity.Position);
                    GravityItemList.Add(GravityBoxUpDown);
                    this.Add(GravityBoxUpDown);
                    GravityBoxUpDown.Added(this);
                }

                if (entity.Type == "GravityBoxSmall")
                {
                    GravityBoxSmall = new GravityBoxSmallCombo(entity.Position);
                    GravityItemList.Add(GravityBoxSmall);
                    this.Add(GravityBoxSmall);
                    GravityBoxSmall.Added(this);
                }

                if (entity.Type == "GravityBoxSmallLeftRight")
                {
                    GravityBoxSmallLeftRight = new GravityBoxSmallLeftRight(entity.Position);
                    GravityItemList.Add(GravityBoxSmallLeftRight);
                    this.Add(GravityBoxSmallLeftRight);
                    GravityBoxSmallLeftRight.Added(this);
                }

                if (entity.Type == "GravityBoxSmallUpDown")
                {
                    GravityBoxSmallUpDown = new GravityBoxSmallUpDown(entity.Position);
                    GravityItemList.Add(GravityBoxSmallUpDown);
                    this.Add(GravityBoxSmallUpDown);
                    GravityBoxSmallUpDown.Added(this);
                }

                if (entity.Type == "Enemy")
                {
                    if (entity.Properties.Count > 0)
                    {
                        EnemyMoveDirection direction = EnemyMoveDirection.Right;
                        int distance = 100;

                        foreach (var item in entity.Properties)
                        {
                            if (item.Key == "Direction")
                            {
                                if (item.Value == "Right")
                                {
                                    direction = EnemyMoveDirection.Right;
                                }
                                else if (item.Value == "Left")
                                {
                                    direction = EnemyMoveDirection.Left;
                                }
                            }
                            else if (item.Key == "Distance")
                            {
                                distance = int.Parse(item.Value);
                            }
                        }

                        Enemy = new EnemyCombo(entity.Position, distance, direction);
                        GravityItemList.Add(Enemy);
                        this.Add(Enemy);
                        Enemy.Added(this);
                    }
                    else
                    {
                        Enemy = new EnemyCombo(entity.Position);
                        GravityItemList.Add(Enemy);
                        this.Add(Enemy);
                        Enemy.Added(this);
                    }
                }

                if (entity.Type == "EnemyUpDown")
                {
                    if (entity.Properties.Count > 0)
                    {
                        EnemyMoveDirection direction = EnemyMoveDirection.Right;
                        int distance = 100;

                        foreach (var item in entity.Properties)
                        {
                            if (item.Key == "Direction")
                            {
                                if (item.Value == "Right")
                                {
                                    direction = EnemyMoveDirection.Right;
                                }
                                else if (item.Value == "Left")
                                {
                                    direction = EnemyMoveDirection.Left;
                                }
                            }
                            else if (item.Key == "Distance")
                            {
                                distance = int.Parse(item.Value);
                            }
                        }

                        EnemyUpDown = new EnemyUpDown(entity.Position, distance, direction);
                        GravityItemList.Add(EnemyUpDown);
                        this.Add(EnemyUpDown);
                        EnemyUpDown.Added(this);
                    }
                    else
                    {
                        EnemyUpDown = new EnemyUpDown(entity.Position);
                        GravityItemList.Add(EnemyUpDown);
                        this.Add(EnemyUpDown);
                        EnemyUpDown.Added(this);
                    }
                }

                if (entity.Type == "EnemyLeftRight")
                {
                    if (entity.Properties.Count > 0)
                    {
                        EnemyMoveDirection direction = EnemyMoveDirection.Right;
                        int distance = 100;

                        foreach (var item in entity.Properties)
                        {
                            if (item.Key == "Direction")
                            {
                                if (item.Value == "Right")
                                {
                                    direction = EnemyMoveDirection.Right;
                                }
                                else if (item.Value == "Left")
                                {
                                    direction = EnemyMoveDirection.Left;
                                }
                            }
                            else if (item.Key == "Distance")
                            {
                                distance = int.Parse(item.Value);
                            }
                        }

                        EnemyLeftRight = new EnemyLeftRight(entity.Position, distance, direction);
                        GravityItemList.Add(EnemyLeftRight);
                        this.Add(EnemyLeftRight);
                        EnemyLeftRight.Added(this);
                    }
                    else
                    {
                        EnemyLeftRight = new EnemyLeftRight(entity.Position);
                        GravityItemList.Add(EnemyLeftRight);
                        this.Add(EnemyLeftRight);
                        EnemyLeftRight.Added(this);
                    }
                }

                if (entity.Type == "Checkpoint")
                {
                    Checkpoint checkpoint = new Checkpoint(entity.Position);
                    this.Add(checkpoint);
                    checkpoint.Added(this);

                    Checkpoints.Add(checkpoint);
                }

                if (entity.Type == "Exit")
                {
                    Exit = new Exit(entity.Position);
                    this.Add(Exit);
                    Exit.Added(this);
                }

                if (entity.Type == "NextLevel")
                {
                    NextLevel = entity.Name;
                }
            }

            if (CurrentPlayerPosition == Vector2.Zero)
            {
                player = new Player(tile.PlayerPosition[0]);
            }
            else
            {
                player = new Player(CurrentPlayerPosition);
            }

            this.Add(player);
            player.Added(this);
        }
Esempio n. 5
0
        public override void Move(int fieldWidth, int fieldHeight)
        {
            bool isOnTopBorder = (this.Position.Top == PlayField.borderTop + 2);
            bool isOnRightFieldBorder = (this.Position.Left == fieldWidth - 2 - this.Width - PlayField.borderSides);
            bool isOnLeftFieldBorder = (this.Position.Left == PlayField.borderSides + 1);
            bool isOnDownFieldBorder = (this.Position.Top == fieldHeight - 2 - this.Length - PlayField.borderBottom);

            // change the direction if the enemy position is on the field border
            if (this.MoveDirection == EnemyMoveDirection.downRight)
            {
                if (isOnRightFieldBorder)
                {
                    this.MoveDirection = EnemyMoveDirection.downLeft;
                }
                else if (isOnDownFieldBorder)
                {
                    this.MoveDirection = EnemyMoveDirection.upRight;
                }
            }
            else if (this.MoveDirection == EnemyMoveDirection.downLeft)
            {
                if (isOnLeftFieldBorder)
                {
                    this.MoveDirection = EnemyMoveDirection.downRight;
                }
                else if (isOnDownFieldBorder)
                {
                    this.MoveDirection = EnemyMoveDirection.upLeft;
                }
            }
            else if (this.MoveDirection == EnemyMoveDirection.upRight)
            {
                if (isOnRightFieldBorder)
                {
                    this.MoveDirection = EnemyMoveDirection.upLeft;
                }
                else if (isOnTopBorder)
                {
                    this.moveDirection = EnemyMoveDirection.downRight;
                }
            }
            else if (this.MoveDirection == EnemyMoveDirection.upLeft)
            {
                if (isOnLeftFieldBorder)
                {
                    this.MoveDirection = EnemyMoveDirection.upRight;
                }
                else if (isOnTopBorder)
                {
                    this.MoveDirection = EnemyMoveDirection.downLeft;
                }
            }

            // move enemy
            if (this.MoveDirection == EnemyMoveDirection.downRight)
            {
                this.MoveDownRight();
            }
            else if (this.MoveDirection == EnemyMoveDirection.downLeft)
            {
                this.MoveDownLeft();
            }
            else if (this.MoveDirection == EnemyMoveDirection.upRight)
            {
                this.MoveUpRight();
            }
            else if (this.MoveDirection == EnemyMoveDirection.upLeft)
            {
                this.MoveUpLeft();
            }
        }