상속: MonoBehaviour
예제 #1
0
 private void Form1_KeyUp(object sender, KeyEventArgs e)
 {//Stops movement when key is lifted
     MoveUp.Stop();
     MoveDown.Stop();
     MoveRight.Stop();
     MoveLeft.Stop();
 }
예제 #2
0
        void ReleaseDesignerOutlets()
        {
            if (MoveUp != null)
            {
                MoveUp.Dispose();
                MoveUp = null;
            }

            if (MoveLeft != null)
            {
                MoveLeft.Dispose();
                MoveLeft = null;
            }

            if (MoveRight != null)
            {
                MoveRight.Dispose();
                MoveRight = null;
            }

            if (MoveDown != null)
            {
                MoveDown.Dispose();
                MoveDown = null;
            }

            if (ZoomLevel != null)
            {
                ZoomLevel.Dispose();
                ZoomLevel = null;
            }
        }
예제 #3
0
        private async Task move(int sourceIndex, int destinationIndex)
        {
            try
            {
                var sourceItem      = Items[sourceIndex];
                var destinationItem = Items[destinationIndex];
                var desiredRank     = destinationItem.Rank;
                if (destinationIndex > sourceIndex)
                {
                    desiredRank++;
                }

                Items.Move(sourceIndex, destinationIndex);
                var response = await QueueClient.SetRank(sourceItem.ID, desiredRank);

                if ((response == null) || !response.Success)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", response != null?response.ErrorMessageClean : "Unable to move the selected video.", "OK");
                }

                MoveUp.ChangeCanExecute();
                MoveDown.ChangeCanExecute();
                MoveToTop.ChangeCanExecute();
                MoveToBottom.ChangeCanExecute();
            }
            catch (Exception ex)
            {
                //XXX : Handle error
                LoggerService.Instance.Log("ERROR: Queue.move: " + ex);
            }
        }
예제 #4
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            MoveUp.Begin();    // To make MoveUp controllable.
            MoveUp.Stop();     // Then force it stop.

            Translate.Y = -ScreenHeight;
            this.Dispatcher.BeginInvoke(new Action(MoveBack.Begin));
        }
예제 #5
0
    void Start()
    {
        player = gameObject.GetComponent <Player>();

        buttonUpArrow   = buttonW = new MoveUp(player);
        buttonDownArrow = buttonS = new MoveDown(player);
        buttonSpace     = new Jump(player);
    }
예제 #6
0
    void FixedUpdate()
    {
        //this is a standtard push that scales diretly to frame rate
        //Time.deltaTime negates the frame rate diffirences and the really high number helps the cube to actually move

        rb.AddForce(0, 0, forwardSpeed * Time.deltaTime);


        if (Input.GetKey("d"))
        {
            Command _moveRight = new MoveRight(rb, lateralSpeed);
            Invoker invoker    = new Invoker();
            invoker.SetCommand(_moveRight);

            invoker.ExecuteComand();
            //commandDisplay.text += "\n" + _moveRight.ToString();
        }

        if (Input.GetKey("a"))
        {
            Command _moveLeft = new MoveLeft(rb, lateralSpeed);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(_moveLeft);
            //  commandDisplay.text += "\n" + _moveLeft.ToString();
            invoker.ExecuteComand();
        }

        if (Input.GetKey("w"))
        {
            Command _moveUp = new MoveUp(rb, lateralSpeed);
            Invoker invoker = new Invoker();
            invoker.SetCommand(_moveUp);
            //   commandDisplay.text += "\n" + _moveUp.ToString();
            invoker.ExecuteComand();
        }

        if (Input.GetKey("s"))
        {
            //loacal _moveDown  //calling the command in commmand
            Command _moveDown = new MoveDown(rb, lateralSpeed);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(_moveDown);
            //  commandDisplay.text += "\n" + _moveDown.ToString();
            invoker.ExecuteComand();
        }

        if (rb.position.y < -1f)
        {
            FindObjectOfType <GameManager>().EndGame();
        }

        if (rb.GetComponentInParent <Transform>().position.z > halfWay)
        {
            OnHalfWay?.Invoke();
        }
    }
