Esempio n. 1
0
        private bool DiractionNoValid(MovingDirection daraction, Cell cell)
        {
            int x = cell.X;
            int y = cell.Y;

            switch (daraction)
            {
                case MovingDirection.Up:
                    y--;
                    break;
                case MovingDirection.Right:
                    x++;
                    break;
                case MovingDirection.Down:
                    y++;
                    break;
                case  MovingDirection.Left:
                    x--;
                    break;

            }
            if(x>4||y>4||x<0||y<0)
                return true;

            return false;
        }
Esempio n. 2
0
 public virtual void MouseDown(MouseControllerEventArgs e)
 {
     flag             = 0;
     Buttonside       = e.Button;
     this.IsMouseDown = true;
     MoveDir          = MovingDirection.None;
     this.grid.CurrentCell.Deactivate();
     this.CurrentBaseRange = this.MouseDownRange = this.Gridmodel.SelectedCells;
 }
Esempio n. 3
0
        public async Task <string> Move(MovingDirection movingDirection)
        {
            if (_concurrentTcpServer.RobotIsConnected)
            {
                await _concurrentTcpServer.Move(movingDirection.Direction);

                return(movingDirection.Direction.ToString());
            }
            return("Robot is not connected");
        }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        if (isGameActive)
        {
            movingSpeed = 200.0f * (props.items[props.gewaehlterDocht.ToString()].schwierigkeit + props.items[props.gewaehlterWachs.ToString()].schwierigkeit);

            float maxBarWidth = barWidth - curWidth;

            //if (Input.GetKeyDown(KeyCode.R)) { ergebnis = ERGEBNISSE.KeinErgebnis; einkommen = 0; }

            if (Input.GetKeyDown(KeyCode.Space) && ergebnis == ERGEBNISSE.KeinErgebnis)
            {
                if (curPos >= superVon && curPos <= superBis)
                {
                    ergebnis = ERGEBNISSE.Super;
                }
                else if (curPos >= zielVon && curPos <= zielBis)
                {
                    ergebnis = ERGEBNISSE.Normal;
                }

                else
                {
                    ergebnis = ERGEBNISSE.Schlecht;
                }
                CalcErgebnis();
            }
            else if (ergebnis == ERGEBNISSE.KeinErgebnis)
            {
                if (curDirection == MovingDirection.Right)
                {
                    curPos = Mathf.Clamp(curPos + Time.deltaTime * movingSpeed, curPos, maxBarWidth);
                }
                else if (curDirection == MovingDirection.Left)
                {
                    curPos = Mathf.Clamp(curPos - Time.deltaTime * movingSpeed, 0, curPos);
                }

                if (curPos == maxBarWidth)
                {
                    curDirection = MovingDirection.Left;
                }
                else if (curPos == 0)
                {
                    curDirection = MovingDirection.Right;
                }
            }
            else if (Input.GetKeyDown(KeyCode.Space) && ergebnis != ERGEBNISSE.KeinErgebnis)
            {
                isGameActive = false;
                curPos       = 0;
                ergebnis     = ERGEBNISSE.KeinErgebnis;
            }
        }
    }
 public void ChangeMovingDirection()
 {
     if (currentMovingDirection == MovingDirection.Vertical)
     {
         currentMovingDirection = MovingDirection.Horizontal;
     }
     else
     {
         currentMovingDirection = MovingDirection.Vertical;
     }
 }
Esempio n. 6
0
 public Worm(Player player, Size size, Point start, MovingDirection direction) : base(Point.Empty, size)
 {
     Players.Add(player);
     StartLocation = start;
     Direction     = StartDirection = direction;
     Body          = new List <Point>()
     {
         StartLocation
     };
     Grow = 2;
 }
 public void MouseDown(MouseControllerEventArgs e)
 {
     isMouseDown    = true;
     mouseDownRange = Grid.Model.SelectedCells;
     mouseDownPoint = e.Location;
     moveDir        = MovingDirection.None;
     flag           = 0;
     if (e.Button == MouseButton.Left)
     {
         this.currentValue = this.Grid.CurrentCell.Renderer.ControlValue;
     }
 }
        public void MouseUp(MouseControllerEventArgs e)
        {
            //throw new NotImplementedException();
            if (mouseDownRange != Grid.Model.SelectedCells && ExcelRangeExtended != null)
            {
                this.FillDraggedRanges();
                ExcelRangeExtendedEventArgs arg = new ExcelRangeExtendedEventArgs(mouseDownRange, Grid.Model.SelectedCells);
                ExcelRangeExtended(Grid, arg);
            }

            moveDir = MovingDirection.None;
            Grid.InvalidateCells();
        }
