Example #1
0
    // Use this for initialization
    void Start()
    {
        config = Constants.Configuration.Instance;
        tag    = "Tram";

        highlited         = false;
        currentClip       = 0;
        waitOffset        = 0;
        clipInCycle       = 0;
        clipCount         = 0;
        substringDivisor  = 10;
        accelerationState = AccelerationState.None;

        // Set the highlighted and default materials
        DefaultMaterials = transform.GetChild(0).GetComponent <MeshRenderer>().materials;
        HighlightMaterials.Add(Resources.Load("Silhouetted Diffuse") as Material);
        HighlightMaterials.Add(Resources.Load("Silhouetted Diffuse") as Material);
        for (int i = HighlightMaterials.Count - 1; i < DefaultMaterials.Length; i++)
        {
            HighlightMaterials.Add(DefaultMaterials[i]);
        }

        // Now that our arrays have been initialized, we can create our first two clips
        if (!travelTram)
        {
            StartCoroutine("CreateClips", 2);
        }
        else
        {
            startTime = Time.unscaledTime;
        }
    }
Example #2
0
 //Constructor -----------------------------------------------------------------------------------
 private PlayerShip(Texture2D loadedSprite, Vector2 startingPosition)
     : base(loadedSprite)
 {
     score = 0;
     this.z_health = 100;
     //IMPORTANT!! Acceleration must divide into maxSpeed evenly.
     this.z_maxSpeed = 7.0f; // <--- Is this divisable
     this.z_acceleration = 1.0f;// <-- By this?
     //END-IMPORTANT
     this.z_IsSlowingDownX = false;
     this.z_IsSlowingDownY = false;
     this.z_accelTimerX = 0;
     this.z_accelTimerY = 0;
     this.z_currentXstate = AccelerationState.zero;
     this.z_currentYstate = AccelerationState.zero;
     this.Lives = 3;
     this.IsInvincible = true;
     this.z_startingPosition = startingPosition;
     this.Position = z_startingPosition;
     SpriteRows = 1;
     SpriteCols = 1;
     this.z_animationDelay = 50;
     z_hitRecInvincible = new Rectangle(100000, 100000, 0, 0);
     z_hitCircleInvincible = new Circle(new Vector2(100000, 100000), 0);
     DrawRotation = MathHelper.PiOver2;
     SpriteOrientation = MathHelper.PiOver2;
     DrawDepth = .4f;
 }
 //Constructor -----------------------------------------------------------------------------------
 public PlayerShip(Texture2D loadedSprite, Vector2 startingPosition)
     : base(loadedSprite)
 {
     this.z_health = 100;
     //IMPORTANT!! Acceleration must divide into maxSpeed evenly.
     this.z_maxSpeed = 4.9f; // <--- Is this divisable
     this.z_acceleration = .7f;// <-- By this?
     //END-IMPORTANT
     this.z_IsSlowingDownX = false;
     this.z_IsSlowingDownY = false;
     this.z_accelTimerX = 0;
     this.z_accelTimerY = 0;
     this.z_currentXstate = AccelerationState.zero;
     this.z_currentYstate = AccelerationState.zero;
     this.z_lives = 10;
     this.z_IsInvincible = true;
     this.z_InvincibleTimer = 0;
     this.z_drawTimer = 0;
     this.z_startingPosition = startingPosition;
     this.setPosition(z_startingPosition);
 }
        private void UpdateState()
        {
            float eventValue = point.Value;
            float accelDiff  = Math.Abs(BaseLine - eventValue);

            if (accelDiff > DifferenceThreshold)
            {
                state = state == AccelerationState.WithinThresholdTracking ? AccelerationState.IgnoringEvent : AccelerationState.TrackingEvent;
            }
            else
            {
                if (state == AccelerationState.TrackingEvent)
                {
                    state = AccelerationState.WithinThresholdTracking;
                }
                else
                {
                    state = AccelerationState.WithinThreshold;
                }
            }

            if (state == AccelerationState.TrackingEvent)
            {
                if (eventValue > 0 && eventValue > EventMaximum)
                {
                    EventMaximum = eventValue;
                }
                else if (eventValue < 0 && eventValue < EventMaximum)
                {
                    EventMaximum = eventValue;
                }
            }

            if (state == AccelerationState.WithinThreshold)
            {
                EventMaximum = 0;
            }
        }
Example #5
0
 /// <summary>
 /// Controls the movement of the tram if it makes stops
 /// Has an acceleration, deceleration, cruise, and wait state
 /// </summary>
 /// <param name="clipName"></param>
 private void MoveTramWithStops(string clipName)
 {
     if (clipName == "Wait")
     {
         // If we just switched to waiting, set the state and the speed
         // This will make the tram wait at a key
         if (accelerationState != AccelerationState.Wait)
         {
             accelerationState = AccelerationState.Wait;
             speed             = config.TramWaitTime;
         }
     }
     else
     {
         // If we just swithced to cruising, set the state and speed
         // This will set the tram to move at its top speed
         if (accelerationState != AccelerationState.Cruise)
         {
             accelerationState = AccelerationState.Cruise;
             speed             = cruiseTime;
         }
     }
 }
Example #6
0
 private void resetYvelocity()
 {
     this.z_currentYstate = AccelerationState.zero;
     this.setVelocity(new Vector2(this.getVelocity().X, 0));
     this.z_IsSlowingDownY = false;
 }
