예제 #1
0
    private void HandleMovement()
    {
        this.manager.EnsureUpdated();
        Vector3 steerPos = manager.GetAgentPosition(this.id);

        steerPos.y        -= this.YOffset;
        transform.position = steerPos;

        float dist = (steerPos - this.Target).magnitude;

        if ((this.State != SteeringState.Stopped) &&
            (dist < this.stoppingRadius))
        {
            this.Stop(this.StickyStopping);
        }
        else if ((this.State == SteeringState.Navigating) &&
                 (dist < this.arrivingRadius))
        {
            this.State = SteeringState.Arriving;
        }

        if ((this.StickyStopping == true) &&
            ((transform.position - this.lastPosition).sqrMagnitude > 0.0001f) &&
            (this.State == SteeringState.Stopped))
        {
            this.Stop(true);
        }
    }
예제 #2
0
 void Awake()
 {
     this.State   = SteeringState.Stopped;
     this.manager = RecastSteeringManager.Instance;
     if (this.manager == null)
     {
         Debug.LogError("Null SteeringManager");
     }
 }
예제 #3
0
 public override void Stop()
 {
     if (this.manager != null)
     {
         // TODO: This sometimes fails. Figure out why. - AS
         this.manager.UpdateAgentMaxSpeed(this.id, 0.0f);
         this.manager.UpdateAgentMaxAcceleration(this.id, 10000.0f);
         this.State = SteeringState.Stopped;
     }
 }
예제 #4
0
        public void SetBehaviorSteer()
        {
            this.behaviorPattern = GameParameters.AlienBehaviorPattern.Steer;

            this.steeringState = AlienInvader.SteeringState.Moving;
            this.movingTimeInChosenDirectionInFrames = 0;
            this.steerToAngle = 225f;

            SetVelocityAndRotationByAngle(270f, GameParameters.ALIEN_INVADER_VELOCITY_VAL);
        }
예제 #5
0
    // Called at the end of the program initialization
    void Start()
    {
        // Set initial steering state to not steering
        state        = SteeringState.NotSteering;
        hopFlag      = true;
        teleportFlag = true;

        office    = new Vector3(0, 0, 0);
        breakroom = new Vector3(0, 0, 5);
        bathroom  = new Vector3(-5, 0, 5);
    }
예제 #6
0
    // Called at the end of the program initialization
    void Start()
    {
        // Set initial steering state to not steering
        state = SteeringState.NotSteering;

        car = GameObject.Find("Classic_car_1955_style1");

        GameObject steeringWheel = GameObject.Find("steeringpivot");

        updateOriginalTransforms();
    }
예제 #7
0
 public override void Stop(bool sticky = true)
 {
     if (this.manager != null)
     {
         // "Sticky" means that we move the target to the agent's current
         // position, so that they don't backtrack and try to find the
         // exact target
         if (sticky == true)
         {
             this.manager.SetAgentTarget(this.id, transform.position);
             this.Target = transform.position;
         }
         this.State = SteeringState.Stopped;
     }
 }
예제 #8
0
        public AlienInvader()
        {
            this.scaleFactor = GameParameters.ALIEN_INVADER_PIC_SCALE_FACTOR;
            this.Velocity    = GameParameters.ZERO_VELOCITY;
            this.IsAttacking = false;

            affineTransform.Rotation           = 0;
            this.IntervalBetweenRocketLaunches = GameParameters.INTERVAL_BETWEEN_ALIEN_INVADER_ROCKET_LAUNCHES;

            this.behaviorPattern = GameParameters.AlienBehaviorPattern.Steer;

            this.steeringState = AlienInvader.SteeringState.Stopped;
            movingTimeInChosenDirectionInFrames = 0;
            steeringCounterlockwise             = true; // steering angle increases

            base.DrawSprite("alienSpaceship");
        }
예제 #9
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        if (joystick.GetAxis().x > 0.0f)
        {
            Invoke("Activate", 2.0f);
            Invoke("FreeMode", 36.0f);
        }
        else if (joystick.GetAxis().x < 0.0f)
        {
            GameObject.FindWithTag("left").GetComponent <Valve.VR.InteractionSystem.Tutorial> ().enabled  = false;
            GameObject.FindWithTag("right").GetComponent <Valve.VR.InteractionSystem.Tutorial> ().enabled = false;
        }

        if (state == SteeringState.Standing)
        {
            if (Triggerbutton.GetPressDown())
            {
                Vector3 temp = space.transform.position;
                temp.y -= 0.15f;
                space.transform.position = temp;
                state = SteeringState.Sitting;
            }
            else
            {
            }
        }

        if (state == SteeringState.Sitting)
        {
            if (sidebutton.GetPressDown())
            {
                Vector3 temp1 = space.transform.position;
                temp1.y += 0.15f;
                space.transform.position = temp1;
                state = SteeringState.Standing;
            }
            else
            {
            }
        }
    }
예제 #10
0
    // ------------------------------------------------------------------ 
    // Desc: 
    // ------------------------------------------------------------------ 

    public void Seek ( Vector3 _pos ) {
        this.targetPos = _pos;
        this.steeringState = SteeringState.seeking;
    }
예제 #11
0
    // ------------------------------------------------------------------ 
    // Desc: 
    // ------------------------------------------------------------------ 

    public void Move ( Vector3 _dir ) {
        this.moveDir = _dir;
        this.steeringState = SteeringState.moving;
    }
