Пример #1
0
        public override void Attack(GameTime gameTime, Player player, Bullets bullets, ContentManager Content)
        {
            Timer2 += gameTime.ElapsedGameTime;
            if (IWillShootInTheNearestFuture && Timer2 > DelayToGenerateBulletSinceShootingStarted)
            {
                bullets.bullets.Add(BulletToAdd);
                BulletToAdd = null;
                IWillShootInTheNearestFuture = false;
            }
            float     v = this.BulletVelocity;
            Rectangle EnemyPlusHisRange = new Rectangle((int)(this.position.X) - Range, (int)(this.position.Y) - Range, (int)(this.size.X) + 2 * Range, (int)(this.size.Y) + 2 * Range);

            if (!Rectangle.Intersect(EnemyPlusHisRange, convertToRectangle(player.position, player.size)).IsEmpty)
            {
                if (TimeFromPreviousShot == 0)
                {
                    TimeFromPreviousShot = gameTime.ElapsedGameTime.Seconds;
                }
                System.TimeSpan delay = new TimeSpan(0, 0, Delay);
                if (((int)(gameTime.TotalGameTime.Seconds) - this.TimeFromPreviousShot >= (int)(delay.Seconds)))
                {
                    if (StateOfMoving != FlyingEnemyState.shooting)
                    {
                        this.PreviousStateOfMoving = StateOfMoving;
                    }
                    StateOfMoving = FlyingEnemyState.shooting;
                    Timer2        = new TimeSpan(0);
                    Texture2D texture = Content.Load <Texture2D>("AnimationSprites/FlyingEnemy/flyingenemy_shooting");
                    animatedSprite = new AnimatedSprite(texture, 1, 12);
                    BulletToAdd    = GenerateBullet((int)this.BulletSize.X, (int)this.BulletSize.Y, v, this.BulletDamage, this.GetType(), this.bulletTexture, Content, player);
                    IWillShootInTheNearestFuture = true;
                    TimeFromPreviousShot         = (int)(gameTime.TotalGameTime.Seconds);
                }
            }
        }
Пример #2
0
        public override void Update(GameTime gameTime, GameWindow gameWindow, Platforms platforms, ref int shift, Player Player, ContentManager content)
        {
            UpdateAnimation(gameTime, content);

            this.UpdateTime(gameTime);
            #region poruszanie sie
            if (StateOfMoving == FlyingEnemyState.rising)
            {
                if (this.canMoveLeft(gameWindow, platforms, shift) && Where == WhereIGo.movingLeft)
                {
                    position.X -= (int)(velocity.X);
                }
                if (this.canMoveRight(gameWindow, platforms, shift) && Where == WhereIGo.movingRight)
                {
                    position.X += (int)(velocity.X);
                }
                if (this.canMoveUp(gameWindow, platforms, shift))
                {
                    position.Y -= (int)(velocity.Y);
                }
                HowHighFromStartLevel += (int)(velocity.Y);
                if (HowHighFromStartLevel >= MaxHeight)
                {
                    StateOfMoving = FlyingEnemyState.falling;
                }
            }
            if (StateOfMoving == FlyingEnemyState.falling)
            {
                if (this.canMoveLeft(gameWindow, platforms, shift) && Where == WhereIGo.movingLeft)
                {
                    position.X -= (int)(velocity.X);
                }
                if (this.canMoveRight(gameWindow, platforms, shift) && Where == WhereIGo.movingRight)
                {
                    position.X += (int)(velocity.X);
                }
                if (this.canMoveDown(gameWindow, platforms, shift))
                {
                    position.Y += (int)(velocity.Y);
                }
                HowHighFromStartLevel -= (int)(velocity.Y);
                if (HowHighFromStartLevel <= 0)
                {
                    StateOfMoving = FlyingEnemyState.rising;
                }
            }
            #endregion
        }
Пример #3
0
 void ChangeFlyingEnemyState(FlyingEnemyState nextState)
 {
     if (!_transitionBlocked)
     {
         if (_curState != nextState)
         {
             FlyingEnemyStateEvent flyingEnemyStateEvent;
             flyingEnemyStateEvent.prevState = _curState;
             flyingEnemyStateEvent.nextState = nextState;
             if (FlyingEnemyStateInitialize(flyingEnemyStateEvent))
             {
                 _curState = nextState;
             }
         }
     }
 }
Пример #4
0
        public void UpdateAnimation(GameTime gameTime, ContentManager content)
        {
            switch (StateOfMoving)
            {
            case FlyingEnemyState.rising:
                Timer1 += gameTime.ElapsedGameTime;
                if (Timer1 > DelayForRisingAndFalling)
                {
                    Timer1 -= DelayForRisingAndFalling;
                    animatedSprite.Update();
                }
                break;

            case FlyingEnemyState.falling:
                Timer1 += gameTime.ElapsedGameTime;
                if (Timer1 > DelayForRisingAndFalling)
                {
                    Timer1 -= DelayForRisingAndFalling;
                    animatedSprite.Update();
                }
                break;

            case FlyingEnemyState.shooting:
                Timer1 += gameTime.ElapsedGameTime;
                if (Timer1 > DelayForShooting)
                {
                    Timer1 -= DelayForShooting;
                    int pomocnicze_klatki = animatedSprite.currentFrame;
                    animatedSprite.Update();
                    if (pomocnicze_klatki + 1 >= animatedSprite.totalFrames)
                    {
                        this.StateOfMoving = this.PreviousStateOfMoving;
                        this.LoadContent(content);
                    }
                }
                break;
            }
        }