Category5.VictimMan.Move C# (CSharp) Method

Move() protected method

protected Move ( float time ) : void
time float
return void
        protected override void Move(float time)
        {
            switch(state)
            {
                case State.Ground:
                    switch (aiState)
                    {
                        case AiState.Running:
                            {
                                updateErrorAngle(0.2f, (float)Math.PI / 8);
                                moveAngle = getAngleToPoint(megatile.level.Tornado.Position) + (float)Math.PI + (speed/3.0f) * errorAngle;

                                drawAngle = moveAngle;
                                Rectangle2D tempLocation = this.bounds.Copy();

                                #region performmove
                                tempLocation.X += (float)(Math.Sin(moveAngle) * (speed)) * time * timeScaleFactor;
                                tempLocation.Y -= (float)(Math.Cos(moveAngle) * (speed)) * time * timeScaleFactor;
                                #endregion

                                #region Do we panic?
                                if (this.megatile.Bounds.IsWithin(tempLocation))
                                {
                                    //we are still within our megatile
                                    this.bounds = tempLocation;
                                }
                                else
                                {
                                    //go crazy
                                    aiState = AiState.Panic;
                                }
                                #endregion
                            }
                            break;
                        case AiState.Panic:
                            {
                                Rectangle2D tempLocation = this.bounds.Copy();
                                if (!free)
                                {
                                    updateErrorAngle(0.2f, (float)Math.PI / 8);

                                    moveAngle += errorAngle;
                                    drawAngle = moveAngle;
                                }

                                #region performmove
                                tempLocation.X += (float)(Math.Sin(moveAngle) * (speed)) * time * timeScaleFactor;
                                tempLocation.Y -= (float)(Math.Cos(moveAngle) * (speed)) * time * timeScaleFactor;
                                #endregion

                                if (this.megatile.Bounds.IsWithin(tempLocation))
                                {
                                    //we are still within our megatile
                                    this.bounds = tempLocation;
                                    free = true;
                                }
                                else
                                {
                                    free = false;
                                }
                            }
                            break;
                    }
                    break;
                case State.Flying:
                    aiState = AiState.Panic;

                    updateErrorDist(tornado.Radius / 8, tornado.Radius / 1.5f); //generates a new error term
                    updateErrorSpeed(tornado.RotationalSpeed / 10.0f, tornado.RotationalSpeed / 2); //generates a new error speed term

                    moveAngle = getAngleToPoint(tornado.Position) + (float)Math.PI / (2 * (getDistanceFromTornado() / (tornado.Radius + errorDist)));

                    #region performmove
                    this.bounds.X += (float)(Math.Sin(moveAngle) * (tornado.RotationalSpeed + errorSpeed)) * time * timeScaleFactor;
                    this.bounds.Y -= (float)(Math.Cos(moveAngle) * (tornado.RotationalSpeed + errorSpeed)) * time * timeScaleFactor;
                    #endregion

                    #region RubberBand
                    RubberBandMe(time);
                    #endregion
                    break;
            }
        }