예제 #12
0
        /// <summary>
        /// Updates the ship
        /// </summary>
        /// <param name="elapsedTime"></param>
        public override void Update(float elapsedTime)
        {
            KeyboardState currentKeyboardState = Keyboard.GetState();

            // Update timers
            defaultGunTimer += elapsedTime;

            // Steer the ship up or down according to user input
            if (currentKeyboardState.IsKeyDown(Keys.Up))
            {
                position.Y -= elapsedTime * velocity.Y;
            }
            else if (currentKeyboardState.IsKeyDown(Keys.Down))
            {
                position.Y += elapsedTime * velocity.Y;
            }

            // Steer the ship left or right according to user input
            steeringState = SteeringState.Straight;

            if (currentKeyboardState.IsKeyDown(Keys.Left))
            {
                if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                    currentKeyboardState.IsKeyDown(Keys.RightShift))
                {
                    steeringState = SteeringState.HardLeft;
                    position.X -= elapsedTime * 2 * velocity.X;

                }
                else
                {
                    steeringState = SteeringState.Left;
                    position.X -= elapsedTime * velocity.X;
                }
            }
            else if (currentKeyboardState.IsKeyDown(Keys.Right))
            {
                if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                    currentKeyboardState.IsKeyDown(Keys.RightShift))
                {
                    position.X += elapsedTime * 2 * velocity.X;
                    steeringState = SteeringState.HardRight;
                }
                else
                {
                    position.X += elapsedTime * velocity.X;
                    steeringState = SteeringState.Right;
                }
            }

            // Fire weapons
            if (currentKeyboardState.IsKeyDown(Keys.Space))
            {
                uint[] ids = ScrollingShooterGame.GameObjectManager.QueryRegion(new Rectangle(0, 0, 100, 100));
                string label = "";
                foreach (uint id in ids)
                    label += id + "-";
                label = "";
                //ScrollingShooterGame.Game.Window.Title = label;
                // Streaming weapons

                // Default gun
                if (defaultGunTimer > 0.25f)
                {
                    ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.Bullet, position);
                    defaultGunTimer = 0f;
                }

                // Fire-once weapons
                if (oldKeyboardState.IsKeyUp(Keys.Space))
                {

                    if ((PowerupType & PowerupType.Fireball) > 0)
                        TriggerFireball();
                }
            }

            // store the current keyboard state for next frame
            oldKeyboardState = currentKeyboardState;
        }
예제 #13
0
        /// <summary>
        /// Updates the ship
        /// </summary>
        /// <param name="elapsedTime"></param>
        public override void Update(float elapsedTime)
        {
            if (this.Dead)
            {
                DeathTimer -= elapsedTime;

                if (DeathTimer <= 0)
                {
                    //Respawn
                    if (this.Lives <= 0)
                    {
                        //Perma Death
                        ScrollingShooterGame.Game.PlayerDeath();
                    }
                    else
                    {
                        this.Health = this.MaxHealth;
                        this.Lives--;
                        this.Dead = false;

                        this.InvincibleTimer = 2;

                        //Respawn or whatever
                    }

                }
                return;
            }

            if (InvincibleTimer > 0)
            {
                InvincibleTimer -= elapsedTime;

                InvincibleFrame -= elapsedTime;
                if (InvincibleFrame < -.1)
                    InvincibleFrame += 0.3f;
            }

            if (!ScrollingShooterGame.LevelManager.Ending)
            {
                KeyboardState currentKeyboardState = Keyboard.GetState();

                // Update timers
                defaultGunTimer += elapsedTime;
                bladesPowerupTimer += elapsedTime;
                energyBlastTimer -= elapsedTime;
                bombTimer += elapsedTime;
                railgunTimer += elapsedTime;
                homingMissileTimer -= elapsedTime;
                shotgunTimer += elapsedTime;
                bubbleTimer += elapsedTime;
                fireballTimer += elapsedTime;
                freezeTimer += elapsedTime;

                if (!drunk)
                {
                    // Steer the ship up or down according to user input
                    if (currentKeyboardState.IsKeyDown(Keys.Up))
                    {
                        position.Y -= elapsedTime * velocity.Y;
                    }
                    else if (currentKeyboardState.IsKeyDown(Keys.Down))
                    {
                        position.Y += elapsedTime * velocity.Y;
                    }

                    // Steer the ship left or right according to user input
                    steeringState = SteeringState.Straight;

                    if (currentKeyboardState.IsKeyDown(Keys.Left))
                    {
                        if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                            currentKeyboardState.IsKeyDown(Keys.RightShift))
                        {
                            steeringState = SteeringState.HardLeft;
                            position.X -= elapsedTime * 2 * velocity.X;

                        }
                        else
                        {
                            steeringState = SteeringState.Left;
                            position.X -= elapsedTime * velocity.X;
                        }
                    }
                    else if (currentKeyboardState.IsKeyDown(Keys.Right))
                    {
                        if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                            currentKeyboardState.IsKeyDown(Keys.RightShift))
                        {
                            position.X += elapsedTime * 2 * velocity.X;
                            steeringState = SteeringState.HardRight;
                        }
                        else
                        {
                            position.X += elapsedTime * velocity.X;
                            steeringState = SteeringState.Right;
                        }
                    }
                }

                //Player is drunk and movements are reversed.
                else
                {
                    //Decrease drunkCounter and make the player sober if their drunk time is up.
                    drunkCounter--;
                    if (drunkCounter == 0)
                    {
                        SoberUp();
                    }
                    // Steer the ship up or down according to user input
                    if (currentKeyboardState.IsKeyDown(Keys.Up))
                    {
                        position.Y += elapsedTime * velocity.Y;
                    }

                    else if (currentKeyboardState.IsKeyDown(Keys.Down))
                    {
                        position.Y -= elapsedTime * velocity.Y;
                    }

                    // Steer the ship left or right according to user input
                    steeringState = SteeringState.Straight;

                    if (currentKeyboardState.IsKeyDown(Keys.Left))
                    {
                        if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                            currentKeyboardState.IsKeyDown(Keys.RightShift))
                        {
                            steeringState = SteeringState.HardLeft;
                            position.X += elapsedTime * 2 * velocity.X;

                        }
                        else
                        {
                            steeringState = SteeringState.Left;
                            position.X += elapsedTime * velocity.X;
                        }
                    }
                    else if (currentKeyboardState.IsKeyDown(Keys.Right))
                    {
                        if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                            currentKeyboardState.IsKeyDown(Keys.RightShift))
                        {
                            position.X -= elapsedTime * 2 * velocity.X;
                            steeringState = SteeringState.HardRight;
                        }
                        else
                        {
                            position.X -= elapsedTime * velocity.X;
                            steeringState = SteeringState.Right;
                        }
                    }
                }
                // Do player clamping
                // Note: 384 = worldView width / 2 and 360 = worldView height / 2
                // I assumed it would be faster to compare hardcoded numbers than to reference the variable directly
                if ((position.X - Bounds.Width / 2) < 0) position.X = Bounds.Width / 2;
                else if ((position.X + Bounds.Width / 2) > 384) position.X = 384 - Bounds.Width / 2;
                if (position.Y < ((ScrollingShooterGame.LevelManager.scrollDistance * -0.5f) + Bounds.Height / 2))
                    position.Y = (ScrollingShooterGame.LevelManager.scrollDistance * -0.5f) + Bounds.Height / 2;
                else if (position.Y > ((ScrollingShooterGame.LevelManager.scrollDistance * -0.5f) + 360 - Bounds.Height / 2))
                    position.Y = (ScrollingShooterGame.LevelManager.scrollDistance * -0.5f) + 360 - Bounds.Height / 2;

                // Fire bomb
                if (currentKeyboardState.IsKeyDown(Keys.B))
                {
                    //checks if player has the bomb power up
                    if ((PowerupType & PowerupType.Bomb) > 0)
                    {
                        if (bombTimer > 1.5f)
                        {
                            ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.Bomb, position);
                            bombTimer = 0f;
                        }
                    }
                }
                if (bladesPowerupTimer > 10.0f && (PowerupType & PowerupType.Blades) > 0)
                {
                    unApplyBlades();
                }

                // Used to test the energy blast powerup levels
                //if (currentKeyboardState.IsKeyDown(Keys.F) && oldKeyboardState.IsKeyUp(Keys.F))
                // energyBlastLevel++;
                if ((PowerupType & PowerupType.Blades) == 0)
                {
                    // Fire weapons
                    if (currentKeyboardState.IsKeyDown(Keys.Space))
                    {
                        if ((PowerupType & PowerupType.Freezewave) > 0)
                        {
                            if (freezeTimer > .5f)
                            {
                                ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.FreezewaveProjectile, position);
                                freezeTimer = 0;
                            }
                        }
                        // Streaming weapons
                        if ((PowerupType & PowerupType.BubbleBeam) > 0)
                        {
                            if (bubbleTimer > .1f)
                            {
                                ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.BubbleBullet, position);
                                bubbleTimer = 0f;
                            }
                        }

                        // Fires a shotgun shot if the shotgun powerup is active and half a second has passed since the last shot
                        if ((PowerupType & PowerupType.ShotgunPowerup) > 0 && shotgunTimer > 0.5f)
                        {
                            TriggerShotgun();
                            shotgunFired.Play();
                            shotgunTimer = 0;
                        }

                        // Default gun
                        if (defaultGunTimer > 0.25f & (PowerupType & PowerupType.Default) > 0)
                        {
                            ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.Bullet, position);
                            bulletFired.Play();
                            defaultGunTimer = 0f;
                        }
                        else if (fireballTimer > 0.4f & (PowerupType & PowerupType.Fireball) > 0)
                        {
                            TriggerFireball();
                            bulletFired.Play();
                            fireballTimer = 0f;
                        }

                        if ((PowerupType & PowerupType.HomingMissiles) > 0)
                        {
                            if (homingMissileTimer <= 0)
                            {
                                homingMissileTimer = homingMissileFireRate;
                                TriggerHomingMissile();
                                rocketFired.Play();
                            }
                        }

                        //Conditionals to fire railgun.
                        if ((PowerupType & PowerupType.Railgun) > 0)
                        {
                            if (railgunTimer > 3.0f)
                            {
                                TriggerRailgun();
                                railgunTimer = 0f;
                            }
                        }

                        // Energy Blast Gun
                        if (((PowerupType & PowerupType.EnergyBlast) > 0) && energyBlastTimer < 0)
                        {
                            TriggerEnergyBlast();
                            laserFired.Play();
                        }

                        // Fire-once weapons
                        if (oldKeyboardState.IsKeyUp(Keys.Space))
                        {

                            if ((PowerupType & PowerupType.DroneWave) > 0)
                            {
                                TriggerDroneWave();
                            }
                        }

                        if ((PowerupType & PowerupType.Frostball) > 0)
                            TriggerFrostball();

                        if ((PowerupType & PowerupType.Birdcrap) > 0)
                        {
                            TriggerBirdcrap();
                        }

                        if ((PowerupType & PowerupType.Bomb) > 0)
                            TriggerBomb();
                    }
                }

                // store the current keyboard state for next frame
                oldKeyboardState = currentKeyboardState;
            }
        }
