コード例 #1
0
        public void OnAlarm(StepState state)
        {
            switch (Action)
            {
            case ACTIONS.WALK_LEFT:
                Action = ACTIONS.STAND_LEFT;
                Hero.State.SetAnimation(0, "стоять ", true);
                GridPosition += new Point(-1, 0);
                break;

            case ACTIONS.WALK_RIGHT:
                Action = ACTIONS.STAND_LEFT;
                Hero.State.SetAnimation(0, "стоять ", true);
                GridPosition += new Point(1, 0);
                break;

            case ACTIONS.TO_SIT:
                Action = ACTIONS.SIT;
                VSize  = SIT_HEIGHT;
                break;

            case ACTIONS.FROM_SIT:
                Action = ACTIONS.STAND_LEFT;
                VSize  = HEIGHT;
                break;

            case ACTIONS.SQUAT_LEFT:
                Action        = ACTIONS.SIT;
                GridPosition += new Point(-1, 0);
                break;

            case ACTIONS.SQUAT_RIGHT:
                Action        = ACTIONS.SIT;
                GridPosition += new Point(1, 0);
                break;

            case ACTIONS.GET_DOWN:
                Action        = ACTIONS.HANG_DOWN;
                GridPosition += new Point(0, 2);
                break;

            case ACTIONS.GET_UP:
                Action        = ACTIONS.STAND_LEFT;
                GridPosition += new Point(0, -2);
                break;

            case ACTIONS.JUMP_ON:
                Action        = ACTIONS.HANG_DOWN;
                GridPosition += new Point(0, -2);
                VSpeed        = 0f;
                break;
            }
        }
コード例 #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            StepState State = new StepState(gameTime, Keyboard.GetState(), Mouse.GetState());

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || State.Keyboard.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            float cam_spd = 0.1f;
            float dx      = (State.Keyboard.IsKeyDown(Keys.Right) ? cam_spd : 0) - (State.Keyboard.IsKeyDown(Keys.Left) ? cam_spd : 0);
            float dy      = (State.Keyboard.IsKeyDown(Keys.Down) ? cam_spd : 0) - (State.Keyboard.IsKeyDown(Keys.Up) ? cam_spd : 0);

            Cam.Position = new Vector2(Cam.Position.X + dx, Cam.Position.Y + dy);
            Player.Hero.Update(gameTime);

            Player.Step(State);
            Cam.Position = Player.Position - Size.ToVector2( ) / Cam.Scale / 2f;
            hackScreen.Update(gameTime, State);

            base.Update(gameTime);
        }