Esempio n. 9
0
        public SteeringStep WithDirection(MovingDirection direction, bool value)
        {
            if (value)
            {
                Direction |= direction;
            }
            else
            {
                Direction &= ~direction;
            }

            return(this);
        }
        public static void SwitchMovingAnimationState(MovingDirection mdir, Animator animator)
        {
            switch (mdir)
            {
            case MovingDirection.Up:
            {
                animator.SetBool("ToGoUp", true);
                animator.SetBool("ToGoDown", false);
                animator.SetBool("ToGoLeft", false);
                animator.SetBool("ToGoRight", false);
            }
            break;

            case MovingDirection.Down:
            {
                animator.SetBool("ToGoUp", false);
                animator.SetBool("ToGoDown", true);
                animator.SetBool("ToGoLeft", false);
                animator.SetBool("ToGoRight", false);
            }
            break;

            case MovingDirection.Right:
            {
                animator.SetBool("ToGoUp", false);
                animator.SetBool("ToGoDown", false);
                animator.SetBool("ToGoLeft", false);
                animator.SetBool("ToGoRight", true);
            }
            break;

            case MovingDirection.Left:
            {
                animator.SetBool("ToGoUp", false);
                animator.SetBool("ToGoDown", false);
                animator.SetBool("ToGoLeft", true);
                animator.SetBool("ToGoRight", false);
            }
            break;

            case MovingDirection.Default:
            {
                animator.SetBool("ToGoUp", false);
                animator.SetBool("ToGoDown", false);
                animator.SetBool("ToGoLeft", false);
                animator.SetBool("ToGoRight", false);
            }
            break;
            }
        }
    public static void activateCheckpoint(GameObject checkpoint, MovingDirection direction)
    {
        if (latestActivatedCheckpoint != null && latestActivatedCheckpoint.Item1 != checkpoint)
        {
            var indicator = latestActivatedCheckpoint.Item1.GetComponentInChildren <Animator>();
            if (indicator != null)
            {
                indicator.ResetTrigger("Activate");
                indicator.SetTrigger("Deactivate");
            }
        }

        latestActivatedCheckpoint = Tuple.Create(checkpoint, direction);
    }
Esempio n. 12
0
            public void Move()
            {
                if (Invaders.Count == 0)
                {
                    return;
                }

                if (UpdateTimer.Passed)
                {
                    // calculate moving distance and direction
                    var distance = new Size(0, 0);
                    var lowest   = Invaders.Max(i => i.Location.Y + i.Size.Height);
                    switch (Direction)
                    {
                    case MovingDirection.Left:
                        var leftmost = Invaders.Min(i => i.Location.X);
                        if (leftmost == 0)
                        {
                            Direction       = MovingDirection.Right;
                            distance.Width  = +1;
                            distance.Height = lowest < Range.Height ? 1 : 0;
                        }
                        else
                        {
                            distance.Width = -1;
                        }
                        break;

                    case MovingDirection.Right:
                        var righttmost = Invaders.Max(i => i.Location.X + i.Size.Width);
                        if (righttmost == Range.Width)
                        {
                            Direction       = MovingDirection.Left;
                            distance.Width  = -1;
                            distance.Height = lowest < Range.Height ? 1 : 0;
                        }
                        else
                        {
                            distance.Width = +1;
                        }
                        break;
                    }
                    foreach (var invader in Invaders)
                    {
                        invader.Move(distance);
                    }

                    UpdateTimer.Reset();
                }
            }
Esempio n. 13
0
 private void CheckMovingDirection()
 {
     if (CurrentSpeed > 0 && CurrentMovingDirection != MovingDirection.Forward)
     {
         CurrentMovingDirection = MovingDirection.Forward;
     }
     else if (CurrentSpeed < 0 && CurrentMovingDirection != MovingDirection.Backward)
     {
         CurrentMovingDirection = MovingDirection.Backward;
     }
     else if (CurrentSpeed == 0 && CurrentMovingDirection != MovingDirection.NotMoving)
     {
         CurrentMovingDirection = MovingDirection.NotMoving;
     }
 }
Esempio n. 14
0
 public Character(string name, Class clss)
 {
     Name                   = name;
     Class                  = clss;
     CurrentHealth          = clss.Health;
     CurrentResource        = clss.Resource;
     Orientation            = Orientation.Down;
     CreatedAt              = DateTime.Now;
     EditedAt               = DateTime.Now;
     Size                   = 10;
     CoordX                 = 150;
     CoordY                 = 150;
     IsDead                 = false;
     BoundingBox            = new AABB(CoordX, CoordY, Size);
     this.movementDirection = MovingDirection.Stop;
 }