예제 #14
0
 // Called at the end of the program initialization
 void Start()
 {
     // Set initial steering state to not steering
     state = SteeringState.NotSteering;
 }
예제 #15
0
    // ------------------------------------------------------------------ 
    // Desc: 
    // ------------------------------------------------------------------ 

    public void DisableSteering () {
        this.steeringState = SteeringState.disable;
    }
예제 #16
0
    // ------------------------------------------------------------------ 
    // Desc: 
    // ------------------------------------------------------------------ 

    public void Stop () {
        this.steeringState = SteeringState.braking;
    }
예제 #17
0
        /**
         *  Steers to one angle for a while (inputs: new angle, angular speed), then stops steering and just moves (input: moving time), then steers to another angle etc.
         */
        public void SteeringBehavior()
        {
            if (this.movingTimeInChosenDirectionInFrames > 0)
            {
                // continue in the same direction
                this.movingTimeInChosenDirectionInFrames -= 1;
            }
            else
            {
                // use steeringCounterclockwise and steerToAngle instead of left-right
                // use steeringSpeedCoefficient, steeringTime, make them randomly selected from interval

                // finished moving
                if (this.steeringState == AlienInvader.SteeringState.Moving)
                {
                    this.steeringState = AlienInvader.SteeringState.Steering;

                    this.steeringCounterlockwise = !this.steeringCounterlockwise;  // changing steering direction

                    randInt = randomGenerator.Next(0, 100);

                    if (randInt < 70)
                    {
                        deepSteering      = false;
                        this.steerToAngle = this.steeringCounterlockwise ? 315f : 225f;
                    }
                    else
                    {
                        deepSteering      = true;
                        this.steerToAngle = this.steeringCounterlockwise ? 335f : 205f;
                    }
                }
                // finished steering step, can do more steering or start moving
                if (this.steeringState == AlienInvader.SteeringState.Steering)
                {
                    if (this.steeringCounterlockwise)
                    { // steering counterlockwise
                        // steering continues
                        if (this.velocityDirectionAngle + GameParameters.ALIEN_INVADER_STEERING_ANGULAR_INCREMENT < this.steerToAngle)
                        {
                            this.movingTimeInChosenDirectionInFrames = GameParameters.ALIEN_INVADER_TIME_INTERVAL_FOR_ONE_STEERING_STEP_IN_NUM_FRAMES;
                            SetVelocityAndRotationByAngle(this.velocityDirectionAngle + GameParameters.ALIEN_INVADER_STEERING_ANGULAR_INCREMENT, GameParameters.ALIEN_INVADER_VELOCITY_VAL);
                        }
                        // steering done
                        else
                        {
                            this.steeringState = AlienInvader.SteeringState.Moving;
                            this.movingTimeInChosenDirectionInFrames = deepSteering ? GameParameters.ALIEN_INVADER_MAX_TIME_INTERVAL_FOR_MOVING_STAGE_IN_NUM_FRAMES : randomGenerator.Next(0, GameParameters.ALIEN_INVADER_MAX_TIME_INTERVAL_FOR_MOVING_STAGE_IN_NUM_FRAMES);
                            SetVelocityAndRotationByAngle(this.steerToAngle, GameParameters.ALIEN_INVADER_VELOCITY_VAL);
                        }
                    }
                    else     // steering clockwise
                    // steering continues
                    {
                        if (this.velocityDirectionAngle - GameParameters.ALIEN_INVADER_STEERING_ANGULAR_INCREMENT > this.steerToAngle)
                        {
                            this.movingTimeInChosenDirectionInFrames = GameParameters.ALIEN_INVADER_TIME_INTERVAL_FOR_ONE_STEERING_STEP_IN_NUM_FRAMES;
                            SetVelocityAndRotationByAngle(this.velocityDirectionAngle - GameParameters.ALIEN_INVADER_STEERING_ANGULAR_INCREMENT, GameParameters.ALIEN_INVADER_VELOCITY_VAL);
                        }
                        // steering done
                        else
                        {
                            this.steeringState = AlienInvader.SteeringState.Moving;
                            this.movingTimeInChosenDirectionInFrames = deepSteering ? GameParameters.ALIEN_INVADER_MAX_TIME_INTERVAL_FOR_MOVING_STAGE_IN_NUM_FRAMES : randomGenerator.Next(0, GameParameters.ALIEN_INVADER_MAX_TIME_INTERVAL_FOR_MOVING_STAGE_IN_NUM_FRAMES);
                            SetVelocityAndRotationByAngle(velocityDirectionAngle, GameParameters.ALIEN_INVADER_VELOCITY_VAL);
                        }
                    }
                }
            }
        }
