Exemple #1
0
        override public void update()
        {
            canLoseLeaves += FlxG.elapsed;
            base.update();

            _leaves.update();
        }
        override public void update()
        {
            velocity.Y = tween.Position;

            tween.Update(FlxG.elapsedAsGameTime);

            fanfare.update();
            base.update();
        }
        //This is the main flixel update function or loop function.
        //Most of the enemy's logic or behavior is in this function here.

        public override void update()
        {
            //Then, rotate toward that angle.
            //We could rotate instantly toward the player by simply calling:
            //angle = angleTowardPlayer();
            //However, we want some less predictable, more wobbly behavior.
            float da = angleTowardPlayer();

            if (da < Angle)
            {
                AngularAcceleration = -AngularDrag;
            }
            else if (da > Angle)
            {
                AngularAcceleration = AngularDrag;
            }
            else
            {
                AngularAcceleration = 0;
            }

            //Figure out if we want the jets on or not.
            _timer += FlxG.elapsed;
            if (_timer > 8)
            {
                _timer = 0;
            }
            bool jetsOn = _timer < 6;

            //Set the bot's movement speed and direction
            //based on angle and whether the jets are on.
            _thrust = FlxU.computeVelocity(_thrust, (jetsOn?90:0), Drag.X, 60);
            FlxU.rotatePoint(0, (int)_thrust, 0, 0, Angle, Velocity);

            //Shooting - three shots every few seconds
            if (onScreen())
            {
                bool  shoot = false;
                float os    = _shotClock;
                _shotClock += FlxG.elapsed;
                if ((os < 4.0) && (_shotClock >= 4.0))
                {
                    _shotClock = 0;
                    shoot      = true;
                }
                else if ((os < 3.5) && (_shotClock >= 3.5))
                {
                    shoot = true;
                }
                else if ((os < 3.0) && (_shotClock >= 3.0))
                {
                    shoot = true;
                }

                //If we rolled over one of those time thresholds,
                //shoot a bullet out along the angle we're currently facing.
                if (shoot)
                {
                    //First, recycle a bullet from the bullet pile.
                    //If there are none, recycle will automatically create one for us.
                    EnemyBullet b = (EnemyBullet)_bullets.recycle(typeof(EnemyBullet));
                    //Then, shoot it from our midpoint out along our angle.
                    b.shoot(getMidpoint(_tagPoint), Angle);
                }
            }

            //Then call FlxSprite's update() function, to automate
            // our motion and animation and stuff.
            base.update();

            //Finally, update the jet particles shooting out the back of the ship.
            if (jetsOn)
            {
                if (!_jets.on)
                {
                    //If they're supposed to be on and they're not,
                    //turn em on and play a little sound.
                    _jets.start(false, 0.5f, 0.01f);
                    if (onScreen())
                    {
                        _sfxJet.play(true);
                    }
                }
                //Then, position the jets at the center of the Enemy,
                //and point the jets the opposite way from where we're moving.
                _jets.at(this);
                _jets.setXSpeed(-Velocity.X - 30, -Velocity.X + 30);
                _jets.setYSpeed(-Velocity.Y - 30, -Velocity.Y + 30);
            }
            else                //If jets are supposed to be off, just turn em off.
            {
                _jets.on = false;
            }
            //Finally, update the jet emitter and all its member sprites.
            _jets.update();
        }