コード例 #3
0
        public void Update(GameTime gameTime, StepState State)
        {
            if (Words != null)
            {
                for (int i = 0; i < Words.Count; i++)
                {
                    Words[i].Update(gameTime, Pos);
                }
            }
            if (Items != null)
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    Items[i].Pos = savedItems.Location.ToVector2() + Vector2.UnitX * (savedItems.Width / 2 - 5) + Vector2.UnitY * (i * 25 + 10);
                    Items[i].Update(gameTime, Pos);
                }
            }
            Point mousePos = State.Mouse.Position;

            if (DraggableText == null)
            {
                if (State.Mouse.LeftButton == ButtonState.Pressed)
                {
                    for (int i = 0; i < Words.Count && DraggableText == null && Words[i].textObject != null; i++)
                    {
                        Rectangle item = Words[i].Rect;
                        item.Offset(Pos);
                        if (item.Contains(mousePos) && Words[i].textObject.Draggable)
                        {
                            DraggableText       = new Tuple <TextObject, int, bool>(Words[i].textObject, i, true);
                            Words[i].textObject = null;
                        }
                    }
                    for (int i = 0; i < Items.Count && DraggableText == null; i++)
                    {
                        Rectangle item = Items[i].GetRectangle();
                        item.Offset(Pos);
                        if (item.Contains(mousePos))
                        {
                            DraggableText = new Tuple <TextObject, int, bool>(Items[i], i, false);
                            Items.RemoveAt(i);
                        }
                    }
                }
            }
            else
            {
                DraggableText.Item1.Update(gameTime, Pos);
                DraggableText.Item1.Pos = mousePos.ToVector2() - Pos;
                if (State.Mouse.LeftButton == ButtonState.Released)
                {
                    Rectangle obj = DraggableText.Item1.GetRectangle();
                    obj.Offset(Pos);
                    for (int i = 0; i < Words.Count; i++)
                    {
                        Rectangle word = Words[i].Rect;
                        word.Offset(Pos);
                        if (word.Intersects(obj) && (Words[i].textObject == null ? true : Words[i].textObject.Draggable) &&
                            i != DraggableText.Item2)
                        {
                            if (DraggableText.Item3)
                            {
                                DraggableText.Item1.Pos = Vector2.Zero;
                                if (Words[i].textObject != null)
                                {
                                    Words[i].textObject.Pos = Vector2.Zero;
                                }
                                Words[DraggableText.Item2].textObject = Words[i].textObject;
                                Words[i].textObject = DraggableText.Item1;
                            }
                            else
                            {
                                DraggableText.Item1.Pos = Vector2.Zero;
                                if (Words[i].textObject != null)
                                {
                                    Items.Add(Words[i].textObject);
                                    Words[i].textObject.Pos = Vector2.Zero;
                                }
                                Words[i].textObject = DraggableText.Item1;
                            }
                            DraggableText = null;
                            return;
                        }
                    }
                    Rectangle savedObjs = savedItems;
                    savedObjs.Offset(Pos);
                    if (savedObjs.Intersects(obj))
                    {
                        DraggableText.Item1.Pos = Vector2.Zero;
                    }
                    {
                        DraggableText.Item1.Pos = Vector2.Zero;
                        Items.Add(DraggableText.Item1);
                        DraggableText = null;
                        return;
                    }
                    if (DraggableText.Item3)
                    {
                        Words[DraggableText.Item2].textObject = DraggableText.Item1;
                    }
                    else
                    {
                        Items.Add(DraggableText.Item1);
                    }
                    DraggableText = null;
                }
            }
        }
コード例 #4
0
 public void Update(GameTime gameTime, StepState State)
 {
 }
