Example #1
0
        public void Move(GameTime gameTime, Boolean movingRight)
        {
            if (!(State is DeadMarioState) && !FlagPoleRiding)
            {
                //Velocity for movement change
                if (facingRight != movingRight && Math.Abs(Velocity.X) > 0)
                {
                    Velocity = facingRight ? new Vector2(Velocity.X - 2, Velocity.Y) : new Vector2(Velocity.X + 2, Velocity.Y);
                }
                facingRight = movingRight;

                elapsedTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                if ((Movement == MarioMovement.Moving || Movement == MarioMovement.Jumping) && Math.Abs(Velocity.X) < maxXVelocity && elapsedTime > movementInterval)
                {
                    Velocity    = facingRight ? new Vector2(Velocity.X + 1, Velocity.Y) : new Vector2(Velocity.X - 1, Velocity.Y);
                    elapsedTime = 0;
                }
                if (Movement != MarioMovement.Jumping)
                {
                    Movement  = MarioMovement.Moving;
                    lastMoved = 0;
                }

                State.Move();
            }
        }
Example #2
0
 public void FinishLevel()
 {
     Game1.Instance.EndLevel();
     //First run
     if (!FlagPoleRiding)
     {
         Location = new Vector2(Game1.Instance.Level.EndOfLevel.X, Location.Y);
         //If Mario is at the top of the pole, give a new life, otherwise give 500 points
         if (Location.Y <= Game1.Instance.Level.EndOfLevel.Y)
         {
             new OneUp(new Collision(Parent, null, CollisionSide.Default)).Execute();
         }
         else
         {
             new AquirePoints(Parent, GameConstants.FlagPoints).Execute();
         }
     }
     FlagPoleRiding = true;
     if (!Grounded)
     {
         State.FlagSlide();
         Velocity = new Vector2(0, 2);
     }
     else
     {
         Velocity = new Vector2(2, 0);
         State.Move();
     }
     if (Location.X > Game1.Instance.Level.CastleDoor)
     {
         Idle();
         Velocity = new Vector2(0, 0);
     }
     lastMoved = 0;
 }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        currentState.Move(box);
        currentState.TransitionCheck(box, target);

        //if (box.transform.position.x < target.transform.position.x && box.transform.position.x - target.transform.position.x > -nearDistance) {
        //    currentState = new NearLeftState();
        //    currentState.Move(box);
        //}
        //else if (box.transform.position.x < target.transform.position.x && box.transform.position.x - target.transform.position.x > -farDistance){
        //    currentState = new LeftState();
        //    currentState.Move(box);
        //}
        //else if (box.transform.position.x < target.transform.position.x && box.transform.position.x - target.transform.position.x < -farDistance)
        //{
        //    currentState = new FarLeftState();
        //    currentState.Move(box);
        //}
        //else if (box.transform.position.x > target.transform.position.x && box.transform.position.x - target.transform.position.x < nearDistance)
        //{
        //    currentState = new NearRightState();
        //    currentState.Move(box);
        //}
        //else if (box.transform.position.x > target.transform.position.x && box.transform.position.x - target.transform.position.x < farDistance)
        //{
        //    currentState = new RightState();
        //    currentState.Move(box);
        //}
        //else if (box.transform.position.x > target.transform.position.x && box.transform.position.x - target.transform.position.x > farDistance)
        //{
        //    currentState = new FarRightState();
        //    currentState.Move(box);
        //}
    }
Example #4
0
 private State Run(State state, int steps)
 {
     for (var i = 0; i < steps; i++)
     {
         state.Move();
         //Console.WriteLine(state);
     }
     return(state);
 }
        public OperationResult Move(Player player, string originalPosition, string newPosition)
        {
            if (player == null)
            {
                throw new ArgumentNullException();
            }

            return(State.Move(this, player, originalPosition, newPosition));
        }
