예제 #1
0
        public void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            lastFire += gameTime.ElapsedGameTime.TotalMilliseconds;

            if (state == RobotState.AGGRESIVE)
            {
                timeCounter += gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
                if (timeCounter > 0.5f)
                {
                    state       = RobotState.IDLE;
                    timeCounter = 0.0f;
                }
            }

            if (this.Position.X >= parent.GetPlayerLocation().X)
            {
                direction = PlayerDirection.RIGHT;
            }
            else
            {
                direction = PlayerDirection.LEFT;
            }

            if ((ConvertUnits.ToDisplayUnits(Position.Y) + parent.CameraOffset.Y) < MainGame.ScreenHeight && (ConvertUnits.ToDisplayUnits(Position.Y) + parent.CameraOffset.Y) > 0 &&
                (ConvertUnits.ToDisplayUnits(Position.X) + parent.CameraOffset.X) < MainGame.ScreenWidth && (ConvertUnits.ToDisplayUnits(Position.X) + parent.CameraOffset.X) > 0 &&
                (lastFire == -1.0f || lastFire > fireRate))
            {
                lastFire = gameTime.ElapsedGameTime.TotalMilliseconds;
                ShootPlayer();
                state = RobotState.AGGRESIVE;
            }
        }
예제 #2
0
        private void RunAtPlayerPlayer()
        {
            float  x     = (Position.X - parent.GetPlayerLocation().X);
            float  y     = (Position.Y - parent.GetPlayerLocation().Y);
            double angle = Math.Atan2(y, x);

            LinearVelocity = new Vector2((float)(-5 * Math.Cos(angle)), (float)(-5 * Math.Sin(angle)));
        }