Esempio n. 15
0
        private void UpdateDirection()
        {
            Direction = new Vector2(path[0].X + TileMap.TILE_SIZE / 2, path[0].Y + TileMap.TILE_SIZE / 2) - new Vector2(PlayerRectangle2.X, PlayerRectangle2.Y);
            Direction.Normalize();

            if (FAbs(Direction.X) - FAbs(Direction.Y) > 0.25f)
            {
                if (Direction.X < 0)
                {
                    currentMovingDirection = MovingDirection.Left;
                }
                else
                {
                    currentMovingDirection = MovingDirection.Right;
                }
            }
            else if (FAbs(Direction.X) - FAbs(Direction.Y) < -0.25f)
            {
                if (Direction.Y < 0)
                {
                    currentMovingDirection = MovingDirection.Up;
                }
                else
                {
                    currentMovingDirection = MovingDirection.Down;
                }
            }
            else
            {
                if (Direction.X < 0 && Direction.Y < 0)
                {
                    currentMovingDirection = MovingDirection.LeftUp;
                }
                else if (Direction.X > 0 && Direction.Y < 0)
                {
                    currentMovingDirection = MovingDirection.RightUp;
                }
                else if (Direction.X < 0 && Direction.Y > 0)
                {
                    currentMovingDirection = MovingDirection.LeftDown;
                }
                else if (Direction.X > 0 && Direction.Y > 0)
                {
                    currentMovingDirection = MovingDirection.RightDown;
                }
            }
        }
        public bool MoveProductionLine(MovingDirection movingDirection)
        {
            switch (movingDirection)
            {
                case MovingDirection.Forward:
                    Console.WriteLine("Production Moved Forward");
                    break;
                case MovingDirection.ToScran:
                    Console.WriteLine("Production Moved To Scran");
                    break;
                case MovingDirection.Back:
                    Console.WriteLine("Production Moved Back");
                    break;
            }

            return true;
        }
Esempio n. 17
0
 //public void onKeyPress(object o, KeyPressEventArgs args)
 public void onKeyPress(Sdl.SDL_keysym keysym)
 {
     switch(keysym.sym)
     {
         case Sdl.SDLK_RETURN:
             this.m_shouldStart = true;
             break;
         case Sdl.SDLK_e:
             this.m_usePotion = true;
             break;
         case Sdl.SDLK_q:
             this.m_dropItem = true;
             break;
         case Sdl.SDLK_SPACE:
             this.m_useAutoAttack = true;
             break;
         case Sdl.SDLK_g:
             this.m_lootItem = true;
             break;
         case Sdl.SDLK_w:
             this.m_currentMoveDirection = MovingDirection.UP;
             if(!this.m_moveKeys.Contains(keysym.sym))
                 this.m_moveKeys.Add(keysym.sym);
             break;
         case Sdl.SDLK_a:
             this.m_currentMoveDirection = MovingDirection.LEFT;
             if(!this.m_moveKeys.Contains(keysym.sym))
                 this.m_moveKeys.Add(keysym.sym);
             break;
         case Sdl.SDLK_s:
             this.m_currentMoveDirection = MovingDirection.DOWN;
             if(!this.m_moveKeys.Contains(keysym.sym))
                 this.m_moveKeys.Add(keysym.sym);
             break;
         case Sdl.SDLK_d:
             this.m_currentMoveDirection = MovingDirection.RIGHT;
             if(!this.m_moveKeys.Contains(keysym.sym))
                 this.m_moveKeys.Add(keysym.sym);
             break;
         default:
             break;
     }
     if(keysym.mod == Sdl.SDLK_LSHIFT)
         this.m_useSpecial = true;
 }
Esempio n. 18
0
    public static Vector2 ToVector(this MovingDirection direction)
    {
        switch (direction)
        {
        case MovingDirection.Up:
            return(Vector2.up);

        case MovingDirection.Right:
            return(Vector2.right);

        case MovingDirection.Down:
            return(Vector2.down);

        case MovingDirection.Left:
            return(Vector2.left);
        }
        return(Vector2.down);
    }
Esempio n. 19
0
    /// <summary>
    /// Initializes the game
    /// </summary>
    public void InIt()
    {
        allBodyPartMovemetScripts = new List <BodyPartMovemet>();
        allBodyParts = new List <GameObject>();
        //Stores Last update time as current time
        lastUpdateTime          = Time.time;
        lastDirectionUpdateTime = Time.time;
        //Calculating initial pos
        Vector3 initialTailPos = advancedSettings.initialTailPos;

        initialTailPos.x += (advancedSettings.size * (advancedSettings.length - 1));

        //Create head part first
        m_snakeHeadPart = Instantiate(snakeHeadPrefab, transform);
        m_snakeHeadPart.transform.localPosition = initialTailPos;
        m_headMovementScript = m_snakeHeadPart.GetComponent <BodyPartMovemet>();
        allBodyPartMovemetScripts.Add(m_headMovementScript);
        allBodyParts.Add(m_snakeHeadPart);
        m_headPos = m_snakeHeadPart.transform.localPosition;

        initialTailPos.x = initialTailPos.x - advancedSettings.size;
        //Create Snake Body part
        for (int i = 0; i < advancedSettings.length - 2; i++)
        {
            GameObject snakeBodyPart = Instantiate(snakeBodyPrefab, transform);
            snakeBodyPart.transform.localPosition = initialTailPos;
            initialTailPos.x = initialTailPos.x - advancedSettings.size;
            allBodyPartMovemetScripts.Add(snakeBodyPart.GetComponent <BodyPartMovemet>());
            allBodyParts.Add(snakeBodyPart);
        }

        //Create snake tail part
        m_snakeTailPart = Instantiate(snakeTailPrefab, transform);
        m_snakeTailPart.transform.localPosition = initialTailPos;
        initialTailPos.x = initialTailPos.x - advancedSettings.size;
        allBodyPartMovemetScripts.Add(m_snakeTailPart.GetComponent <BodyPartMovemet>());
        allBodyParts.Add(m_snakeTailPart);

        AssignScriptReferenceToEachPart();
        InvokeRepeating("ShowNewApple", 0, 3);
        Direction = MovingDirection.right;
        gameOver  = false;
    }