예제 #7
0
#pragma warning restore 0649

    private void Start()
    {
        _worldSpawner = GetComponent <AutoSpawn_Dynamic>();
        _player       = FindObjectOfType <MoveUp>();

        for (int i = 0; i <= initialPresetSize; i++)
        {
            _worldSpawner.UseObject();
            _player.UpdateNext();
        }
    }
        public void Update()
        {
            //Check keys in keymap
            //Has Released Keys
            foreach (var item in keyMap.OnReleasedKeyMap)
            {
                if (Input.GetKeyUp(item.Key))
                {
                    Debug.Log(string.Format("onReleasedKeyMap Key released {0}", item.Value.ToString())); //Log key to console
                    Command command = null;
                    switch (item.Value)
                    {
                    case "Move Up":
                        //trigger Move Up command
                        command = new MoveUp();
                        break;

                    case "Move Down":
                        //trigger Move Down command
                        command = new MoveDown();
                        break;

                    case "Move Left":
                        //trigger Move Left command
                        command = new MoveLeft();
                        break;

                    case "Move Right":
                        //trigger Move Down command
                        command = new MoveRight();
                        break;

                    case "Undo":
                        if (Commands.Count > 0)
                        {
                            command = (Command)Commands.Pop();
                            if (command is ICommandWithUndo)     //if the popped command has an undo command use it
                            {
                                command = ((ICommandWithUndo)command).UndoCommand;
                            }
                        }
                        break;
                    }
                    if (command != null)
                    {
                        if (command is ICommandWithUndo)
                        {
                            Commands.Push((ICommandWithUndo)command); //only push commands with undo to the stack
                        }
                        command.Execute(MoveCommandTarget);
                    }
                }
            }
        }
예제 #9
0
 protected override void RenderContent(UnityEngine.Object undoRecordObject)
 {
     MoveForward.RenderEditorGUI(undoRecordObject);
     MoveBack.RenderEditorGUI(undoRecordObject);
     StrafeLeft.RenderEditorGUI(undoRecordObject);
     StrafeRight.RenderEditorGUI(undoRecordObject);
     MoveUp.RenderEditorGUI(undoRecordObject);
     MoveDown.RenderEditorGUI(undoRecordObject);
     Pan.RenderEditorGUI(undoRecordObject);
     LookAround.RenderEditorGUI(undoRecordObject);
     Orbit.RenderEditorGUI(undoRecordObject);
 }
        public override void Update(GameTime gameTime)
        {
            var kstate = Keyboard.GetState();

            if (kstate.IsKeyDown(slowMode))
            {
                speed = (speed == originalSpeed) ? speed / slowModeModifier : speed * slowModeModifier;
            }

            if (kstate.IsKeyDown(godMode) && pastKey.IsKeyUp(godMode))
            {
                isGod = !isGod;
            }

            // for testing the win states
            if (kstate.IsKeyDown(win) && pastKey.IsKeyUp(win))
            {
                winner = 1; // win -> see win screen
            }
            //for testing lose life
            if (kstate.IsKeyDown(hit) && pastKey.IsKeyUp(hit))
            {
                if (invincible == false)
                {
                    takeHit(); //player is hit
                }
            }

            if (kstate.IsKeyDown(upKey))
            {
                position = new MoveUp(speed).getNewPosition(position, velocity);
            }
            if (kstate.IsKeyDown(downKey))
            {
                position = new MoveDown(speed).getNewPosition(position, velocity);
            }
            if (kstate.IsKeyDown(leftKey))
            {
                position = new MoveLeft(speed).getNewPosition(position, velocity);
            }
            if (kstate.IsKeyDown(rightKey))
            {
                position = new MoveRight(speed).getNewPosition(position, velocity);
            }
            if (kstate.IsKeyDown(shootKey) && pastKey.IsKeyUp(shootKey))
            {
                shoot();
            }
            pastKey = Keyboard.GetState();

            bulletsUpdateAndCleanup(gameTime);
        }
