Exemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            //base.Update(gameTime);

            this.oldMouseState = this.newMouseState;
            this.newMouseState = Mouse.GetState();
            this.mouse         = Mouse.GetState();

            if (!isInCastle && !isInBattle)
            {
                this.lastAbstractCoord = this.abstractPlayerPositon;

                // take position where need to go
                //this.mouse.LeftButton == ButtonState.Pressed - for single click movement
                if (MouseExtended.Current.WasDoubleClick(MouseButton.Left))
                {
                    this.lastMouseClickPosition.X = this.mouse.X;
                    this.lastMouseClickPosition.Y = this.mouse.Y;
                }

                //MovingWithMouse();

                if (this.availableMove > 0)
                {
                    this.CharacterMoving();

                    // re-calculate player available move
                    this.availableMove -= CollisionDetection.CalculateDistanceTravelled(this.lastAbstractCoord,
                                                                                        this.abstractPlayerPositon);
                }

                this.MakeCurrentAnimationFrame(gameTime);
                this.SendSoundQuery(gameTime, this.lastAbstractCoord, this.abstractPlayerPositon);
            }
        }
        public WarUnit TryTakeNearestEnemyUnit(WarUnit enemyUnit, int radius)
        {
            this.supportUnit = null;

            double minDistance = double.MaxValue;

            foreach (var unit in this.enemyUnits)
            {
                double currentDistance = CollisionDetection.CalculateDistanceTravelled(unit.Key.DrawCoord,
                                                                                       enemyUnit.DrawCoord);

                if ((currentDistance < minDistance) && ((int)currentDistance < radius))
                {
                    this.supportUnit = unit.Key;

                    minDistance = currentDistance;
                }
            }

            return(this.supportUnit);
        }
Exemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            //base.Update(gameTime);

            if (!Character.GetIsInBattle && !Character.GetIsInCastle)
            {
                this.iSeePlayer = false;

                this.lastAbstractCoord = this.coordGargamel;

                float plTopSide    = Character.DrawCoordPlayer.Y;
                float plBottomSide = Character.DrawCoordPlayer.Y + Character.PlayerCropHeight;
                float plLeftSide   = Character.DrawCoordPlayer.X;
                float plRightSide  = Character.DrawCoordPlayer.X + Character.PlayerCropWidth;

                float enemyTop    = this.drawCoordEnemy.Y;
                float enemyBottom = this.drawCoordEnemy.Y + cropHeight;
                float enemyLeft   = this.drawCoordEnemy.X;
                float enemyRight  = this.drawCoordEnemy.X + cropWidth;

                bool isPlayerUp    = CollisionDetection.IsNear(plBottomSide, this.drawCoordEnemy.Y, this.enemySearchRadius);
                bool isPlayerDown  = CollisionDetection.IsNear(plTopSide, this.drawCoordEnemy.Y + cropHeight, this.enemySearchRadius);
                bool isPlayerLeft  = CollisionDetection.IsNear(plRightSide, this.drawCoordEnemy.X, this.enemySearchRadius);
                bool isPlayerRight = CollisionDetection.IsNear(plLeftSide, this.drawCoordEnemy.X + cropWidth, this.enemySearchRadius);

                if (!CharacterManager.itIsPlayerTurn && this.availableMove > 0)
                {
                    EnemyMoving(isPlayerUp, isPlayerRight, isPlayerLeft, isPlayerDown);

                    this.availableMove -= CollisionDetection.CalculateDistanceTravelled(this.lastAbstractCoord,
                                                                                        this.coordGargamel);
                }


                this.drawCoordEnemy.X = this.coordGargamel.X + CharacterManager.barbarian.CoordP().X;
                this.drawCoordEnemy.Y = this.coordGargamel.Y + CharacterManager.barbarian.CoordP().Y;


                CheckForBattle(plTopSide, enemyBottom, plLeftSide, enemyRight, plRightSide, enemyLeft, plBottomSide, enemyTop, gameTime);


                // Re-Write new position of enemy on the screen
                CharacterManager.EnemiesPositionList[ID] = this.drawCoordEnemy;

                MakeCurrentAnimationFrame(gameTime);

                ShowEnemyArmy(plTopSide, plBottomSide, plLeftSide, plRightSide, gameTime);

                if (this.lastAbstractCoord != this.coordGargamel)
                {
                    this.iSeePlayer = true;
                }

                this.SendSoundQuery(gameTime, this.lastAbstractCoord, this.coordGargamel);
            }

            // Check if the mouse position is inside the rectangle
            // fix it !

            //var mouseState = Mouse.GetState();
            //var mousePosition = coordGargamel;
            //Rectangle area = new Rectangle(new Point((int)coordGargamel.X, (int)drawCoordEnemy.X), new Point((int)coordGargamel.Y, (int)drawCoordEnemy.Y));

            /// fix the problem !!!


            //if (area.Contains(mousePosition))
            //{
            //    if (mouseState.LeftButton == ButtonState.Pressed)
            //    {
            //        moveSpeedEnemy = 0f;
            //        //isAlive = false;

            //    }
            //}
        }