예제 #18
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            // If the joystick is pressed forward and the button is pressed
            if (joystick.GetAxis().y > 0.0f && joystick.GetAxis().y < 0.5f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.WalkingForward;
            }

            else if (joystick.GetAxis().y >= 0.5f && button.GetPress())
            {
                //changing the state to Running Forward
                state = SteeringState.RunningForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && joystick.GetAxis().y > -0.5f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.WalkingBackward;
            }
            else if (joystick.GetAxis().y <= -0.5f && button.GetPress())
            {
                //changing the state to Running Backward
                state = SteeringState.RunningBackward;
            }


            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.WalkingForward)
        {
            //if speen is increased, The user will go into running state from walking state.
            if (joystick.GetAxis().y >= 0.5f && button.GetPress())
            {
                //changing the state to Running Forward
                state = SteeringState.RunningForward;
            }

            // If the button is not pressed
            else if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && joystick.GetAxis().y > -0.5f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.WalkingBackward;
            }

            else if (joystick.GetAxis().y <= -0.5f && button.GetPress())
            {
                //changing the state to Running Forward
                state = SteeringState.RunningBackward;
            }


            // Process current steering forward state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.WalkingBackward)
        {
            if (joystick.GetAxis().y <= -0.5f && button.GetPress())
            {
                //changing the state to Running backward
                state = SteeringState.RunningBackward;
            }

            // If the button is not pressed
            else if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && joystick.GetAxis().y < 0.5f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.WalkingForward;
            }

            else if (joystick.GetAxis().y >= 0.5f && button.GetPress())
            {
                //changing the state to Running Forward
                state = SteeringState.RunningForward;
            }

            // Process current steering backward state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }
        else if (state == SteeringState.RunningForward)
        {
            if (joystick.GetAxis().y > 0.0f && joystick.GetAxis().y < 0.5f && button.GetPress())
            {
                state = SteeringState.WalkingForward;
            }
            else if (joystick.GetAxis().y < 0.0f && joystick.GetAxis().y > -0.5f && button.GetPress())
            {
                state = SteeringState.WalkingBackward;
            }
            else if (joystick.GetAxis().y <= -0.5f && button.GetPress())
            {
                state = SteeringState.RunningBackward;
            }
            else if (!button.GetPress())
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }
        else if (state == SteeringState.RunningBackward)
        {
            if (joystick.GetAxis().y > 0.0f && joystick.GetAxis().y < 0.5f && button.GetPress())
            {
                state = SteeringState.WalkingForward;
            }
            else if (joystick.GetAxis().y < 0.0f && joystick.GetAxis().y > -0.5f && button.GetPress())
            {
                state = SteeringState.WalkingBackward;
            }
            else if (joystick.GetAxis().y >= 0.5f && button.GetPress())
            {
                state = SteeringState.RunningForward;
            }
            else if (!button.GetPress())
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }
    }
예제 #19
0
    // ------------------------------------------------------------------ 
    // Desc: 
    // ------------------------------------------------------------------ 

    public void Avoid () {
        this.steeringState = SteeringState.avoiding;
    }