Esempio n. 20
0
    // Update is called once per frame
    void Update()
    {
        var deltaDistance = Time.deltaTime * HorizontalSpeed * (int)_movingDirection;

        _movedDistance += deltaDistance;

        if (_movingDirection == MovingDirection.Right && _movedDistance >= HorizontalDistance)
        {
            //zu weit, umdrehen!
            _movingDirection = MovingDirection.Left;
        }
        if (_movingDirection == MovingDirection.Left && _movedDistance <= 0)
        {
            //zu weit, umdrehen!
            _movingDirection = MovingDirection.Right;
        }

        transform.Translate(deltaDistance, 0, 0);
    }
        private void SwitchMovingState(MovingDirection movingDirection)
        {
            switch (movingDirection)
            {
            case MovingDirection.ToEnd:
                SetDesiredVelocity(endPosition);
                break;

            case MovingDirection.ToStart:
                SetDesiredVelocity(startPosition);
                break;

            case MovingDirection.Disabled:
                SetDesiredVelocity(Vector3.zero);
                break;
            }

            currentDirection = movingDirection;
        }
Esempio n. 22
0
 void Update()
 {
     if (activeDirection == MovingDirection.LEFT)
     {
         gameObject.transform.Translate(Vector3.forward * Time.deltaTime * speed);
         if (gameObject.transform.position.z >= 0)
         {
             activeDirection = MovingDirection.RIGHT;
         }
     }
     else
     {
         gameObject.transform.Translate(Vector3.back * Time.deltaTime * speed);
         if (gameObject.transform.position.z <= -31)
         {
             activeDirection = MovingDirection.LEFT;
         }
     }
 }
Esempio n. 23
0
 public void ChangeSpeedBy(MovingDirection d, int absSpeed)
 {
     if (d == MovingDirection.Up)
     {
         SpeedY -= absSpeed;
     }
     if (d == MovingDirection.Down)
     {
         SpeedY += absSpeed;
     }
     if (d == MovingDirection.Left)
     {
         SpeedX -= absSpeed;
     }
     if (d == MovingDirection.Right)
     {
         SpeedX += absSpeed;
     }
 }
Esempio n. 24
0
        private void OnButtonKeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Down:
                if (previousDirection != MovingDirection.Up)
                {
                    nextDirection = MovingDirection.Down;
                }
                break;

            case Key.Up:
                if (previousDirection != MovingDirection.Down)
                {
                    nextDirection = MovingDirection.Up;
                }
                break;

            case Key.Left:
                if (previousDirection != MovingDirection.Right)
                {
                    nextDirection = MovingDirection.Left;
                }
                break;

            case Key.Right:
                if (previousDirection != MovingDirection.Left)
                {
                    nextDirection = MovingDirection.Right;
                }
                break;

            case Key.Escape:
                _timer.Stop();
                this.Close();
                break;
            }
            if (direction == 0)
            {
                direction = nextDirection;
            }
        }
Esempio n. 25
0
        public void SetRandomDirection()
        {
            Random r = new Random();

            if (r.NextDouble() > 0.2)
            {
                return;
            }

            switch (r.Next(0, 5))
            {
            case 0:
                this.BoundingBox.VelocityX = 0;
                this.BoundingBox.VelocityY = -1;
                this.movementDirection     = MovingDirection.Top;
                break;

            case 1:
                this.BoundingBox.VelocityX = 1;
                this.BoundingBox.VelocityY = 0;
                this.movementDirection     = MovingDirection.Right;
                break;

            case 2:
                this.BoundingBox.VelocityX = 0;
                this.BoundingBox.VelocityY = 1;
                this.movementDirection     = MovingDirection.Down;
                break;

            case 3:
                this.BoundingBox.VelocityX = -1;
                this.BoundingBox.VelocityY = 0;
                this.movementDirection     = MovingDirection.Left;
                break;

            case 4:
                this.BoundingBox.VelocityX = 0;
                this.BoundingBox.VelocityY = 0;
                this.movementDirection     = MovingDirection.Stop;
                break;
            }
        }