Example #6
0
        private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            x = Convert.ToInt32((e.X - p.StagePos.X) / p.dpi);
            y = Convert.ToInt32((e.Y - p.StagePos.Y) / p.dpi);

            //hittest states
            hitState = stateList.FirstOrDefault(x => x.Bounds.Contains(new Point(this.x, this.y)));

            #region drag bezier handles
            if (dragState != null && e.Button == MouseButtons.Left)
            {
                //FLogger.Log(LogType.Debug, "bezierHandleStart");
                Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(p.bezierEdit.highlightTransition.startState.Bounds), State.Center(p.bezierEdit.highlightTransition.endState.Bounds), 40, 40, 0.0);
                if (dragState == "bezierStart")
                {
                    p.bezierEdit.highlightTransition.startBezierPoint = new Point(this.x - myEdgePoints.A.X, this.y - myEdgePoints.A.Y);
                }
                if (dragState == "bezierEnd")
                {
                    p.bezierEdit.highlightTransition.endBezierPoint = new Point(this.x - myEdgePoints.B.X, this.y - myEdgePoints.B.Y);
                }
            }
            #endregion

            #region drag states
            if (selectedState == null && e.Button == MouseButtons.Right)
            {
                Point mousePos = MousePosition;
                int   deltaX   = (mousePos.X - previousPosition.X);
                int   deltaY   = (mousePos.Y - previousPosition.Y);
                previousPosition = MousePosition;
                p.StagePos.X    += deltaX;
                p.StagePos.Y    += deltaY;
            }

            if (selectedState != null && e.Button == MouseButtons.Left && dragState == null)
            {
                selectedState.Move(new Point(Convert.ToInt32(e.X / p.dpi) - (p.StateSize / 2) - Convert.ToInt32(p.StagePos.X / p.dpi), Convert.ToInt32(e.Y / p.dpi) - (p.StateSize / 2) - Convert.ToInt32(p.StagePos.Y / p.dpi)));
            }

            #endregion

            #region startConnection

            if (startConnectionState != null && hitState != null)
            {
                targetConnectionState = hitState;
            }
            else
            {
                targetConnectionState = null;
            }
            #endregion

            this.Invalidate(); //redraw
        }
Example #7
0
        private int Distance(List <string> input)
        {
            var state = new State();

            foreach (var step in input)
            {
                state.Move(step);
            }

            return(state.Distance());
        }
Example #8
0
        /// <summary>
        /// List of possible successor states.
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        private Dictionary <int, State> Successors(State state)
        {
            Dictionary <int, State> succ = new Dictionary <int, State>(7);

            for (int i = 1; i <= 7; i++)
            {
                State s = state.Move(i);
                if (s != null)
                {
                    succ.Add(i, s);             // if move is valid add it to succ.
                }
            }
            return(succ);
        }
Example #9
0
    private void Update()
    {
        currentState.Run();

        if (Input.GetKeyDown(KeyCode.Space))
        {
            yunaAnim.SetTrigger("jump");
            currentState.Jump();
        }

        if (Input.GetKeyDown(KeyCode.A) | Input.GetKeyDown(KeyCode.D))
        {
            currentState.Move();
        }
    }
Example #10
0
    public StateMachine Move()
    {
        State nextState = currentState;

        while (true)
        {
            nextState = nextState.Move();
            if (nextState == null)
            {
                break;
            }

            currentState    = nextState;
            isStopAfterMove = true;
        }
        return(this);
    }
Example #11
0
        private (bool, int) Search(int bound)
        {
            CurrentState = States.Peek();
            State currentForChildren = CurrentState;

            ExploredCounter++;
            MaxDepth = CurrentState.DepthLevel > MaxDepth ? CurrentState.DepthLevel : MaxDepth;
            int heuristicFunction = HeuristicFunction(CurrentState);

            if (heuristicFunction > bound)
            {
                return(false, heuristicFunction);
            }
            if (CurrentState.IsSolved())
            {
                return(true, heuristicFunction);
            }
            int min = Int32.MaxValue;
            List <DirectionEnum> moves = CurrentState.GetAllowedMoves();

            foreach (var move in moves)
            {
                State state = new State(DimensionX, DimensionY, currentForChildren.Move(move), move, currentForChildren.DepthLevel + 1, currentForChildren);
                States.Push(state);
                Visited++;
                var result = Search(bound);
                if (result.Item1)
                {
                    return(true, heuristicFunction);
                }

                if (result.Item2 < min)
                {
                    min = result.Item2;
                }
                States.Pop();
            }

            return(false, min);
        }
Example #12
0
 private void BreedNewStates(State state)
 {
     for (int i = 0; i < state.ItemToFloor.Length; i++)
     {
         if (state.Elevator != state.ItemToFloor[i])
         {
             continue;
         }
         {
             var s = new State(state);
             s.Move(i, 1);
             _unvisited.Enqueue(s);
         }
         {
             var s = new State(state);
             s.Move(i, -1);
             _unvisited.Enqueue(s);
         }
         for (int j = i + 1; j < state.ItemToFloor.Length; j++)
         {
             if (state.Elevator != state.ItemToFloor[j])
             {
                 continue;
             }
             {
                 var s = new State(state);
                 s.Move(i, j, 1);
                 _unvisited.Enqueue(s);
             }
             {
                 var s = new State(state);
                 s.Move(i, j, -1);
                 _unvisited.Enqueue(s);
             }
         }
     }
 }
