Ejemplo n.º 1
0
        public enemygGBL(Vector2 position, int width, int height, Vector2 velocity, float rotation, Vector2 origin, Vector2 scale, Color color, bool islive)
        {
            _texture       = MyContentManager.GetInstance().LoadContent <Texture2D>("enemyGBL");
            _idleAniamtion = new Animation();
            _idleAniamtion.AddFrame(new Rectangle(0, 0, 100, 130), TimeSpan.FromSeconds(.25));
            _idleAniamtion.AddFrame(new Rectangle(100, 0, 100, 130), TimeSpan.FromSeconds(.25));
            _currentAnimation = _idleAniamtion;

            isTurnright  = true;
            _bulletspeed = 10;
            _speed       = 2;
            Health       = 10;
            EnemySprite  = new Sprite(position, width, height, velocity, rotation, origin, scale, color, islive);


            _upray    = new Ray2D(new Vector2(position.X + width / 2, position.Y), new Vector2(0, -0.01f));
            _downray  = new Ray2D(new Vector2(position.X + width / 2, position.Y + height), new Vector2(0, 0.01f));
            _rightray = new Ray2D(new Vector2(position.X + width, position.Y + height / 2), new Vector2(0.01f, 0));
            _leftray  = new Ray2D(new Vector2(position.X, position.Y + height / 2), new Vector2(-0.01f, 0));

            _canUp    = true;
            _canDown  = true;
            _canRight = true;
            _canLeft  = true;

            rnd    = new Random();
            _state = GBLSate.XL;
            rndnum = rnd.Next(0, 4);

            changetime  = 2.0f;
            changetimer = 0.0f;
            stoptime    = 2.0f;
            stoptimer   = 0.0f;
            attacktime  = 2.0f;
            attacktimer = 0.0f;
            firetime    = 0.5f;
            firetimer   = 0.0f;
        }
Ejemplo n.º 2
0
        public override void Update(GameTime gametime)
        {
            CheckCanMove();
            if (_state == GBLSate.XL)
            {
                changetimer += gametime.ElapsedGameTime.TotalSeconds;
                if (changetimer >= changetime)
                {
                    changetimer = 0.0f;
                    if (!_isfindHero)
                    {
                        rndnum = rnd.Next(0, 4);
                    }
                }
                if ((GameManager.GetInstance().Player.Position - EnemySprite.Position).Length() <= 400)
                {
                    _isfindHero = true;
                    _state      = GBLSate.FINDENEMY;
                }
            }
            else
            {
                if (_state == GBLSate.FINDENEMY)
                {
                    stoptimer += gametime.ElapsedGameTime.TotalSeconds;
                    if (stoptimer >= stoptime)
                    {
                        _state = GBLSate.ATTACK;
                    }
                }
                else if (_state == GBLSate.ATTACK)
                {
                    attacktimer += gametime.ElapsedGameTime.TotalSeconds;
                    if (attacktimer >= attacktime)
                    {
                        _state = GBLSate.FINDENEMY;
                    }
                }
            }



            switch (_state)
            {
            case GBLSate.XL:
                MoveXL();
                break;

            case GBLSate.FINDENEMY:
                Move();
                break;

            case GBLSate.ATTACK:
                Attack(gametime);
                break;
            }

            if (Health <= 0)
            {
                EnemySprite.IsLive = false;
            }

            _currentAnimation = _idleAniamtion;
            _currentAnimation.Update(gametime);
            EnemySprite.Update();
        }