Esempio n. 26
0
        public override bool OnNewFrame()
        {
            PXCMGesture gesture = QueryGesture();

            PXCMGesture.GeoNode ndata;
            pxcmStatus          sts = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out ndata);

            if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                _lastDirection = _DetectGesture(ndata.positionImage.x, ndata.positionImage.y);
                if (_lastDirection != MovingDirection.Undefined)
                {
                    _sender.UpdateGesture(_lastDirection);
                }

                //Console.WriteLine("node HAND_MIDDLE ({0},{1})", ndata.positionImage.x, ndata.positionImage.y);
            }

            return(++_nframes < 50000);
        }
Esempio n. 27
0
    /// <summary>
    /// This will take input from button controller
    /// </summary>
    /// <param name="buttonType"></param>
    internal void OnButtonClicked(AllButtonTypes buttonType)
    {
        if (gameOver)
        {
            OnRestartButtonPressed();
            return;
        }

        if (Time.time <= (lastDirectionUpdateTime + advancedSettings.nextMoveTime))
        {
            return;
        }

        //Handle inputs
        if (buttonType == AllButtonTypes.turnLeft_button)
        {
            switch (Direction)
            {
            case MovingDirection.right: Direction = MovingDirection.up; break;

            case MovingDirection.left: Direction = MovingDirection.down; break;

            case MovingDirection.up: Direction = MovingDirection.left; break;

            case MovingDirection.down: Direction = MovingDirection.right; break;
            }
        }
        else if (buttonType == AllButtonTypes.turnRight_button)
        {
            switch (Direction)
            {
            case MovingDirection.right: Direction = MovingDirection.down; break;

            case MovingDirection.left: Direction = MovingDirection.up; break;

            case MovingDirection.up: Direction = MovingDirection.right; break;

            case MovingDirection.down: Direction = MovingDirection.left; break;
            }
        }
    }
Esempio n. 28
0
    private void FixedUpdate()
    {
        Vector3 position = _rigidbody.position;

        Vector3Int cellPosition = _tilemap.WorldToCell(position);
        int        xd           = _movingDirection == MovingDirection.Left ? -1 : 1;

        if (cellPosition != _prevCellPosition)
        {
            var tile = _tilemap.GetTile(cellPosition);
            if (tile == _recycleTile)
            {
                if (didHidRecycleTileEvent != null)
                {
                    didHidRecycleTileEvent();
                }
            }

            var targetCellPosition = FindNewTargetPosition(cellPosition, xd);
            if (targetCellPosition.x < cellPosition.x)
            {
                _movingDirection = MovingDirection.Left;
            }
            else if (targetCellPosition.x > cellPosition.x)
            {
                _movingDirection = MovingDirection.Right;
            }
            _destination      = _tilemap.CellToWorld(targetCellPosition) + _tilemap.cellSize * 0.5f;
            _prevCellPosition = cellPosition;
        }

        _velocity += (_destination - (Vector2)position) * _movementElasticity * Time.fixedDeltaTime;
        _velocity *= _movementFriction;
        var sqrMagnitude = _velocity.sqrMagnitude;

        if (_velocity.sqrMagnitude > _maxVelocity * _maxVelocity)
        {
            _velocity = _maxVelocity * _velocity / Mathf.Sqrt(sqrMagnitude);
        }
        _rigidbody.MovePosition(position + (Vector3)_velocity * Time.fixedDeltaTime * _movementStrength);
    }
Esempio n. 29
0
        public Cell GetCell(int x, int y, MovingDirection direction)
        {
            Cell cell = null;

            switch (direction)
            {
                case MovingDirection.Up:
                    cell = _fildCells[x, --y];
                    break;
                case MovingDirection.Down:
                    cell = _fildCells[x, ++y];
                    break;
                case MovingDirection.Left:
                    cell = _fildCells[--x, y];
                    break;
                case MovingDirection.Right:
                    cell = _fildCells[++x, y];
                    break;
            }
            return cell;
        }
        public static void Move(MovingDirection direction, Position position)
        {
            switch (direction)
            {
            case MovingDirection.Up:
                position.CurY--;
                break;

            case MovingDirection.Down:
                position.CurY++;
                break;

            case MovingDirection.Left:
                position.CurX--;
                break;

            case MovingDirection.Right:
                position.CurX++;
                break;
            }
        }
Esempio n. 31
0
    IEnumerator PerformTurn(MovingDirection targetDirection)
    {
        isTurnLocked = true;

        direction = targetDirection;

        SetAnimatorOn(direction);

        yield return(wait);

        yield return(wait);

        MovingDirection nextDirection = FindNextDirection(direction);

        while (IsDirectionAvailable(nextDirection))
        {
            yield return(null);
        }

        isTurnLocked = false;
    }