Example #13
0
 /// <summary>
 /// List of possible successor states.
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 private Dictionary<int, State> Successors(State state)
 {
     Dictionary<int, State> succ = new Dictionary<int, State>(7);
     for(int i = 1; i <= 7; i++)
     {
         State s = state.Move(i);
         if (s != null) succ.Add(i, s);  // if move is valid add it to succ.
     }
     return succ;
 }
Example #14
0
 public void Move()
 {
     State.Move();
 }
Example #15
0
 public void MakeMove(string move)
 {
     State.Move(this, move);
 }
 public void Update()
 {
     State.Move();
 }
Example #17
0
        private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            bool redraw = false;

            x = Convert.ToInt32((e.X - p.StagePos.X) / p.dpi);
            y = Convert.ToInt32((e.Y - p.StagePos.Y) / p.dpi);

            //hittest states
            hitState = stateList.FirstOrDefault(x => x.Bounds.Contains(new Point(this.x, this.y)));

            #region drag bezier handles
            if (dragState != null && e.Button == MouseButtons.Left)
            {
                //FLogger.Log(LogType.Debug, "bezierHandleStart");
                Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(p.bezierEdit.highlightTransition.startState.Bounds), State.Center(p.bezierEdit.highlightTransition.endState.Bounds), 40, 40, 0.0);
                if (dragState == "bezierStart")
                {
                    p.bezierEdit.highlightTransition.startBezierPoint = new Point(this.x - myEdgePoints.A.X, this.y - myEdgePoints.A.Y);
                }
                if (dragState == "bezierEnd")
                {
                    p.bezierEdit.highlightTransition.endBezierPoint = new Point(this.x - myEdgePoints.B.X, this.y - myEdgePoints.B.Y);
                }
                redraw = true;
            }
            #endregion

            #region drag things

            //drag stage
            if (selectedState == null && e.Button == MouseButtons.Right)
            {
                Point mousePos = MousePosition;
                int   deltaX   = (mousePos.X - previousPosition.X);
                int   deltaY   = (mousePos.Y - previousPosition.Y);
                previousPosition = MousePosition;
                p.StagePos.X    += deltaX;
                p.StagePos.Y    += deltaY;
                redraw           = true;
            }

            //drag state
            if (selectedState != null && Form.ModifierKeys != Keys.Control && e.Button == MouseButtons.Left && dragState == null)
            {
                selectedState.Move(new Point(Convert.ToInt32(e.X / p.dpi) - (p.StateSize / 2) - Convert.ToInt32(p.StagePos.X / p.dpi), Convert.ToInt32(e.Y / p.dpi) - (p.StateSize / 2) - Convert.ToInt32(p.StagePos.Y / p.dpi)));
                redraw = true;
            }

            //drag region
            if (selectedState == null && Form.ModifierKeys != Keys.Control && hitRegion != null && e.Button == MouseButtons.Left && hitsizeHandle == null && dragState == null)
            {
                Point mousePos = MousePosition;
                int   deltaX   = (mousePos.X - previousPosition.X);
                int   deltaY   = (mousePos.Y - previousPosition.Y);
                previousPosition     = MousePosition;
                hitRegion.Bounds     = new Rectangle(hitRegion.Bounds.X + deltaX, hitRegion.Bounds.Y + deltaY, hitRegion.Bounds.Width, hitRegion.Bounds.Height);
                hitRegion.SizeHandle = new Rectangle(hitRegion.SizeHandle.X + deltaX, hitRegion.SizeHandle.Y + deltaY, 10, 10);
                redraw = true;
            }

            //drag size

            if (e.Button == MouseButtons.Left && hitsizeHandle != null)
            {
                Point mousePos = MousePosition;
                int   deltaX   = (mousePos.X - previousPosition.X);
                int   deltaY   = (mousePos.Y - previousPosition.Y);
                previousPosition = MousePosition;


                int sizeX = hitsizeHandle.SizeHandle.X + deltaX;
                int sizeY = hitsizeHandle.SizeHandle.Y + deltaY;

                if ((sizeX - hitsizeHandle.Bounds.X + 10) < 100)
                {
                    sizeX = hitsizeHandle.Bounds.X + 90;
                }
                if ((sizeY - hitsizeHandle.Bounds.Y + 10) < 100)
                {
                    sizeY = hitsizeHandle.Bounds.Y + 90;
                }

                hitsizeHandle.SizeHandle = new Rectangle(sizeX, sizeY, 10, 10);
                hitsizeHandle.Bounds     = new Rectangle(hitsizeHandle.Bounds.X, hitsizeHandle.Bounds.Y, sizeX - hitsizeHandle.Bounds.X + 10, sizeY - hitsizeHandle.Bounds.Y + 10);
                redraw = true;
            }


            #endregion

            #region startConnection

            if (startConnectionState != null)
            {
                redraw = true;
            }

            if (startConnectionState != null && hitState != null)
            {
                targetConnectionState = hitState;
            }
            else
            {
                targetConnectionState = null;
            }
            #endregion

            SetSelectionRectangle(e);

            //redraw
            if (redraw)
            {
                this.Invalidate();
            }
        }
 public override void Move(Point offset)
 {
     State.Move(Shape, offset);
     NotifyUpdate();
 }
