Esempio n. 1
0
 public shuttle(Texture2D im, SoundEffect shipsnd)
 {
     img          = im;
     position     = new Vector2(420, 420);
     currentstate = State.idle;
     direction    = Vector2.Zero;
     speed        = Vector2.Zero;
     rotation     = 0;
     mstate       = movingstate.idle;
     shipsound    = shipsnd;
 }
Esempio n. 2
0
        public void update(GameTime gametime)
        {
            KeyboardState CurrentKeyboardState = Keyboard.GetState();

            if (CurrentKeyboardState.IsKeyUp(Keys.Up) && CurrentKeyboardState.IsKeyUp(Keys.Left) && CurrentKeyboardState.IsKeyUp(Keys.Right) && CurrentKeyboardState.IsKeyUp(Keys.Down))
            {
                currentstate = State.idle;
                mstate       = movingstate.idle;
            }
            else if (CurrentKeyboardState.IsKeyDown(Keys.Up) || CurrentKeyboardState.IsKeyDown(Keys.Left) || CurrentKeyboardState.IsKeyDown(Keys.Right) || CurrentKeyboardState.IsKeyDown(Keys.Down))
            {
                currentstate = State.moving;
            }
            if ((CurrentKeyboardState.IsKeyDown(Keys.B) == true) && ((speed.Y != 0) || (speed.X != 0)))
            {
                brakeshuttle();
            }
            UpdateMovement(CurrentKeyboardState);
            PreviousKeyboardState = CurrentKeyboardState;
            position += direction * speed * (float)gametime.ElapsedGameTime.TotalSeconds;
        }
Esempio n. 3
0
        private void UpdateMovement(KeyboardState aCurrentKeyboardState)
        {
            if ((currentstate == State.moving))
            {
                speed     = Vector2.Zero;
                direction = Vector2.Zero;
                if ((aCurrentKeyboardState.IsKeyDown(Keys.Left) == true) && (aCurrentKeyboardState.IsKeyDown(Keys.Up)) == true)
                {
                    if (mstate == movingstate.upleft)
                    {
                        if (shuttle_speed <= topspeed)
                        {
                            shuttle_speed += acceleration;
                        }
                    }
                    rotation    = 5.5f;
                    speed.Y     = shuttle_speed;
                    speed.X     = shuttle_speed;
                    direction.X = left;
                    direction.Y = up;
                    mstate      = movingstate.upleft;
                    calibrateshipsound();     //takeout
                }
                else if ((aCurrentKeyboardState.IsKeyDown(Keys.Right) == true) && (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true))
                {
                    if (mstate == movingstate.upright)
                    {
                        if (shuttle_speed <= topspeed)
                        {
                            shuttle_speed += acceleration;
                        }
                    }

                    rotation    = 13.5f;
                    speed.Y     = shuttle_speed;
                    speed.X     = shuttle_speed;
                    direction.X = right;
                    direction.Y = up;
                    calibrateshipsound();    //takeout
                    mstate = movingstate.upright;
                }
                else if ((aCurrentKeyboardState.IsKeyDown(Keys.Left) == true) && (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true))
                {
                    if (mstate == movingstate.downleft)
                    {
                        if (shuttle_speed <= topspeed)
                        {
                            shuttle_speed += acceleration;
                        }
                    }

                    rotation    = 3.8f;
                    speed.Y     = shuttle_speed;
                    speed.X     = shuttle_speed;
                    direction.X = left;
                    direction.Y = down;
                    calibrateshipsound();    //takeout
                    mstate = movingstate.downleft;
                }
                else if ((aCurrentKeyboardState.IsKeyDown(Keys.Right) == true) && (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true))
                {
                    if (mstate == movingstate.downright)
                    {
                        if (shuttle_speed <= topspeed)
                        {
                            shuttle_speed += acceleration;
                        }
                    }

                    rotation    = 15.0f;
                    speed.Y     = shuttle_speed;
                    speed.X     = shuttle_speed;
                    direction.X = right;
                    direction.Y = down;
                    calibrateshipsound();    //takeout
                    mstate = movingstate.downright;
                }
                else if (aCurrentKeyboardState.IsKeyDown(Keys.Left) == true)
                {
                    if (mstate == movingstate.left)
                    {
                        if (shuttle_speed <= topspeed)
                        {
                            shuttle_speed += acceleration;
                        }
                    }
                    else
                    {
                        rotation = 4.7f;
                    }
                    speed.X     = shuttle_speed;
                    direction.X = left;
                    mstate      = movingstate.left;
                    calibrateshipsound();//takeout
                }
                else if (aCurrentKeyboardState.IsKeyDown(Keys.Right) == true)
                {
                    if (mstate == movingstate.right)
                    {
                        if (shuttle_speed <= topspeed)
                        {
                            shuttle_speed += acceleration;
                        }
                    }

                    rotation    = 14.1f;
                    speed.X     = shuttle_speed;
                    direction.X = right;
                    mstate      = movingstate.right;
                    calibrateshipsound();//takeout
                }
                else if (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true)
                {
                    if (mstate == movingstate.up)
                    {
                        if (shuttle_speed <= topspeed)
                        {
                            shuttle_speed += acceleration;
                        }
                    }

                    speed.Y     = shuttle_speed;
                    direction.Y = up;
                    rotation    = 0.0f;
                    mstate      = movingstate.up;
                    calibrateshipsound();//takeout
                }
                else if (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true)
                {
                    if (mstate == movingstate.down)
                    {
                        if (shuttle_speed <= topspeed)
                        {
                            shuttle_speed += acceleration;
                        }
                    }

                    speed.Y     = shuttle_speed;
                    direction.Y = down;
                    rotation    = 3.1f;
                    mstate      = movingstate.down;
                    calibrateshipsound();//takeout
                }
            }
        }