예제 #11
0
        /// <summary>
        /// Function for creating commands
        /// </summary>
        /// <param name="command">Command name</param>
        /// <returns>New command object</returns>
        public ICommand CreateCommand(string command)
        {
            ICommand resultCommand;

            if (this.commandDictionary.ContainsKey(command))
            {
                return(this.commandDictionary[command]);
            }

            switch (command)
            {
            case "u":
                resultCommand = new MoveUp();
                break;

            case "d":
                resultCommand = new MoveDown();
                break;

            case "l":
                resultCommand = new MoveLeft();
                break;

            case "r":
                resultCommand = new MoveRight();
                break;

            case "restart":
                resultCommand = new RestartCommand();
                break;

            case "top":
                resultCommand = new ScoreCommand();
                break;

            case "exit":
                resultCommand = new ExitCommand();
                break;

            case "undo":
                resultCommand = new UndoCommand();
                break;

            default:
                throw new InvalidCommandException(GlobalErrorMessages.InvalidCommandMessage);
            }

            this.commandDictionary.Add(command, resultCommand);
            return(resultCommand);
        }
예제 #12
0
        private void GameOver()
        {
            ZebraMover.Stop();
            BlueMove.Stop();
            PurpleMove.Stop();
            GreenMove.Stop();
            GameEnd.Visible         = true;
            PlayAgainButton.Visible = true;

            //Stops orange car from moving
            MoveUp.Stop();
            MoveDown.Stop();
            MoveRight.Stop();
            MoveLeft.Stop();
        }
예제 #13
0
    void FixedUpdate()
    {
        rb.AddForce(0, 0, forwardSpeed * Time.deltaTime);


        if (Input.GetKey("d"))
        {
            Command _moveRight = new MoveRight(rb, lateralSpeed);
            Invoker invoker    = new Invoker();
            invoker.SetCommand(_moveRight);

            invoker.ExecuteCommand();
            //commandDisplay.text += "\n" + _moveRight.ToString();
        }

        if (Input.GetKey("a"))
        {
            Command _moveLeft = new MoveLeft(rb, lateralSpeed);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(_moveLeft);
            //commandDisplay.text += "\n" + _moveLeft.ToString();
            invoker.ExecuteCommand();
        }

        if (Input.GetKey("w"))
        {
            Command _moveUp = new MoveUp(rb, lateralSpeed);
            Invoker invoker = new Invoker();
            invoker.SetCommand(_moveUp);
            //commandDisplay.text += "\n" + _moveUp.ToString();
            invoker.ExecuteCommand();
        }

        if (Input.GetKey("s"))
        {
            //loacal _moveDown  //calling the command in commmand
            Command _moveDown = new MoveDown(rb, lateralSpeed);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(_moveDown);
            //commandDisplay.text += "\n" + _moveDown.ToString();
            invoker.ExecuteCommand();
        }

        if (rb.position.y < -1f)
        {
            FindObjectOfType <GameManager>().EndGame();
        }
    }