Example #7
0
 //Helper Methods for updating the player's ship
 private void resetXvelocity()
 {
     this.z_currentXstate = AccelerationState.zero;
     this.setVelocity(new Vector2(0, this.getVelocity().Y));
     this.z_IsSlowingDownX = false;
 }
Example #8
0
 public void reset()
 {
     score = 0;
     this.z_health = 100;
     //IMPORTANT!! Acceleration must divide into maxSpeed evenly.
     this.z_maxSpeed = 4.9f; // <--- Is this divisable
     this.z_acceleration = .7f;// <-- By this?
     //END-IMPORTANT
     this.z_IsSlowingDownX = false;
     this.z_IsSlowingDownY = false;
     this.z_accelTimerX = 0;
     this.z_accelTimerY = 0;
     this.z_currentXstate = AccelerationState.zero;
     this.z_currentYstate = AccelerationState.zero;
     this.z_lives = 3;
     this.z_IsInvincible = true;
     this.z_InvincibleTimer = 0;
     this.z_drawTimer = 0;
     this.setPosition(z_startingPosition);
     this.resetXvelocity();
     this.resetYvelocity();
 }
Example #9
0
 public void accelerateUp()
 {
     if (this.getVelocity().Y > -1 * this.z_maxSpeed)
     {
         if (this.z_IsSlowingDownY)
             this.resetYvelocity();
         this.setVelocity(new Vector2(this.getVelocity().X, this.getVelocity().Y - this.z_acceleration));
         this.z_currentYstate = AccelerationState.negative;
     }
 }
Example #10
0
 public void accelerateRight()
 {
     if (this.getVelocity().X < this.z_maxSpeed)
     {
         if (this.z_IsSlowingDownX)
             this.resetXvelocity();
         this.setVelocity(new Vector2(this.getVelocity().X + this.z_acceleration, this.getVelocity().Y));
         this.z_currentXstate = AccelerationState.positive;
     }
 }
Example #11
0
 //Acceleration Methods ---------------------------------------------------------------------------------
 public void accelerateLeft()
 {
     if (this.getVelocity().X > -1 * this.z_maxSpeed)
     {
         if (this.z_IsSlowingDownX)
             this.resetXvelocity();
         this.setVelocity(new Vector2(this.getVelocity().X - this.z_acceleration, this.getVelocity().Y));
         this.z_currentXstate = AccelerationState.negative;
     }
 }
Example #12
0
 public void accelerateDown()
 {
     if (this.getVelocity().Y < this.z_maxSpeed)
     {
         if (this.z_IsSlowingDownY)
             this.resetYvelocity();
         this.setVelocity(new Vector2(this.getVelocity().X, this.getVelocity().Y + this.z_acceleration));
         this.z_currentYstate = AccelerationState.positive;
     }
 }
Example #13
0
 public void Stop()
 {
     _accelerationState = AccelerationState.Stopping;
     Acceleration = new Vector2((Velocity.X > 0 ? -1 : 1) * WalkingAcceleration, Acceleration.Y);
 }
Example #14
0
        public static RoverState Parse(String initString)
        {
            Char accStateChar = initString[0];
            Char turnStateChar = initString[1];

            AccelerationState accState;
            RotationState rotState;

            switch(accStateChar)
            {
                case 'a':
                    accState = AccelerationState.Accelerating;
                    break;
                case 'b':
                    accState = AccelerationState.Braking;
                    break;
                case '-':
                    accState = AccelerationState.Rolling;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("Can't parse acceleration state: " + accStateChar);
            }

            switch (turnStateChar)
            {
                case 'L':
                    rotState = RotationState.HardLeft;
                    break;
                case 'l':
                    rotState = RotationState.Left;
                    break;
                case '-':
                    rotState = RotationState.Straight;
                    break;
                case 'r':
                    rotState = RotationState.Right;
                    break;
                case 'R':
                    rotState = RotationState.HardRight;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("Can't parse rotation state: " + turnStateChar);
            }

            return new RoverState(accState, rotState);
        }
Example #15
0
 public RoverState(AccelerationState accState, RotationState rotState)
 {
     this.accState = accState;
     this.rotState = rotState;
 }
Example #16
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (_accelerationState == AccelerationState.Accelerating && Math.Abs(Velocity.X) >= WalkingSpeed) {
                Acceleration = new Vector2(0, Acceleration.Y);
                Velocity = new Vector2((Velocity.X > 0 ? 1 : -1) * WalkingSpeed, Velocity.Y);
                _accelerationState = AccelerationState.Idle;
            }

            if (
                _accelerationState == AccelerationState.Stopping
                && (
                    (Acceleration.X < 0 && Velocity.X <= 0)
                    || (Acceleration.X > 0 && Velocity.X >= 0)
                    )
            ) {
                Acceleration = new Vector2(0, Acceleration.Y);
                Velocity = new Vector2(0, Velocity.Y);
                _accelerationState = AccelerationState.Idle;
            }

            UpdateLegs(gameTime);
            LookAtUpdate();

            //UpdateWelds(gameTime);
        }
Example #17
0
 public void WalkRight()
 {
     _accelerationState = AccelerationState.Accelerating;
     if (!IsCollidingRight() && Acceleration.X != WalkingSpeed)
         Acceleration = new Vector2(WalkingAcceleration, Acceleration.Y);
     //Velocity = new Vector2(10, Velocity.Y);
 }