Esempio n. 32
0
    void SetAnimatorOn(MovingDirection curDirection)
    {
        switch (curDirection)
        {
        case MovingDirection.Down:
            animator.SetTrigger("Down");
            break;

        case MovingDirection.Left:
            animator.SetTrigger("Left");
            break;

        case MovingDirection.Up:
            animator.SetTrigger("Up");
            break;

        case MovingDirection.Right:
            animator.SetTrigger("Right");
            break;
        }
    }
Esempio n. 33
0
 public void MovePlayer(MovingDirection direction, GameObject whoIsMoving)
 {
     if (_canMove)
     {
         if (anotherMovement == false)
         {
             if (whoIsMoving.CompareTag("Player1") && _frontCanMove)
             {
                 MovingLogic1(direction, whoIsMoving);
             }
             else if (whoIsMoving.CompareTag("Player2") && _backCanMove)
             {
                 MovingLogic1(direction, whoIsMoving);
             }
         }
         else
         {
             MovingLogic2(direction, whoIsMoving);
         }
     }
 }
        public override IState Update()
        {
            // Move
            Vector3 dir = MovementHelper.GetMovement();

            if (dir.magnitude >= param.chara.thresMove)
            {
                dir = MovementHelper.NormalizeAndScaleMovementByTime(dir);

                MovingDirection mdirCur = MovementHelper.GetMovingDirection(dir);
                if (mdirCur != mdirLast)
                {
                    Character.SwitchMovingAnimationState(mdirCur, param.animator);
                    mdirLast = mdirCur;
                }
                param.chara.controller.Move(dir);
            }
            else
            {
                return(new StateCharaIdle(param)); // StateCharaIdle
            }

            // Shoot
            if (Input.GetMouseButtonDown(0))
            {
                if (param.chara.shooter.MarkInstance == null)
                {
                    Vector3 posMouse = Input.mousePosition;
                    Vector3 posW     = Camera.main.ScreenToWorldPoint(posMouse);
                    posW.z = 0;

                    param.chara.shooter.Deploy(posW);

                    return(new StateCharaMovingDeploying(param)); // StateCharaMovingDeploying
                }
            }

            return(null);
        }
Esempio n. 35
0
        public void Update(GameTime theGameTime, KeyboardState currentKeyboardState, KeyboardState oldKeyboardState, 
                           List<Tile> tiles, MouseState mouseState, MouseState oldMouseState, Camera camera)
        {
            Vector2 destination = Vector2.Zero;

            if(mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton != ButtonState.Pressed)
            {
                 destination = new Vector2(mouseState.X + camera.Origin.X, mouseState.Y + camera.Origin.Y);
            }

            if (destination != Vector2.Zero)
            {
                Tile start = tiles.Where(tile => tile.TileRectangle.Intersects(PlayerRectangle2)).ToList()[0];
                Tile des = tiles.Where(tile => tile.TileRectangle.Intersects(new Rectangle((int)destination.X, (int)destination.Y, 2, 2))).ToList()[0];

                if (des.TileType != 1) return;

                path = PathFinder.FindPath(start, des, tiles.Where(tile => tile.TileType == 1).ToList());
            }

            if(path.Count > 0)
            {
                UpdateMovement(path, theGameTime);
            }

            oldMovingDirection = currentMovingDirection;
        }
Esempio n. 36
0
        public virtual void move(Point inNewPosition)
        {
            if (inNewPosition.X == getPosition().X && inNewPosition.Y == getPosition().Y)
                return;

            if (inNewPosition.X > m_position.X) m_viewingDirection = MovingDirection.RIGHT;
            else if (inNewPosition.X < m_position.X) m_viewingDirection = MovingDirection.LEFT;
            else if (inNewPosition.Y > m_position.Y) m_viewingDirection = MovingDirection.DOWN;
            else if (inNewPosition.Y < m_position.Y) m_viewingDirection = MovingDirection.UP;

            m_position = inNewPosition;
            m_moveTick = m_moveSpeed;
        }
Esempio n. 37
0
 public void setViewingDirection(MovingDirection inDirection)
 {
     this.m_viewingDirection = inDirection;
 }