예제 #14
0
파일: GameHub.cs 프로젝트: MatasGos/BMAN
        public async Task SendMoveMessage(string moveCommand)
        {
            await Task.Run(() =>
            {
                ICommand command = null;
                Player p         = Server.GetPlayerById(Context.ConnectionId);
                switch (moveCommand)
                {
                case "moveleft":
                    command = new MoveLeft(p, Server.current);
                    break;

                case "moveright":
                    command = new MoveRight(p, Server.current);
                    break;

                case "moveup":
                    command = new MoveUp(p, Server.current);
                    break;

                case "movedown":
                    command = new MoveDown(p, Server.current);
                    break;

                case "moveleftup":
                    command = new MoveLeftUp(p, Server.current);
                    break;

                case "moveleftdown":
                    command = new MoveLeftDown(p, Server.current);
                    break;

                case "moverightup":
                    command = new MoveRightUp(p, Server.current);
                    break;

                case "moverightdown":
                    command = new MoveRightDown(p, Server.current);
                    break;
                }
                p.SetCommand(command);
            });
        }
    void FixedUpdate()                      // Using FixedUpdate() because we are using physics
    {
        // Add forward force
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);

        // Check if user is pressing the "up" key (either up arrow or 'w')
        if (Input.GetKey("w") || Input.GetKey(KeyCode.UpArrow))
        {
            Command moveUp  = new MoveUp(rb, jumpForce);
            Invoker invoker = new Invoker();
            invoker.SetCommand(moveUp);
            invoker.ExecuteCommand(moveUp);

            commandLog.text += "Move Up\n";
        }

        // Check if user is pressing the "right" key (either right arrow or 'd')
        if (Input.GetKey("d") || Input.GetKey(KeyCode.RightArrow))
        {
            Command moveRight = new MoveRight(rb, sidewaysForce);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(moveRight);
            invoker.ExecuteCommand(moveRight);

            commandLog.text += "Move Right\n";
        }

        // Check if user is pressing the "left" key (either left arrow or 'a')
        if (Input.GetKey("a") || Input.GetKey(KeyCode.LeftArrow))
        {
            Command moveLeft = new MoveLeft(rb, sidewaysForce);
            Invoker invoker  = new Invoker();
            invoker.SetCommand(moveLeft);
            invoker.ExecuteCommand(moveLeft);

            commandLog.text += "Move Left\n";
        }

        if (rb.position.y < -1f)
        {
            FindObjectOfType <GameManager>().EndGame();
        }
    }
예제 #16
0
        private void RootPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (InputElement != null)
            {
                RootPanel.MouseMove -= RootPanel_MouseMove;
                InputElement.ReleaseMouseCapture();
                InputElement     = null;
                CurrentTranslate = 0;

                if (Translate.Y < 0 && Translate.Y > (-ScreenHeight / 2))
                {
                    MoveBack.Begin();
                }
                else if (Translate.Y <= (-ScreenHeight / 2))
                {
                    ((DoubleAnimation)MoveUp.Children[0]).To = -ScreenHeight;
                    MoveUp.Begin();
                }
            }
        }
예제 #17
0
 public Schema()
     : base()
 {
     InstanceType = typeof(__SoPersonOb__);
     ClassName    = "PersonObj";
     Properties.ClearExposed();
     FirstName = Add <__TString__>("FirstName");
     FirstName.DefaultValue = "";
     FirstName.SetCustomAccessors((_p_) => { return(((__SoPersonOb__)_p_).__bf__FirstName__); }, (_p_, _v_) => { ((__SoPersonOb__)_p_).__bf__FirstName__ = (System.String)_v_; }, false);
     LastName = Add <__TString__>("LastName");
     LastName.DefaultValue = "";
     LastName.SetCustomAccessors((_p_) => { return(((__SoPersonOb__)_p_).__bf__LastName__); }, (_p_, _v_) => { ((__SoPersonOb__)_p_).__bf__LastName__ = (System.String)_v_; }, false);
     SortOrder = Add <__TLong__>("SortOrder");
     SortOrder.DefaultValue = 0L;
     SortOrder.SetCustomAccessors((_p_) => { return(((__SoPersonOb__)_p_).__bf__SortOrder__); }, (_p_, _v_) => { ((__SoPersonOb__)_p_).__bf__SortOrder__ = (System.Int64)_v_; }, false);
     MoveUp = Add <__TLong__>("MoveUp$");
     MoveUp.DefaultValue = 0L;
     MoveUp.Editable     = true;
     MoveUp.SetCustomAccessors((_p_) => { return(((__SoPersonOb__)_p_).__bf__MoveUp__); }, (_p_, _v_) => { ((__SoPersonOb__)_p_).__bf__MoveUp__ = (System.Int64)_v_; }, false);
     MoveUp.AddHandler((Json pup, Property <Int64> prop, Int64 value) => { return(new Input.MoveUp()
         {
             App = (PersonObj)pup, Template = (TLong)prop, Value = value
         }); }, (Json pup, Starcounter.Input <Int64> input) => { ((PersonObj)pup).Handle((Input.MoveUp)input); });
     MoveDown = Add <__TLong__>("MoveDown$");
     MoveDown.DefaultValue = 0L;
     MoveDown.Editable     = true;
     MoveDown.SetCustomAccessors((_p_) => { return(((__SoPersonOb__)_p_).__bf__MoveDown__); }, (_p_, _v_) => { ((__SoPersonOb__)_p_).__bf__MoveDown__ = (System.Int64)_v_; }, false);
     MoveDown.AddHandler((Json pup, Property <Int64> prop, Int64 value) => { return(new Input.MoveDown()
         {
             App = (PersonObj)pup, Template = (TLong)prop, Value = value
         }); }, (Json pup, Starcounter.Input <Int64> input) => { ((PersonObj)pup).Handle((Input.MoveDown)input); });
     ItemDropped = Add <__TLong__>("ItemDropped$");
     ItemDropped.DefaultValue = 0L;
     ItemDropped.Editable     = true;
     ItemDropped.SetCustomAccessors((_p_) => { return(((__SoPersonOb__)_p_).__bf__ItemDropped__); }, (_p_, _v_) => { ((__SoPersonOb__)_p_).__bf__ItemDropped__ = (System.Int64)_v_; }, false);
     ItemDropped.AddHandler((Json pup, Property <Int64> prop, Int64 value) => { return(new Input.ItemDropped()
         {
             App = (PersonObj)pup, Template = (TLong)prop, Value = value
         }); }, (Json pup, Starcounter.Input <Int64> input) => { ((PersonObj)pup).Handle((Input.ItemDropped)input); });
 }
