Esempio n. 1
0
        //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();
        }
Esempio n. 2
0
        public override void update()
        {
            //game restart timer
            if (!Alive)
            {
                _restart += FlxG.elapsed;
                if (_restart > 2)
                {
                    FlxG.resetState();
                }
                return;
            }

            //make a little noise if you just touched the floor
            if (justTouched(Floor) && (Velocity.Y > 50))
            {
                _sfxLand.play(true);
            }

            //MOVEMENT
            Acceleration.X = 0;
            if (FlxG.keys.pressed(Keys.Left) /*|| _pad.buttonLeft.status == FlxButton.Pressed*/)
            {
                Facing          = Left;
                Acceleration.X -= Drag.X;
            }
            else if (FlxG.keys.pressed(Keys.Right) /*|| _pad.buttonRight.status == FlxButton.Pressed*/)
            {
                Facing          = Right;
                Acceleration.X += Drag.X;
            }
            if (FlxG.keys.justPressed(Keys.X))
            {
                jump();
            }

            //AIMING
            if (FlxG.keys.pressed(Keys.Up) /*|| _pad.buttonUp.status == FlxButton.Pressed*/)
            {
                _aim = Up;
            }
            else if ((FlxG.keys.pressed(Keys.Down) /*|| _pad.buttonDown.status == FlxButton.Pressed*/) && Velocity.Y != 0)
            {
                _aim = Down;
            }
            else
            {
                _aim = Facing;
            }

            //ANIMATION
            if (Velocity.Y != 0)
            {
                if (_aim == Up)
                {
                    play("jump_up");
                }
                else if (_aim == Down)
                {
                    play("jump_down");
                }
                else
                {
                    play("jump");
                }
            }
            else if (Velocity.X == 0)
            {
                if (_aim == Up)
                {
                    play("idle_up");
                }
                else
                {
                    play("idle");
                }
            }
            else
            {
                if (_aim == Up)
                {
                    play("run_up");
                }
                else
                {
                    play("run");
                }
            }

            //SHOOTING
            if (FlxG.keys.pressed(Keys.C) /*|| _pad.buttonB.status == FlxButton.Pressed*/)
            {
                if (!_justShoot)
                {
                    if (flickering)
                    {
                        _sfxJam.play(true);
                    }
                    else
                    {
                        getMidpoint(_tagPoint);
                        ((Bullet)_bullets.recycle(typeof(Bullet))).shoot(_tagPoint, (int)_aim);
                        if (_aim == Down)
                        {
                            Velocity.Y -= 36;
                        }
                    }
                    _justShoot = true;
                }
            }
            else
            {
                _justShoot = false;
            }
        }