예제 #20
0
        /// <summary>
        /// Updates the ship
        /// </summary>
        /// <param name="elapsedTime"></param>
        public override void Update(float elapsedTime)
        {
            KeyboardState currentKeyboardState = Keyboard.GetState();

            // Update timers
            defaultGunTimer    += elapsedTime;
            bladesPowerupTimer += elapsedTime;
            energyBlastTimer   -= elapsedTime;
            bombTimer          += elapsedTime;
            railgunTimer       += elapsedTime;

            if (!drunk)
            {
                // Steer the ship up or down according to user input
                if (currentKeyboardState.IsKeyDown(Keys.Up))
                {
                    position.Y -= elapsedTime * velocity.Y;
                }
                else if (currentKeyboardState.IsKeyDown(Keys.Down))
                {
                    position.Y += elapsedTime * velocity.Y;
                }

                // Steer the ship left or right according to user input
                steeringState = SteeringState.Straight;

                if (currentKeyboardState.IsKeyDown(Keys.Left))
                {
                    if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                        currentKeyboardState.IsKeyDown(Keys.RightShift))
                    {
                        steeringState = SteeringState.HardLeft;
                        position.X   -= elapsedTime * 2 * velocity.X;
                    }
                    else
                    {
                        steeringState = SteeringState.Left;
                        position.X   -= elapsedTime * velocity.X;
                    }
                }
                else if (currentKeyboardState.IsKeyDown(Keys.Right))
                {
                    if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                        currentKeyboardState.IsKeyDown(Keys.RightShift))
                    {
                        position.X   += elapsedTime * 2 * velocity.X;
                        steeringState = SteeringState.HardRight;
                    }
                    else
                    {
                        position.X   += elapsedTime * velocity.X;
                        steeringState = SteeringState.Right;
                    }
                }
            }

            //Player is drunk and movements are reversed.
            else
            {
                //Decrease drunkCounter and make the Player sober if their drunk time is up.
                drunkCounter--;
                if (drunkCounter == 0)
                {
                    SoberUp();
                }
                // Steer the ship up or down according to user input
                if (currentKeyboardState.IsKeyDown(Keys.Up))
                {
                    position.Y += elapsedTime * velocity.Y;
                }

                else if (currentKeyboardState.IsKeyDown(Keys.Down))
                {
                    position.Y -= elapsedTime * velocity.Y;
                }

                // Steer the ship left or right according to user input
                steeringState = SteeringState.Straight;

                if (currentKeyboardState.IsKeyDown(Keys.Left))
                {
                    if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                        currentKeyboardState.IsKeyDown(Keys.RightShift))
                    {
                        steeringState = SteeringState.HardLeft;
                        position.X   += elapsedTime * 2 * velocity.X;
                    }
                    else
                    {
                        steeringState = SteeringState.Left;
                        position.X   += elapsedTime * velocity.X;
                    }
                }
                else if (currentKeyboardState.IsKeyDown(Keys.Right))
                {
                    if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                        currentKeyboardState.IsKeyDown(Keys.RightShift))
                    {
                        position.X   -= elapsedTime * 2 * velocity.X;
                        steeringState = SteeringState.HardRight;
                    }
                    else
                    {
                        position.X   -= elapsedTime * velocity.X;
                        steeringState = SteeringState.Right;
                    }
                }
            }
            // Fire bomb
            if (currentKeyboardState.IsKeyDown(Keys.B))
            {
                //checks if Player has the bomb power up
                if ((PowerupType & PowerupType.Bomb) > 0)
                {
                    if (bombTimer > 1.5f)
                    {
                        ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.Bomb, position);
                        bombTimer = 0f;
                    }
                }
            }
            if (bladesPowerupTimer > 10.0f && (PowerupType & PowerupType.Blades) > 0)
            {
                unApplyBlades();
            }

            // Used to test the energy blast powerup levels
            //if (currentKeyboardState.IsKeyDown(Keys.F) && oldKeyboardState.IsKeyUp(Keys.F))
            //    energyBlastLevel++;

            if ((PowerupType & PowerupType.Blades) == 0)
            {
                // Fire weapons
                if (currentKeyboardState.IsKeyDown(Keys.Space))
                {
                    // Streaming weapons
                    if ((PowerupType & PowerupType.BubbleBeam) > 0)
                    {
                        if (defaultGunTimer > BubbleBullet.FIRE_INTERVAL_MS)
                        {
                            ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.BubbleBullet, position);
                            defaultGunTimer = 0f;
                        }
                    }

                    // Fires a shotgun shot if the shotgun powerup is active and half a second has passed since the last shot
                    if ((PowerupType & PowerupType.ShotgunPowerup) > 0 &&
                        defaultGunTimer > 0.5f)
                    {
                        TriggerShotgun();
                        defaultGunTimer = 0;
                    }

                    // Default gun
                    if (defaultGunTimer > 0.25f)
                    {
                        ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.Bullet, position);
                        defaultGunTimer = 0f;
                    }


                    //Conditionals to fire railgun.
                    if ((PowerupType & PowerupType.Railgun) > 0)
                    {
                        if (railgunTimer > 3.0f)
                        {
                            TriggerRailgun();
                            railgunTimer = 0f;
                        }
                    }

                    // Energy Blast Gun
                    if (((PowerupType & PowerupType.EnergyBlast) > 0) && energyBlastTimer < 0)
                    {
                        TriggerEnergyBlast();
                    }

                    // Fire-once weapons
                    if (oldKeyboardState.IsKeyUp(Keys.Space))
                    {
                        if ((PowerupType & PowerupType.Fireball) > 0)
                        {
                            TriggerFireball();
                        }

                        if ((PowerupType & PowerupType.DroneWave) > 0)
                        {
                            TriggerDroneWave();
                        }
                    }

                    if ((PowerupType & PowerupType.Frostball) > 0)
                    {
                        TriggerFrostball();
                    }

                    if ((PowerupType & PowerupType.Birdcrap) > 0)
                    {
                        TriggerBirdcrap();
                    }
                    if ((PowerupType & PowerupType.Bomb) > 0)
                    {
                        TriggerBomb();
                    }
                }
            }

            // store the current keyboard state for next frame
            oldKeyboardState = currentKeyboardState;
        }