예제 #18
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {//Start timer to move car
            if (e.KeyCode == Keys.Up)
            {
                MoveUp.Start();
            }

            if (e.KeyCode == Keys.Down)
            {
                MoveDown.Start();
            }

            if (e.KeyCode == Keys.Right)
            {
                MoveRight.Start();
            }

            if (e.KeyCode == Keys.Left)
            {
                MoveLeft.Start();
            }
        }
예제 #19
0
        private void RootPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            MouseY = e.GetPosition(this).Y;

            CurrentTranslate = Translate.Y;
            Translate.Y      = CurrentTranslate;

            InputElement = (IInputElement)sender;
            InputElement.CaptureMouse();

            if (MoveBack.GetCurrentState() == ClockState.Active)
            {
                MoveBack.Stop();
            }

            if (MoveUp.GetCurrentState() == ClockState.Active)
            {
                MoveUp.Stop();
            }

            RootPanel.MouseMove += RootPanel_MouseMove;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GestureController"/> class.
        /// </summary>
        public GestureController()
        {
            // Define the gestures

            IRelativeGestureSegment moveDown = new MoveDown();

            AddGesture(GestureType.MoveDown, moveDown);

            IRelativeGestureSegment moveIn = new MoveIn();

            AddGesture(GestureType.MoveIn, moveIn);

            IRelativeGestureSegment moveLeft = new MoveLeft();

            AddGesture(GestureType.MoveLeft, moveLeft);

            IRelativeGestureSegment moveRight = new MoveRight();

            AddGesture(GestureType.MoveRight, moveRight);

            IRelativeGestureSegment moveOut = new MoveOut();

            AddGesture(GestureType.MoveOut, moveOut);

            IRelativeGestureSegment moveUp = new MoveUp();

            AddGesture(GestureType.MoveUp, moveUp);

            IRelativeGestureSegment handCloseOrOpen = new HandCloseOrOpen();

            AddGesture(GestureType.HandCloseOrOpen, handCloseOrOpen);

            IRelativeGestureSegment headMoved = new HeadMoved();

            AddGesture(GestureType.HeadMoved, headMoved);

            //CvInvoke.cvNamedWindow("Source");
        }