Example #19
0
 public void InputMove(Vector2 direction)
 {
     _state.Move(this, direction);
 }
 // Update is called once per frame
 void Update()
 {
     currentState.Move();
     currentState.Appearence();
     rigidbodyOfEnemy.velocity = transform.up * velocity;
 }
Example #21
0
        public void ManipulateUpdate(IManipulatable _target, IManipulatableParams mparams, Point location)
        {
            State target = _target as State;

            target.Move(location, (ManipulateParams)mparams);
        }
Example #22
0
 public void Move(Vector3 direction)
 {
     State.Move(direction);
 }
Example #23
0
 //�������� ������� ����������� �����
 protected override void StartSearch()
 {
     Started();
        /* if (!DoHaveResolve(_start))
             Progressing("������� �� �����. ������� �� ������");
         else*/
         {
             SearchIDA searchIDA = new SearchIDA();
             State state = new State();
             for (int i = 0; i < SearchBase.Dimension * SearchBase.Dimension; ++i)
             {
                 int value = _start[i];
                 value++;
                 if (value != SearchBase.Dimension * SearchBase.Dimension)
                     state.SetCell(i / SearchBase.Dimension, i % SearchBase.Dimension, value);
                 else
                     state.SetEmpty(i / SearchBase.Dimension, i % SearchBase.Dimension);
             }
             searchIDA._state.m_cells = (uint[,])state.m_cells.Clone();
             searchIDA._state.m_emptyX = state.m_emptyX;
             searchIDA._state.m_emptyY = state.m_emptyY;
             _countStates = 0;
             //����� ����� ������������ ����
             List<Move> solution = searchIDA.GetOptimalSolution();
             //�� �������� ����� ����������� �� ������� ������� � ���������
             solution.Reverse();
             arResult = new int[solution.Count + 1][];
             arResult[0] = _start;
             int arIndex = 1;
             foreach (Move m in solution)
             {
                 state.Move(m);
                 arResult[arIndex] = new int[SearchBase.Dimension * SearchBase.Dimension];
                 int j = 0;
                 for (int ii = 0; ii < SearchBase.Dimension; ii++)
                     for (int jj = 0; jj < SearchBase.Dimension; jj++, j++)
                     {
                         if (ii == state.m_emptyX &&
                             jj == state.m_emptyY)
                             arResult[arIndex][j] = SearchBase.Dimension * SearchBase.Dimension - 1;
                         else
                             arResult[arIndex][j] = (int)state.m_cells[ii, jj];// - 1;
                     }
                 arIndex++;
             }
             TimeSpan timeSearch = DateTime.Now - timeStart;
             if (arResult.Length - 1 != 0)
             {
                 int v=(arResult.Length - 1)%10;
                 string st = (v == 2 || v == 3 || v == 4) ? " ����" : ((v == 1) ? " ���" : " �����");
                 Progressing("����",
                     "�����. " + Environment.NewLine + (arResult.Length).ToString(CultureInfo.InvariantCulture) +
                     st+Environment.NewLine + "�����:" + timeSearch.ToString() +
                     Environment.NewLine + "\n����� ���-�� ������������� ���������\t: " +
                     _countStates.ToString(CultureInfo.InvariantCulture) +
                     Environment.NewLine + "\n**** ����� �������� ****" +
                     Environment.NewLine + "\n����� ������\t: " + timeSearch.ToString() +
                     Environment.NewLine + "\n���-�� ����� ��� ����� �������\t: " +
                     (arResult.Length ).ToString(CultureInfo.InvariantCulture) +
                     Environment.NewLine + "\n  �� ������ ������ ������ \n(��� Ctrl+P) � ��������� ������� ����������� �����.");
             }
             else
                 Progressing("� ��� � ������ ������ ?");
         }
         Finished();
 }