예제 #21
0
        /// <summary>
        /// Updates the ship
        /// </summary>
        /// <param name="elapsedTime"></param>
        public override void Update(float elapsedTime)
        {
            KeyboardState currentKeyboardState = Keyboard.GetState();

            // Update timers
            defaultGunTimer += elapsedTime;
            bladesPowerupTimer += elapsedTime;
            energyBlastTimer -= elapsedTime;
            bombTimer += elapsedTime;
            railgunTimer += elapsedTime;
            homingMissileTimer -= elapsedTime;

            if (!drunk)
            {
                // Steer the ship up or down according to user input
                if (currentKeyboardState.IsKeyDown(Keys.Up))
                {
                    position.Y -= elapsedTime * velocity.Y;
                }
                else if (currentKeyboardState.IsKeyDown(Keys.Down))
                {
                    position.Y += elapsedTime * velocity.Y;
                }

                // Steer the ship left or right according to user input
                steeringState = SteeringState.Straight;

                if (currentKeyboardState.IsKeyDown(Keys.Left))
                {
                    if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                        currentKeyboardState.IsKeyDown(Keys.RightShift))
                    {
                        steeringState = SteeringState.HardLeft;
                        position.X -= elapsedTime * 2 * velocity.X;

                    }
                    else
                    {
                        steeringState = SteeringState.Left;
                        position.X -= elapsedTime * velocity.X;
                    }
                }
                else if (currentKeyboardState.IsKeyDown(Keys.Right))
                {
                    if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                        currentKeyboardState.IsKeyDown(Keys.RightShift))
                    {
                        position.X += elapsedTime * 2 * velocity.X;
                        steeringState = SteeringState.HardRight;
                    }
                    else
                    {
                        position.X += elapsedTime * velocity.X;
                        steeringState = SteeringState.Right;
                    }
                }
            }

            //Player is drunk and movements are reversed.
            else
            {
                //Decrease drunkCounter and make the player sober if their drunk time is up.
                drunkCounter--;
                if (drunkCounter == 0)
                {
                    SoberUp();
                }
                // Steer the ship up or down according to user input
                if (currentKeyboardState.IsKeyDown(Keys.Up))
                {
                    position.Y += elapsedTime * velocity.Y;
                }

                else if (currentKeyboardState.IsKeyDown(Keys.Down))
                {
                    position.Y -= elapsedTime * velocity.Y;
                }

                // Steer the ship left or right according to user input
                steeringState = SteeringState.Straight;

                if (currentKeyboardState.IsKeyDown(Keys.Left))
                {
                    if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                        currentKeyboardState.IsKeyDown(Keys.RightShift))
                    {
                        steeringState = SteeringState.HardLeft;
                        position.X += elapsedTime * 2 * velocity.X;

                    }
                    else
                    {
                        steeringState = SteeringState.Left;
                        position.X += elapsedTime * velocity.X;
                    }
                }
                else if (currentKeyboardState.IsKeyDown(Keys.Right))
                {
                    if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                        currentKeyboardState.IsKeyDown(Keys.RightShift))
                    {
                        position.X -= elapsedTime * 2 * velocity.X;
                        steeringState = SteeringState.HardRight;
                    }
                    else
                    {
                        position.X -= elapsedTime * velocity.X;
                        steeringState = SteeringState.Right;
                    }
                }
            }
            // Fire bomb
            if (currentKeyboardState.IsKeyDown(Keys.B))
            {
                //checks if player has the bomb power up
                if ((PowerupType & PowerupType.Bomb) > 0)
                {
                    if (bombTimer > 1.5f)
                    {
                        ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.Bomb, position);
                        bombTimer = 0f;
                    }
                }
            }
            if (bladesPowerupTimer > 10.0f && (PowerupType & PowerupType.Blades) > 0)
            {
                unApplyBlades();
            }

            // Used to test the energy blast powerup levels
            //if (currentKeyboardState.IsKeyDown(Keys.F) && oldKeyboardState.IsKeyUp(Keys.F))
            //    energyBlastLevel++;
            if ((PowerupType & PowerupType.Blades) == 0)
            {
                // Fire weapons
                if (currentKeyboardState.IsKeyDown(Keys.Space))
                {
                    if ((PowerupType & PowerupType.Freezewave) > 0)
                    {
                        if (defaultGunTimer > .5f)
                        {
                            ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.FreezewaveProjectile, position);
                        }
                    }
                    // Streaming weapons
                    if ((PowerupType & PowerupType.BubbleBeam) > 0)
                    {
                        if (defaultGunTimer > BubbleBullet.FIRE_INTERVAL_MS)
                        {
                            ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.BubbleBullet, position);
                            defaultGunTimer = 0f;
                        }
                    }

                    // Fires a shotgun shot if the shotgun powerup is active and half a second has passed since the last shot
                    if ((PowerupType & PowerupType.ShotgunPowerup) > 0 && shotgunTimer > 0.5f)
                    {
                        TriggerShotgun();
                        shotgunTimer = 0;
                    }

                    // Default gun
                    if (defaultGunTimer > 0.25f)
                    {
                        ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.Bullet, position);
                        bulletFired.Play();
                        defaultGunTimer = 0f;
                    }

                    if((PowerupType & PowerupType.HomingMissiles) > 0)
                    {
                        if (homingMissileTimer <= 0)
                        {
                            homingMissileTimer = homingMissileFireRate;
                            TriggerHomingMissile();
                        }
                    }

                    //Conditionals to fire railgun.
                    if ((PowerupType & PowerupType.Railgun) > 0)
                    {
                        if (railgunTimer > 3.0f)
                        {
                            TriggerRailgun();
                            railgunTimer = 0f;
                        }
                    }

                    // Energy Blast Gun
                    if (((PowerupType & PowerupType.EnergyBlast) > 0) && energyBlastTimer < 0)
                    {
                        TriggerEnergyBlast();
                    }

                    // Fire-once weapons
                    if (oldKeyboardState.IsKeyUp(Keys.Space))
                    {

                        if ((PowerupType & PowerupType.Fireball) > 0)
                            TriggerFireball();

                        if ((PowerupType & PowerupType.DroneWave) > 0)
                        {
                            TriggerDroneWave();
                        }
                    }

                    if ((PowerupType & PowerupType.Frostball) > 0)
                        TriggerFrostball();

                    if ((PowerupType & PowerupType.Birdcrap) > 0)
                    {
                        TriggerBirdcrap();
                    }

                    if ((PowerupType & PowerupType.Bomb) > 0)
                        TriggerBomb();
                }
            }

            // store the current keyboard state for next frame
            oldKeyboardState = currentKeyboardState;
        }