예제 #21
0
 void Update()
 {
     if (Input.GetKey(KeyCode.A))
     {
         moveLeft = new MoveLeft(transform, speed);
         moveLeft.Execute();
     }
     if (Input.GetKey(KeyCode.D))
     {
         moveRight = new MoveRight(transform, speed);
         moveRight.Execute();
     }
     if (Input.GetKey(KeyCode.W))
     {
         moveUp = new MoveUp(transform, speed);
         moveUp.Execute();
     }
     if (Input.GetKey(KeyCode.S))
     {
         moveDown = new MoveDown(transform, speed);
         moveDown.Execute();
     }
 }
예제 #22
0
 void Start()
 {
     InvokeRepeating ("IncreaseTimeScale", 1, 15);
     cameraSpeed = Camera.main.GetComponent<MoveUp>();
     camSpeed = MoveUp.cameraSpeed;
 }
        private void UserControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (KeyValidator.IsUpKey(e.Key))
            {
                e.Handled = true;
                MoveUp?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsDownKey(e.Key))
            {
                e.Handled = true;
                MoveDown?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsLeftKey(e.Key))
            {
                e.Handled = true;
                MoveLeft?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsRightKey(e.Key))
            {
                e.Handled = true;
                MoveRight?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsPageDownKey(e.Key))
            {
                e.Handled = true;
                MovePageDown?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsPageUpKey(e.Key))
            {
                e.Handled = true;
                MovePageUp?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsDeleteKey(e.Key))
            {
                if (!ReadOnlyMode)
                {
                    e.Handled = true;
                    ByteDeleted?.Invoke(this, new EventArgs());

                    return;
                }
            }
            else if (KeyValidator.IsBackspaceKey(e.Key))
            {
                e.Handled = true;
                ByteDeleted?.Invoke(this, new EventArgs());

                MovePrevious?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsEscapeKey(e.Key))
            {
                e.Handled = true;
                EscapeKey?.Invoke(this, new EventArgs());
                return;
            }

            //MODIFY BYTE
            if (!ReadOnlyMode)
            {
                if (KeyValidator.IsHexKey(e.Key))
                {
                    string key;
                    if (KeyValidator.IsNumericKey(e.Key))
                    {
                        key = KeyValidator.GetDigitFromKey(e.Key).ToString();
                    }
                    else
                    {
                        key = e.Key.ToString().ToLower();
                    }

                    switch (_keyDownLabel)
                    {
                    case KeyDownLabel.FirstChar:
                        FirstHexChar.Content = key;
                        _keyDownLabel        = KeyDownLabel.SecondChar;
                        Action = ByteAction.Modified;
                        Byte   = ByteConverters.HexToByte(FirstHexChar.Content.ToString() + SecondHexChar.Content.ToString())[0];
                        break;

                    case KeyDownLabel.SecondChar:
                        SecondHexChar.Content = key;
                        _keyDownLabel         = KeyDownLabel.NextPosition;

                        Action = ByteAction.Modified;
                        Byte   = ByteConverters.HexToByte(FirstHexChar.Content.ToString() + SecondHexChar.Content.ToString())[0];

                        //Move focus event
                        MoveNext?.Invoke(this, new EventArgs());
                        break;
                    }
                }
            }
        }
예제 #24
0
 private void Start()
 {
     _player = FindObjectOfType <MoveUp>();
     time    = _player.time;
 }
예제 #25
0
 private void Start()
 {
     _player    = FindObjectOfType <MoveUp>();
     _transform = transform;
     _time      = _player.time;
 }
예제 #26
0
 private void lblUp_Click(object sender, EventArgs e)
 {
     MoveUp?.Invoke(this, this);
 }