コード例 #5
0
 public void Step(StepState state)
 {
     if (Alarm > 0)
     {
         Alarm--;
         if (Alarm == 0)
         {
             OnAlarm(state);
         }
     }
     if (Action == ACTIONS.WALK_LEFT)
     {
         Position += new Vector2(-1f / WALK_TIME, 0);
     }
     if (Action == ACTIONS.WALK_RIGHT)
     {
         Position += new Vector2(1f / WALK_TIME, 0);
     }
     if (Action == ACTIONS.STAND_LEFT)
     {
         if (Map[GridPosition + new Point(0, 2)] == Map.EMPTY)
         {
             Action = ACTIONS.FALL;
         }
         else if (state.Keyboard.IsKeyDown(Keys.A) && !Collision(GridPosition + new Point(-1, 0)))
         {
             Action = ACTIONS.WALK_LEFT;
             Alarm  = WALK_TIME;
             Hero.State.SetAnimation(0, "бег", true);
             Hero.Skeleton.FlipX = false;
         }
         else if (state.Keyboard.IsKeyDown(Keys.D) && !Collision(GridPosition + new Point(1, 0)))
         {
             Action = ACTIONS.WALK_RIGHT;
             Alarm  = WALK_TIME;
             Hero.State.SetAnimation(0, "бег", true);
             Hero.Skeleton.FlipX = true;
         }
         else if (state.Keyboard.IsKeyDown(Keys.S))
         {
             Point temp = GridPosition + new Point(0, 2);
             if (Map[temp] == Map.LEFT_SHELF ||
                 Map[temp] == Map.RIGHT_SHELF)
             {
                 Action = ACTIONS.GET_DOWN;
                 Alarm  = GET_DOWN_TIME;
             }
             else
             {
                 Action = ACTIONS.TO_SIT;
                 Alarm  = TO_SIT_TIME;
             }
         }
         else if (state.Keyboard.IsKeyDown(Keys.W))
         {
             Point temp = GridPosition + new Point(0, -2);
             if (Map[temp] == Map.LEFT_SHELF || Map[temp] == Map.RIGHT_SHELF)
             {
                 Action = ACTIONS.JUMP_ON;
                 uint  h = 2u;
                 float t = (float)Math.Sqrt(2f * h / GRAVITY);
                 VSpeed = -GRAVITY * t;
                 Alarm  = (uint)Math.Floor(t);
             }
         }
     }
     if (Action == ACTIONS.JUMP_ON)
     {
         Position += new Vector2(0, VSpeed);
         VSpeed   += GRAVITY;
     }
     if (Action == ACTIONS.GET_DOWN)
     {
         Position += new Vector2(0, 2f / GET_DOWN_TIME);
     }
     if (Action == ACTIONS.TO_SIT)
     {
         VSize -= (HEIGHT - SIT_HEIGHT) / TO_SIT_TIME;
     }
     if (Action == ACTIONS.SIT)
     {
         if (Map[GridPosition + new Point(0, 2)] == Map.EMPTY)
         {
             Action = ACTIONS.FALL;
         }
         else if (state.Keyboard.IsKeyDown(Keys.W) && !Collision(GridPosition))
         {
             Action = ACTIONS.FROM_SIT;
             Alarm  = FROM_SIT_TIME;
         }
         else if (state.Keyboard.IsKeyDown(Keys.A) && !Collision(GridPosition + new Point(-1, 1)))
         {
             Action = ACTIONS.SQUAT_LEFT;
             Alarm  = SQUAT_TIME;
         }
         else if (state.Keyboard.IsKeyDown(Keys.D) && !Collision(GridPosition + new Point(1, 1)))
         {
             Action = ACTIONS.SQUAT_RIGHT;
             Alarm  = SQUAT_TIME;
         }
     }
     if (Action == ACTIONS.HANG_DOWN)
     {
         if (state.Keyboard.IsKeyDown(Keys.S))
         {
             Action = ACTIONS.FALL;
         }
         else if (state.Keyboard.IsKeyDown(Keys.W))
         {
             Action = ACTIONS.GET_UP;
             Alarm  = GET_UP_TIME;
         }
     }
     if (Action == ACTIONS.GET_UP)
     {
         Position += new Vector2(0, -2f / GET_UP_TIME);
     }
     if (Action == ACTIONS.FALL)
     {
         VSpeed    = Math.Min(2, VSpeed + GRAVITY);
         Position += new Vector2(0f, VSpeed);
         if (Position.Y - GridPosition.Y > 1f)
         {
             Vector2 pos = Position;
             GridPosition += new Point(0, 1);
             if (Map[GridPosition + new Point(0, 2)] != Map.EMPTY)
             {
                 VSize  = HEIGHT;
                 Action = ACTIONS.STAND_LEFT;
                 VSpeed = 0f;
             }
             else
             {
                 Position = pos;
             }
         }
     }
     if (Action == ACTIONS.SQUAT_LEFT)
     {
         Position += new Vector2(-1f / SQUAT_TIME, 0);
     }
     if (Action == ACTIONS.SQUAT_RIGHT)
     {
         Position += new Vector2(1f / SQUAT_TIME, 0);
     }
     if (Action == ACTIONS.FROM_SIT)
     {
         VSize += (HEIGHT - SIT_HEIGHT) / FROM_SIT_TIME;
     }
     if (Hero != null)
     {
         Hero.pos = Position;
     }
 }