예제 #22
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            if (System.Math.Abs(joystick.GetAxis().y) > System.Math.Abs(joystick.GetAxis().x))
            {
                // If the joystick is pressed forward and the button is pressed
                if (joystick.GetAxis().y > 0.0f && button.GetPress())
                {
                    // Change state to steering forward
                    state = SteeringState.SteeringForward;
                }

                // If the joystick is pressed backward and the button is pressed
                else if (joystick.GetAxis().y < 0.0f && button.GetPress())
                {
                    // Change state to steering backward
                    state = SteeringState.SteeringBackward;
                }
            }

            else if (System.Math.Abs(joystick.GetAxis().y) < System.Math.Abs(joystick.GetAxis().x))
            {
                // If the joystick is pressed forward and the button is pressed
                if (joystick.GetAxis().x > 0.0f && button.GetPress())
                {
                    // Change state to steering forward
                    state = SteeringState.SteeringRight;
                }

                // If the joystick is pressed backward and the button is pressed
                else if (joystick.GetAxis().x < 0.0f && button.GetPress())
                {
                    // Change state to steering backward
                    state = SteeringState.SteeringLeft;
                }
            }

            else
            {
                state = SteeringState.NotSteering;
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            else if (System.Math.Abs(joystick.GetAxis().y) < System.Math.Abs(joystick.GetAxis().x))
            {
                // If the joystick is pressed right and the button is pressed
                if (joystick.GetAxis().x > 0.0f && button.GetPress())
                {
                    // Change state to steering right
                    state = SteeringState.SteeringRight;
                }

                // If the joystick is pressed left and the button is pressed
                else if (joystick.GetAxis().x < 0.0f && button.GetPress())
                {
                    // Change state to steering left
                    state = SteeringState.SteeringLeft;
                }
            }
            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringBackward;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        else if (state == SteeringState.SteeringBackward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            else if (System.Math.Abs(joystick.GetAxis().y) < System.Math.Abs(joystick.GetAxis().x))
            {
                // If the joystick is pressed right and the button is pressed
                if (joystick.GetAxis().x > 0.0f && button.GetPress())
                {
                    // Change state to steering right
                    state = SteeringState.SteeringRight;
                }

                // If the joystick is pressed left and the button is pressed
                else if (joystick.GetAxis().x < 0.0f && button.GetPress())
                {
                    // Change state to steering left
                    state = SteeringState.SteeringLeft;
                }
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }


        else if (state == SteeringState.SteeringRight)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward or backward and the button is pressed
            else if (System.Math.Abs(joystick.GetAxis().x) < System.Math.Abs(joystick.GetAxis().y))
            {
                // If the joystick is pressed forward and the button is pressed
                if (joystick.GetAxis().y > 0.0f && button.GetPress())
                {
                    // Change state to steering forward
                    state = SteeringState.SteeringForward;
                }

                // If the joystick is pressed backward and the button is pressed
                else if (joystick.GetAxis().y < 0.0f && button.GetPress())
                {
                    // Change state to steering backward
                    state = SteeringState.SteeringBackward;
                }
            }

            else if (joystick.GetAxis().x < 0 && button.GetPress())
            {
                state = SteeringState.SteeringLeft;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.right;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().x *direction *speed *Time.deltaTime;
            }
        }

        else if (state == SteeringState.SteeringLeft)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward or backward and the button is pressed
            else if (System.Math.Abs(joystick.GetAxis().x) < System.Math.Abs(joystick.GetAxis().y))
            {
                // If the joystick is pressed forward and the button is pressed
                if (joystick.GetAxis().y > 0.0f && button.GetPress())
                {
                    // Change state to steering forward
                    state = SteeringState.SteeringForward;
                }

                // If the joystick is pressed backward and the button is pressed
                else if (joystick.GetAxis().y < 0.0f && button.GetPress())
                {
                    // Change state to steering backward
                    state = SteeringState.SteeringBackward;
                }
            }

            else if (joystick.GetAxis().x > 0 && button.GetPress())
            {
                state = SteeringState.SteeringRight;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.right;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().x *direction *speed *Time.deltaTime;
            }
        }
    }
예제 #23
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            // If the joystick is pressed forward and the button is pressed
            if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            // Process current steering forward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.SteeringBackward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }
    }
예제 #24
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            // If the joystick is pressed forward and the button is pressed
            if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }


            // If the trigger button is pressed
            else if (jumpButton.GetPress())
            {
                // Change state to jump state
                state = SteeringState.Jump;
            }



            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            // Process current steering forward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.SteeringBackward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
            }
        }


        // If it is a jump state
        else if (state == SteeringState.Jump)
        {
            // If the button is not pressed
            if (!jumpButton.GetPress())
            {
                // Change state to fall
                state = SteeringState.Fall;
            }


            // Process current steering jump state
            else
            {
                Vector3 direction;
                direction = Vector3.up;

                // Translate the space to so that the user can jump
                while (i < 10)
                {
                    space.transform.position += Vector3.up * Time.deltaTime;
                    if (i == 9)
                    {
                        Thread.Sleep(1000);
                    }

                    i++;
                }
            }
        }
    }
예제 #25
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        if (isHit)
        {
            state = SteeringState.ForcedBrake;
        }
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            if (trigger.GetPress() || joystick.GetAxis().x > 0)
            {
                state = SteeringState.Accelerate;
            }

            if (joystick.GetAxis().x > 0)
            {
                state = SteeringState.Accelerate;
            }
            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        else if (state == SteeringState.Accelerate)
        {
            played = false;
            if (BrakeTrigger.GetPress())
            {
                state = SteeringState.Brake;
            }
            else if (!trigger.GetPress() && joystick.GetAxis().x == 0)
            {
                state = SteeringState.Decelerate;
            }

            else
            {
                deltaRotation             = GameObject.Find("scripts/VirtualHand").GetComponent <VirtualHand> ().deltaRotation;
                speed                     = joystick.GetAxis().x *acceleration_factor *   100;
                space.transform.position += space.transform.forward * Time.deltaTime * speed;
                space.transform.Rotate(0, deltaRotation.y * 20, 0);
                Debug.Log("Accelerate");
                if (acc_sound.isPlaying)
                {
                }
                else
                {
                    acc_sound.Play();
                    brk_sound.Stop();
                }
            }
        }
        else if (state == SteeringState.Decelerate)
        {
            if (BrakeTrigger.GetPress())
            {
                state = SteeringState.NotSteering;
            }
            else if (speed <= 0)
            {
                state = SteeringState.NotSteering;
            }
            else if (trigger.GetPress() || joystick.GetAxis().x > 0)
            {
                state = SteeringState.Accelerate;
            }
            else
            {
                deltaRotation             = GameObject.Find("scripts/VirtualHand").GetComponent <VirtualHand> ().deltaRotation;
                space.transform.position += space.transform.forward * speed * Time.deltaTime;
                speed -= speed * acceleration_factor;
                space.transform.Rotate(0, deltaRotation.y * 20, 0);
                Debug.Log("Decelerate");
                acc_sound.Stop();
            }
        }

        else if (state == SteeringState.Brake)
        {
            if (!BrakeTrigger.GetPress())
            {
                state = SteeringState.Decelerate;
            }
            else if (speed <= 0)
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                //space.transform.position += space.transform.forward * speed * Time.deltaTime * acceleration_factor;
                space.transform.position += space.transform.forward * speed * Time.deltaTime;
                speed -= speed * acceleration_factor;
                Debug.Log("Brake");
                if (brk_sound.isPlaying || played)
                {
                }
                else
                {
                    brk_sound.Play();
                    acc_sound.Stop();
                    played = true;
                }
            }
        }
        else if (state == SteeringState.ForcedBrake)
        {
            acc_sound.Stop();
            brk_sound.Stop();
            Debug.Log("force brake");
            if (gripButton.GetPress())
            {
                space.transform.rotation = originalSpaceRotation;
                space.transform.position = originalSpaceTransform;
                car.transform.rotation   = originalCarRotation;
                car.transform.position   = originalCarTransform;
                GameObject broken_window = GameObject.Find("front_window_broken");
                GameObject good_window   = GameObject.Find("front_window");

                GameObject steeringWheel = GameObject.Find("steeringpivot");
                steeringWheel.transform.rotation = originalWheelRotation;
                steeringWheel.transform.position = originalWheelTransform;
                speed = 0;

                deltaRotation.Set(0, 0, 0, 0);

                broken_window.GetComponent <MeshRenderer>().enabled = false;
                good_window.GetComponent <MeshRenderer>().enabled   = true;
                isHit = false;
                state = SteeringState.NotSteering;
            }
            else if (speed <= 1)
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                space.transform.position += space.transform.forward * speed * Time.deltaTime * -1 * acceleration_factor;
                speed -= speed * acceleration_factor;
            }
        }
    }