예제 #27
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (playerObject == null)
            {
                return;
            }

            var moved = false;

            if (PlayerSettings.canMove)
            {
                var calc = PlayerSettings.minPlayerSpeed * (PlayerSettings.maxPlayerSize / playerObject.size);

                var speed = calc > PlayerSettings.maxPlayerSpeed ? PlayerSettings.maxPlayerSpeed : calc;
                var mover = new PlayerMover();
                if (PlayerSettings.movingUp)
                {
                    var newCoord = playerObject.yCoord - speed;
                    if (newCoord < 0)
                    {
                        return;
                    }

                    ICommand moveUp = new MoveUp(playerObject, newCoord);
                    mover.performMove(moveUp);
                    moved = true;
                }

                if (PlayerSettings.movingDown)
                {
                    var newCoord = playerObject.yCoord + speed;
                    if (newCoord > maxY)
                    {
                        return;
                    }

                    ICommand moveDown = new MoveDown(playerObject, newCoord);
                    mover.performMove(moveDown);
                    moved = true;
                }

                if (PlayerSettings.movingLeft)
                {
                    var newCoord = playerObject.xCoord - speed;
                    if (newCoord < 0)
                    {
                        return;
                    }

                    ICommand moveLeft = new MoveLeft(playerObject, newCoord);
                    mover.performMove(moveLeft);
                    moved = true;
                }

                if (PlayerSettings.movingRight)
                {
                    var newCoord = playerObject.xCoord + speed;
                    if (newCoord > maxX)
                    {
                        return;
                    }

                    ICommand moveRight = new MoveRight(playerObject, newCoord);
                    mover.performMove(moveRight);
                    moved = true;
                }

                //Create memento only if moved.
                if (moved)
                {
                    playerObject.SetPosition(new TwoDimensionalPosition
                    {
                        X = playerObject.xCoord,
                        Y = playerObject.yCoord
                    });

                    playerPositions.AddMemento(playerObject.CreateMemento());
                }
            }
            else
            {
                timer--;
                savedPositionCount--;

                var newPos = playerPositions.GetMemento(savedPositionCount);

                if (newPos.GetSavedPosition(playerObject.Uuid) != null)
                {
                    playerObject.MoveX(newPos.GetSavedPosition(playerObject.Uuid).X);
                    moved = true;
                }

                if (newPos.GetSavedPosition(playerObject.Uuid) != null)
                {
                    playerObject.MoveY(newPos.GetSavedPosition(playerObject.Uuid).Y);
                    moved = true;
                }

                //Stop moving back either when timer ends or when out of saved positions
                if (timer <= 0 || savedPositionCount <= 0)
                {
                    PlayerSettings.canMove = true;
                }
            }

            //Send player locations to server.
            if (moved)
            {
                var content = new Dictionary <string, string>
                {
                    { "playerUuid", currentPlayer.Uuid },
                    { "xCoord", playerObject.objectControl.Location.X.ToString() },
                    { "yCoord", playerObject.objectControl.Location.Y.ToString() }
                };

                updater.PostData("api/player/move", Processor.PostDataType.Post, content);
            }

            CheckForCollision();
        }
        public void Execute()
        {
            Redraw();

            var input = System.Console.ReadKey().Key;

            while (input != System.ConsoleKey.Escape)
            {
                Move      command = null;
                Character actor   = null;

                switch (input)
                {
                case System.ConsoleKey.UpArrow:
                    actor   = _character1;
                    command = new MoveUp(_character1.PosX, _character1.PosY);
                    break;

                case System.ConsoleKey.LeftArrow:
                    actor   = _character1;
                    command = new MoveLeft(_character1.PosX, _character1.PosY);
                    break;

                case System.ConsoleKey.DownArrow:
                    actor   = _character1;
                    command = new MoveDown(_character1.PosX, _character1.PosY);
                    break;

                case System.ConsoleKey.RightArrow:
                    actor   = _character1;
                    command = new MoveRight(_character1.PosX, _character1.PosY);
                    break;

                case System.ConsoleKey.W:
                    actor   = _character2;
                    command = new MoveUp(_character2.PosX, _character2.PosY);
                    break;

                case System.ConsoleKey.A:
                    actor   = _character2;
                    command = new MoveLeft(_character2.PosX, _character2.PosY);
                    break;

                case System.ConsoleKey.S:
                    actor   = _character2;
                    command = new MoveDown(_character2.PosX, _character2.PosY);
                    break;

                case System.ConsoleKey.D:
                    actor   = _character2;
                    command = new MoveRight(_character2.PosX, _character2.PosY);
                    break;

                case System.ConsoleKey.Backspace:
                    if (_actions.TryPop(out var action))
                    {
                        action.Command.Undo(action.Actor);
                    }
                    break;

                default:
                    _drawer.WriteMessage("You can move [A] with the [ARROW] keys, [B] with the [WASD] keys, and exit with the [ESCAPE] key.");
                    break;
                }

                if (command != null)
                {
                    command.Execute(actor);
                    _actions.Push(new MoveAction(actor, command));
                }

                Redraw();

                input = System.Console.ReadKey().Key;
            }
        }
 public void Handle(MoveUp message)
 {
     _camera.MoveUp(_settings.CameraMoveSpeedPerSecond * message.InputState.ElapsedTime.TotalSeconds);
 }