Esempio n. 38
0
 //public void onKeyRelease(object o, KeyReleaseEventArgs args)
 public void onKeyRelease(Sdl.SDL_keysym keysym)
 {
     switch(keysym.sym)
     {
         case Sdl.SDLK_w:
             if(this.m_moveKeys.Contains(Sdl.SDLK_s))
                 this.m_currentMoveDirection = MovingDirection.DOWN;
             else if(this.m_moveKeys.Contains(Sdl.SDLK_a))
                 this.m_currentMoveDirection = MovingDirection.LEFT;
             else if(this.m_moveKeys.Contains(Sdl.SDLK_d))
                 this.m_currentMoveDirection = MovingDirection.RIGHT;
             else
                 this.m_currentMoveDirection = MovingDirection.NONE;
             break;
         case Sdl.SDLK_a:
             if(this.m_moveKeys.Contains(Sdl.SDLK_d))
                 this.m_currentMoveDirection = MovingDirection.DOWN;
             else if(this.m_moveKeys.Contains(Sdl.SDLK_w))
                 this.m_currentMoveDirection = MovingDirection.UP;
             else if(this.m_moveKeys.Contains(Sdl.SDLK_d))
                 this.m_currentMoveDirection = MovingDirection.RIGHT;
             else
                 this.m_currentMoveDirection = MovingDirection.NONE;
             break;
         case Sdl.SDLK_s:
             if(this.m_moveKeys.Contains(Sdl.SDLK_w))
                 this.m_currentMoveDirection = MovingDirection.UP;
             else if(this.m_moveKeys.Contains(Sdl.SDLK_a))
                 this.m_currentMoveDirection = MovingDirection.LEFT;
             else if(this.m_moveKeys.Contains(Sdl.SDLK_d))
                 this.m_currentMoveDirection = MovingDirection.RIGHT;
             else
                 this.m_currentMoveDirection = MovingDirection.NONE;
             break;
         case Sdl.SDLK_d:
             if(this.m_moveKeys.Contains(Sdl.SDLK_s))
                 this.m_currentMoveDirection = MovingDirection.DOWN;
             else if(this.m_moveKeys.Contains(Sdl.SDLK_a))
                 this.m_currentMoveDirection = MovingDirection.LEFT;
             else if(this.m_moveKeys.Contains(Sdl.SDLK_w))
                 this.m_currentMoveDirection = MovingDirection.UP;
             else
                 this.m_currentMoveDirection = MovingDirection.NONE;
             break;
         default:
             return;
     }
     this.m_moveKeys.Remove(keysym.sym);
 }
Esempio n. 39
0
 public Bullet(Entity inShooter, MovingDirection inDirection, Point inPosition)
 {
     this.m_shooter = inShooter;
     this.m_movingDirection = inDirection;
     this.m_position = inPosition;
 }
Esempio n. 40
0
 public StickArm(Entity inShooter, MovingDirection inDirection, Point inPosition)
     : base(inShooter, inDirection, inPosition)
 {
     m_speed = 1;
 }