예제 #26
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            ResetHeight();
            // If the joystick is pressed forward and the btnTouchpad is pressed
            if (joystick.GetAxis().y > 0.0f && btnTouchpad.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the btnTouchpad is pressed
            else if (joystick.GetAxis().y < 0.0f && btnTouchpad.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }
            else if (btnTrigger.GetPress())
            {
                state = SteeringState.Hop;
            }

            else if (btnTeleport.GetPress())
            {
                state = SteeringState.Teleport;
            }
            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the btnTouchpad is not pressed
            if (!btnTouchpad.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed backward and the btnTouchpad is pressed
            else if (joystick.GetAxis().y < 0.0f && btnTouchpad.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            // Process current steering forward state
            else
            {
                // Added to avoid flying up or down while moving
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.SteeringBackward)
        {
            // If the btnTouchpad is not pressed
            if (!btnTouchpad.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the btnTouchpad is pressed
            else if (joystick.GetAxis().y > 0.0f && btnTouchpad.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                // Added to avoid flying up or down while moving
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        // if state is hop
        else if (state == SteeringState.Hop)
        {
            // If the btnTrigger is not pressed
            if (!btnTrigger.GetPress())
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                Hop();
            }
        }

        // if state is teleport
        else if (state == SteeringState.Teleport)
        {
            // If the btnTeleport is not pressed
            if (!btnTeleport.GetPress())
            {
                // Return state to NotSteering
                state = SteeringState.NotSteering;
                // Set teleportFlag to true, to let the user teleport again.
                teleportFlag = true;
            }
            else
            {
                // ensures that the user can teleport only one level when they press the trigger
                if (teleportFlag)
                {
                    // move to another room
                    Teleport();
                }
            }
        }
    }
예제 #27
0
        /// <summary>
        /// Updates the ship
        /// </summary>
        /// <param name="elapsedTime"></param>
        public override void Update(float elapsedTime)
        {
            KeyboardState currentKeyboardState = Keyboard.GetState();

            // Update timers
            defaultGunTimer += elapsedTime;

            // Steer the ship up or down according to user input
            if(currentKeyboardState.IsKeyDown(Keys.Up))
            {
                position.Y -= elapsedTime * velocity.Y;
            }
            else if(currentKeyboardState.IsKeyDown(Keys.Down))
            {
                position.Y += elapsedTime * velocity.Y;
            }

            // Steer the ship left or right according to user input
            steeringState = SteeringState.Straight;

            if (currentKeyboardState.IsKeyDown(Keys.Left))
            {
                if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                    currentKeyboardState.IsKeyDown(Keys.RightShift))
                {
                    steeringState = SteeringState.HardLeft;
                    position.X -= elapsedTime * 2 * velocity.X;

                }
                else
                {
                    steeringState = SteeringState.Left;
                    position.X -= elapsedTime * velocity.X;
                }
            }
            else if (currentKeyboardState.IsKeyDown(Keys.Right))
            {
                if (currentKeyboardState.IsKeyDown(Keys.LeftShift) ||
                    currentKeyboardState.IsKeyDown(Keys.RightShift))
                {
                    position.X += elapsedTime * 2 * velocity.X;
                    steeringState = SteeringState.HardRight;
                }
                else
                {
                    position.X += elapsedTime * velocity.X;
                    steeringState = SteeringState.Right;
                }
            }

            // Fire weapons
            if (currentKeyboardState.IsKeyDown(Keys.Space))
            {
                // Streaming weapons

                // Default gun
                if (defaultGunTimer > 0.25f)
                {
                    ScrollingShooterGame.Game.projectiles.Add(new Bullet(ScrollingShooterGame.Game.Content, position));
                    defaultGunTimer = 0f;
                }

                // Fire-once weapons
                if (oldKeyboardState.IsKeyUp(Keys.Space))
                {

                    if ((powerups & Powerups.Fireball) > 0)
                        TriggerFireball();
                }
            }

            // store the current keyboard state for next frame
            oldKeyboardState = currentKeyboardState;
        }
예제 #28
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            // If the joystick is pressed forward and the button is pressed
            if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            //HW2 - If the joystick is pressed leftward and the button is pressed
            else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering leftward
                state = SteeringState.SteeringLeft;
            }

            //HW2 - If the joystick is pressed rightward and the button is pressed
            else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering rightward
                state = SteeringState.SteeringRight;
            }



            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            //HW2 - If the joystick is pressed leftward and the button is pressed
            else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering leftward
                state = SteeringState.SteeringLeft;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            //HW2 - If the joystick is pressed rightward and the button is pressed
            else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering rightward
                state = SteeringState.SteeringRight;
            }

            // Process current steering forward state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.SteeringBackward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            //HW2 - If the joystick is pressed leftward and the button is pressed
            else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering leftward
                state = SteeringState.SteeringLeft;
            }

            //HW2 - If the joystick is pressed rightward and the button is pressed
            else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering rightward
                state = SteeringState.SteeringRight;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
            }
        }

        //HW2 - if state is steering leftward
        else if (state == SteeringState.SteeringLeft)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            //HW2 - If the joystick is pressed rightward and the button is pressed
            else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering rightward
                state = SteeringState.SteeringRight;
            }

            // Process current strafe left state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().x *tracker.transform.right *speed *Time.deltaTime;
            }
        }

        //HW2 - If state is steering rightward
        else if (state == SteeringState.SteeringRight)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            //HW2 - If the joystick is pressed leftward and the button is pressed
            else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering leftward
                state = SteeringState.SteeringLeft;
            }

            // Process current strafe right state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().x *tracker.transform.right *speed *Time.deltaTime;
            }
        }
    }