예제 #30
0
        private void Running()
        {
            // updating mainSprite
            if (Fire.Triggered())
            {
                mainSprite.NewDirection();
            }
            else if (MoveUp.Triggered())
            {
                mainSprite.NewDirection(0);
            }
            else if (MoveRight.Triggered())
            {
                mainSprite.NewDirection(1);
            }
            else if (MoveDown.Triggered())
            {
                mainSprite.NewDirection(2);
            }
            else if (MoveLeft.Triggered())
            {
                mainSprite.NewDirection(3);
            }
            else
            {
                mainSprite.NewDirection();
            }
            mainSprite.Update();

            // update all other enemies
            for (var i = 1; i < sprites.Count; i++)
            {
                var sprite = sprites[i];
                sprite.Update();

                if (mainSprite.CollidesWith(sprite))
                {
                    if (sprite is EnemySprite || sprite is RockSprite)
                    {
                        GoToCrashed();
                        break;
                    }
                    else if (sprite is FlagSprite)
                    {
                        GameState.Score     += GameState.FlagScore;
                        GameState.FlagScore += 100;
                        sprites.Remove(sprite);

                        if (!sprites.Any(xx => xx is FlagSprite))
                        {
                            GoToCompleted();
                        }
                    }
                }
            }

            GameState.Fuel--;
            if (GameState.Fuel == 0)
            {
                GoToCrashed();
            }
        }
    // Update is called once per frame
    public void Update()
    {
        //Check keys in keymap
        //Has Released Keys
        foreach (var item in input.keysPressed)
        {
            if (Input.GetKeyDown(item.Key))
            {
                Command command = null;
                // Debug.Log(string.Format("onReleasedKeyMap Key pressed {0}", item.Value.ToString())); //Log key to console

                switch (item.Value)
                {
                case "Move Up":
                    //trigger Move Up command

                    command = new MoveUp();

                    break;

                case "Move Down":

                    command = new MoveDown();

                    break;

                case "Move Left":

                    command = new MoveLeft();
                    break;

                case "Move Right":
                    command = new MoveRight();

                    break;

                case "Switch":
                    command = new SwitchWeapon();
                    break;

                case "Roll":
                    command = new Roll();
                    break;

                case "Shoot":
                    command = new Shoot();

                    break;

                case "DEBUG":
                    GameObject temp;
                    temp           = MoveableEntity;
                    MoveableEntity = DEBUGEntity;
                    DEBUGEntity    = temp;
                    break;
                }

                if (command != null)
                {
                    ActivateCommand(command);
                }
            }

            if (Input.GetKeyUp(item.Key))
            {
                Command command = null;
                // Debug.Log(string.Format("onReleasedKeyMap Key released {0}", item.Value.ToString())); //Log key to console
                switch (item.Value)
                {
                case "Move Up":
                    command = new WaitUp();
                    break;

                case "Move Down":
                    command = new WaitDown();
                    break;

                case "Move Left":
                    command = new WaitLeft();
                    break;

                case "Move Right":
                    command = new WaitRight();
                    break;
                }
                if (command != null)
                {
                    ActivateCommand(command);
                }
            }
        }
    }