Esempio n. 41
0
 private void OnPlayerInput(MovingDirection direction)
 {
     if ((direction == MovingDirection.Forward && !_isFacingForward) ||
         (direction == MovingDirection.Backward && _isFacingForward))
     {
         Flip();
     }
     _direction = direction;
 }
    void Move()
    {
        if ((!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.LeftArrow))){
            foreach (MovingDirection dir in previousMovingDirections){
                if (dir == MovingDirection.Left){
                    previousMovingDirections.Remove(dir);
                    break;
                }
            }

            if (movingDirection == MovingDirection.Left)
                movingDirection = MovingDirection.None;
        }
        if ((!Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.RightArrow))){
            foreach (MovingDirection dir in previousMovingDirections){
                if (dir == MovingDirection.Right){
                    previousMovingDirections.Remove(dir);
                    break;
                }
            }

            if (movingDirection == MovingDirection.Right)
                movingDirection = MovingDirection.None;
        }
        if ((!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.UpArrow))){
            foreach (MovingDirection dir in previousMovingDirections){
                if (dir == MovingDirection.Up){
                    previousMovingDirections.Remove(dir);
                    break;
                }
            }

            if (movingDirection == MovingDirection.Up)
                movingDirection = MovingDirection.None;
        }
        if ((!Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.DownArrow))){
            foreach (MovingDirection dir in previousMovingDirections){
                if (dir == MovingDirection.Down){
                    previousMovingDirections.Remove(dir);
                    break;
                }
            }

            if (movingDirection == MovingDirection.Down)
                movingDirection = MovingDirection.None;
        }

        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)){
            if (movingDirection != MovingDirection.None)
                previousMovingDirections.Add(movingDirection);
            movingDirection = MovingDirection.Left;
        }
        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)){
            if (movingDirection != MovingDirection.None)
                previousMovingDirections.Add(movingDirection);
            movingDirection = MovingDirection.Right;
        }
        if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)){
            if (movingDirection != MovingDirection.None)
                previousMovingDirections.Add(movingDirection);
            movingDirection = MovingDirection.Up;
        }
        if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)){
            if (movingDirection != MovingDirection.None)
                previousMovingDirections.Add(movingDirection);
            movingDirection = MovingDirection.Down;
        }
        //if a key has not just been pressed but is still being held down
        if (movingDirection == MovingDirection.None){
            //if there are previousMovingDirections
            if (previousMovingDirections.Count > 0){
                if (previousMovingDirections[previousMovingDirections.Count-1] == MovingDirection.Left){
                    if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)){
                        movingDirection = MovingDirection.Left;
                        previousMovingDirections.RemoveAt(previousMovingDirections.Count-1);
                    }
                }
                else if (previousMovingDirections[previousMovingDirections.Count-1] == MovingDirection.Right){
                    if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)){
                        movingDirection = MovingDirection.Right;
                        previousMovingDirections.RemoveAt(previousMovingDirections.Count-1);
                    }
                }
                else if (previousMovingDirections[previousMovingDirections.Count-1] == MovingDirection.Up){
                    if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)){
                        movingDirection = MovingDirection.Up;
                        previousMovingDirections.RemoveAt(previousMovingDirections.Count-1);
                    }
                }
                else if (previousMovingDirections[previousMovingDirections.Count-1] == MovingDirection.Down){
                    if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)){
                        movingDirection = MovingDirection.Down;
                        previousMovingDirections.RemoveAt(previousMovingDirections.Count-1);
                    }
                }
                //else just move if you need to
            }else{
                if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)){
                    if (movingDirection != MovingDirection.None)
                        previousMovingDirections.Add(movingDirection);
                    movingDirection = MovingDirection.Left;
                }
                if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)){
                    if (movingDirection != MovingDirection.None)
                        previousMovingDirections.Add(movingDirection);
                    movingDirection = MovingDirection.Right;
                }
                if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)){
                    if (movingDirection != MovingDirection.None)
                        previousMovingDirections.Add(movingDirection);
                    movingDirection = MovingDirection.Up;
                }
                if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)){
                    if (movingDirection != MovingDirection.None)
                        previousMovingDirections.Add(movingDirection);
                    movingDirection = MovingDirection.Down;
                }
            }
        }

        if (movingDirection == MovingDirection.Left){
            if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)){
                transform.rotation = Quaternion.Euler(0,0,90);
                transform.position = transform.position + (transform.up * Speed);
            }
        }
        if (movingDirection == MovingDirection.Right){
            if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)){
                transform.rotation = Quaternion.Euler(0,0,270);
                transform.position = transform.position + (transform.up * Speed);
            }
        }
        if (movingDirection == MovingDirection.Up){
            if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)){
                transform.rotation = Quaternion.Euler(0,0,0);
                transform.position = transform.position + (transform.up * Speed);
            }
        }
        if (movingDirection == MovingDirection.Down){
            if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)){
                transform.rotation = Quaternion.Euler(0,0,180);
                transform.position = transform.position + (transform.up * Speed);
            }
        }

        if (movingDirection == MovingDirection.Left){
            Moving = true;
            MoveDirection = 0;
        }
        if (movingDirection == MovingDirection.Up){
            Moving = true;
            MoveDirection = 1;
        }
        if (movingDirection == MovingDirection.Right){
            Moving = true;
            MoveDirection = 2;
        }
        if (movingDirection == MovingDirection.Down){
            Moving = true;
            MoveDirection = 3;
        }
        if (movingDirection == MovingDirection.None){
            Moving = false;
        }
    }
Esempio n. 43
0
        private void UpdateDirection()
        {
            Direction = new Vector2(path[0].X + TileMap.TILE_SIZE / 2, path[0].Y + TileMap.TILE_SIZE / 2) - new Vector2(PlayerRectangle2.X, PlayerRectangle2.Y);
            Direction.Normalize();

            if (FAbs(Direction.X) - FAbs(Direction.Y) > 0.25f)
            {
                if (Direction.X < 0)
                    currentMovingDirection = MovingDirection.Left;
                else
                    currentMovingDirection = MovingDirection.Right;
            }
            else if (FAbs(Direction.X) - FAbs(Direction.Y) < -0.25f)
            {
                if (Direction.Y < 0)
                    currentMovingDirection = MovingDirection.Up;
                else
                    currentMovingDirection = MovingDirection.Down;
            }
            else
            {
                if (Direction.X < 0 && Direction.Y < 0) currentMovingDirection = MovingDirection.LeftUp;
                else if (Direction.X > 0 && Direction.Y < 0) currentMovingDirection = MovingDirection.RightUp;
                else if (Direction.X < 0 && Direction.Y > 0) currentMovingDirection = MovingDirection.LeftDown;
                else if (Direction.X > 0 && Direction.Y > 0) currentMovingDirection = MovingDirection.RightDown;
            }
        }
 protected override bool MoveProduction(MovingDirection direction)
 {
     return _productionLineMover.MoveProductionLine(direction);
 }
Esempio n. 45
0
 public void ToDirection(MovingDirection toDirection)
 {
     while (currentDirection != toDirection) {
         RotateLeft();
     }
 }
 protected abstract bool MoveProduction(MovingDirection direction);