Beispiel #1
0
 void Moving()
 {
     if (ExectuingCommand != null)
     {
         if (ExectuingCommand.isBeingExecuted)
         {
             ExecuteCommand();
         }
         else
         {
             ExectuingCommand = null;
         }
     }
     else
     {
         if (CommandQueue.Count > 0)
         {
             ExectuingCommand = CommandQueue.Dequeue();
         }
         else
         {
             Searching();
         }
     }
 }
Beispiel #2
0
        public void Ctor_WhenMovementCommandIsNotForwardOrBackward_ThrowsInvalidOperationException()
        {
            _movementCommand = MovementCommand.Left;
            Func <ForwardBackwardMovementStrategy> func = () => ForwardBackwardMovementStrategy;

            func.Should().Throw <InvalidOperationException>();
        }
Beispiel #3
0
    public void DoUpdate()
    {
        if (Command != MovementCommand.None)
        {
            Vector2 newCoordinates;
            if (MapReference.CanMoveTo(Coordinates, Command, out newCoordinates))
            {
                if ((int)(newCoordinates - Coordinates).magnitude == 1)
                {
                    Move(newCoordinates);
                }
                else
                {
                    Teleport(newCoordinates);
                }
                if (IsPlayer())
                {
                    if (GhostCreationRequested)
                    {
                        CreateNextGhost();
                        GhostCreationRequested = false;
                    }
                    PreviousCommand.Add(Command);
                    GhostPath.AddCommand(Command);
                }
            }

            Command = MovementCommand.None;
        }
    }
Beispiel #4
0
 public void AskMoveRight(InputAction.CallbackContext ctx)
 {
     if (ctx.started && !UI_Manager.instance.bLevelPaused && Command == MovementCommand.None && GetLastCommand() != MovementCommand.Left && !IsMoving && !LoopLocked && !IsRewinding)
     {
         Command = MovementCommand.Right;
     }
 }
        public bool handleDrivingKey(Keys key, bool justCheck = false)
        {
            if (!drivingModeEnabled)
            {
                return(false); // never handle if not in driving mode.
            }

            bool handled = true;

            try
            {
                MovementCommand command = tryConvertKeyToMovementCommand(key);

                if (!justCheck)
                {
                    sendMovementCommand(command);
                }
            }
            catch (ArgumentException)
            {
                handled = false;
            }

            return(handled);
        }
        public RemoteControlProgram(RepairDroid repairDroid, ICommandInput commandInput, IView consoleView)
        {
            _relativePosition = Coordinate.Origin;
            _lastPosition     = _relativePosition;

            _movementCommand            = (MovementCommand)(-1);
            commandInput.InputReceived += (_, v) => _movementCommand = (MovementCommand)v;

            repairDroid.OnReply += (_, msg) =>
            {
                switch (msg)
                {
                case RepairDroidStatusCode.HitWall:
                    consoleView.Write(GetNewLocation(_relativePosition), '#');

                    break;

                case RepairDroidStatusCode.Moved:
                    consoleView.Write(_relativePosition, '.');
                    Move();
                    consoleView.Write(_relativePosition, 'D');
                    break;

                case RepairDroidStatusCode.MovedAndFoundOxygenSystem:
                    Move();
                    FoundOxygenSystem?.Invoke(this, _relativePosition);
                    _run = false;
                    break;
                }
                ;
            };
            _repairDroid  = repairDroid;
            _commandInput = commandInput;
        }
Beispiel #7
0
    private AudioSource a;               //In case we want to play sound effects.

    void Start()
    {
        originalPosition = transform.position;
        originalRotation = transform.rotation;
        a = GetComponent <AudioSource>();

        attachedBattery = GetComponent <Battery>();
        useBattery      = attachedBattery != null;

        if (type == PathType.PingPong)
        {
            MovementCommand[] newSteps = new MovementCommand[steps.Length * 2];
            int pos = 0;
            foreach (MovementCommand step in steps)
            {
                newSteps[pos] = step;
                newSteps[newSteps.Length - 1 - pos] = new MovementCommand(step.type, step.interpretSpeedAsGoal, step.duration, -step.speed, -step.angularSpeed, step.freezePosition, step.freezeRotation, step.sound);

                pos += 1;
            }
            steps = newSteps;
        }

        Activate();
    }
        private void KeepAlive()
        {
            while (true)
            {
                keepAliveCommand.Execute();

                if (!allowCommand())
                {
                    //Console.WriteLine("***Emergency stop enabled***");
                    if (emergencyLeftStopCommand == null)
                    {
                        emergencyLeftStopCommand = new MovementCommand(EMERGENCY_LEFT_STOP);
                    }

                    if (emergencyRightStopCommand == null)
                    {
                        emergencyRightStopCommand = new MovementCommand(EMERGENCY_RIGHT_STOP);
                    }

                    emergencyLeftStopCommand.Execute();
                    emergencyRightStopCommand.Execute();
                }

                Thread.Sleep(_sleepPeriod);
            }
        }
    public void ApplyCommandOnPlayer(PlayerBody body, MovementCommand command, float deltaTime = -1)
    {
        if(deltaTime < 0)
        {
            deltaTime = Time.deltaTime;
        }

        Transform bodyTransform = body.gameObject.transform;
        Rigidbody bodyRigidbody = body.gameObject.rigidbody;
        if(command.LateralAxis != 0)
        {
            float torqueMagnitude = body.RotAcceleration * command.LateralAxis * deltaTime;
            bodyRigidbody.AddTorque(bodyTransform.up.normalized * torqueMagnitude);
        }

        if(command.FrontAxis != 0)
        {
            float forceMagnitude = body.LinearAcceleration * command.FrontAxis * deltaTime;
            /*
            Vector3 comOffset = (-bodyTransform.up + bodyTransform.forward * Mathf.Sign(command.FrontAxis)) / 2;
            bodyRigidbody.AddForceAtPosition(bodyTransform.forward * forceMagnitude, bodyRigidbody.centerOfMass + comOffset, ForceMode.Acceleration);
            */
            bodyRigidbody.AddForce(bodyTransform.forward.normalized*forceMagnitude);
        }

        if(command.TestButton(MovementCommand.ActionFlags.Jump))
        {
            body.Jump();
        }
    }
Beispiel #10
0
        public void TestPlacingBombCommand()
        {
            var map     = new GameMap(2, 1, 0);
            var player1 = new PlayerEntity();

            player1.BombBag = 1;

            var block = map.GetBlockAtLocation(1, 1);

            block.SetEntity(player1);

            var transaction = new CommandTransaction(new DummyLogger());
            var command     = new PlaceBombCommand();

            command.PerformCommand(map, player1, transaction);
            transaction.ValidateCommands(map);
            transaction.ProcessCommands(map);

            transaction = new CommandTransaction(new DummyLogger());
            command     = new PlaceBombCommand();
            Assert.Throws <InvalidCommandException>(() => command.PerformCommand(map, player1, transaction),
                                                    "Cannot place bomb in same location twice");

            var moveCommand = new MovementCommand(MovementCommand.Direction.Right);

            moveCommand.PerformCommand(map, player1, transaction);
            transaction.ValidateCommands(map);
            transaction.ProcessCommands(map);

            transaction = new CommandTransaction(new DummyLogger());
            command     = new PlaceBombCommand();
            Assert.Throws <InvalidCommandException>(() => command.PerformCommand(map, player1, transaction),
                                                    "Player cannot place more bombs than is in the bomb bag");
        }
Beispiel #11
0
        /// <summary>
        /// Construct a NonPlayerCharacterMovement
        /// </summary>
        /// <param name="nDialogIndex">the index of an NPC</param>
        /// <param name="movementInstructionDataChunk">The full memory chunk of all movement instructions</param>
        /// <param name="movementOffsetDataChunk">the full memory chunk of the movement offsets</param>
        public NonPlayerCharacterMovement(int nDialogIndex, DataChunk movementInstructionDataChunk, DataChunk movementOffsetDataChunk)
        {
            // we totally ignore the first entry, since it's bad stuff
            if (nDialogIndex == 0)
            {
                return;
            }

            this._movementInstructionDataChunk = movementInstructionDataChunk;
            this._movementOffsetDataChunk      = movementOffsetDataChunk;
            this._nDialogIndex = nDialogIndex;

            // todo: not a very efficient method of getting a UINT16 from the list -> it has to create a brand new list!
            _nOffset = movementOffsetDataChunk.GetChunkAsUint16List() [nDialogIndex];

            // if it has the value of 0xFFFF then it indicates there are currently no instructions
            if (_nOffset == 0xFFFF)
            {
                return;
            }

            // calculate the offset
            int nOffsetIndex = (nDialogIndex) * (MAX_COMMAND_LIST_ENTRIES * MAX_MOVEMENT_COMMAND_SIZE);

            // get a copy because the GetAsByteList is an expensive method call
            List <byte> rawData = movementInstructionDataChunk.GetAsByteList();

            // gets a smaller version of it - much easier to keep track of
            _loadedData = rawData.GetRange(nOffsetIndex, MAX_COMMAND_LIST_ENTRIES * 2);

            int nIndex = _nOffset;

            for (int i = 0; i < MAX_COMMAND_LIST_ENTRIES; i++)
            {
                byte nIterations = _loadedData[nIndex];
                MovementCommandDirection direction = (MovementCommandDirection)_loadedData[nIndex + 1];

                // if we have hit 0xFF then there is nothing else in the list and we can just return
                if (nIterations == 0xFF || nIterations == 0)
                {
                    return;
                }

                if (!(direction == MovementCommandDirection.East || direction == MovementCommandDirection.West || direction == MovementCommandDirection.North ||
                      direction == MovementCommandDirection.South))
                {
                    throw new Ultima5ReduxException("a bad direction was set: " + direction.ToString());
                }


                // we have a proper movement instruction so let's add it to the queue
                MovementCommand movementCommand = new MovementCommand(direction, nIterations);
                //this.movementQueue.Enqueue(movementCommand);
                AddNewMovementInstruction(movementCommand);

                // we actually grab from the offset, but it is circular, so we need to mod it
                nIndex = (nIndex + 2) % (MAX_COMMAND_LIST_ENTRIES * 2);
            }
        }
        public void ConstructorShouldSetMovements(IList <Movement> expected)
        {
            var sut = new MovementCommand(expected);

            var actual = sut.Movements;

            actual.Should().BeEquivalentTo(expected);
        }
        public void SetRecieverShouldAcceptMovements(IList <Movement> movements, [Frozen] Mock <IRover> rover)
        {
            var sut = new MovementCommand(movements);

            Action actual = () => sut.SetReceiver(rover.Object);

            actual.Should().NotThrow <System.Exception>();
        }
 void OnEnable()
 {
     player1       = GameObject.FindGameObjectWithTag("Player");
     player2       = GameObject.FindGameObjectWithTag("PlayerClone");
     currentPlayer = player1;
     currentPlayer.GetComponent <Player>().Indicator.SetActive(true);
     command = new MovementCommand(currentPlayer.GetComponent <Player>());
 }
Beispiel #15
0
            public Action(Point position, MovementCommand movementCommand)
            {
                Position                = position;
                MovementCommand         = movementCommand;
                OriginalMovementCommand = movementCommand;

                _availableMovementCommands = MovementCommand.All.Except(new[] { movementCommand }).ToList();
            }
        public void SetRecieverAndExecuteShouldMakeRoverMove(IList <Movement> expected, [Frozen] Mock <IRover> rover)
        {
            var sut = new MovementCommand(expected);

            sut.SetReceiver(rover.Object);
            sut.Execute();

            rover.Verify(p => p.Move(expected), Times.Once);
        }
        public void sendMovementCommand(MovementCommand command)
        {
            // Create new command packet to send.
            GloObject <GloDrivingCommand> gloCommand = new GloObject <GloDrivingCommand>(Glo.IDs.DrivingCommand);

            gloCommand.data.movementType = (UInt32)command;

            link.send(gloCommand);
        }
Beispiel #18
0
    private void AskMoveNextPoint(int index)
    {
        TimeElapsed[index] -= MovingSpeed;

        if (CurrentIndex[index] >= Commands.Count - 1)
        {
            CurrentIndex[index] = Commands.Count - 1;
            WaitingDeath[index] = true;
            return;
        }
        else
        {
            CurrentIndex[index]++;
        }

        MovementCommand command = Commands[CurrentIndex[index]];

        Vector3 offset = Vector3.up * Height;

        Vector2 newCoord;

        PositionMovementStart[index] = MapReference.MapCoordinatesToWorldSpace(CurrentPoint[index]) + offset;
        if (MapReference.CanMoveTo(CurrentPoint[index], command, out newCoord))
        {
            if ((int)(CurrentPoint[index] - newCoord).magnitude != 1)
            {
                WaitingDeath[index] = true;
                AddTrailFromExisting(index, newCoord);
                switch (Commands[CurrentIndex[index]])
                {
                case MovementCommand.Up:
                    offset.z = OutOfBoundOffset;
                    break;

                case MovementCommand.Down:
                    offset.z = -OutOfBoundOffset;
                    break;

                case MovementCommand.Left:
                    offset.x = -OutOfBoundOffset;
                    break;

                case MovementCommand.Right:
                    offset.x = OutOfBoundOffset;
                    break;
                }

                PositionMovementEnd[index] = PositionMovementStart[index] + offset;
            }
            else
            {
                CurrentPoint[index]        = newCoord;
                PositionMovementEnd[index] = MapReference.MapCoordinatesToWorldSpace(CurrentPoint[index]) + offset;
            }
        }
    }
Beispiel #19
0
 // Use this for initialization
 void Start()
 {
     ActivePlayer  = this;
     pooledCommand = new MovementCommand
     {
         x        = 0,
         y        = 0,
         lifetime = -1.0f
     };
 }
        public async Task <IActionResult> MovePlayer(string nickname, [FromBody] MovementCommand command)
        {
            if (string.IsNullOrWhiteSpace(nickname))
            {
                return(BadRequest("Username cannot be null or empty."));
            }

            var playerPosition = await _movementService.MovePlayer(nickname, command.Direction);

            return(Ok(playerPosition));
        }
        public void CreateMovementCommand_GarbageString_ThrowsArgumentException()
        {
            string rawCommand = "K334/.e;fe";

            Assert.Throws <System.ArgumentException>(
                delegate
            {
                MovementCommand command = new MovementCommand(rawCommand);
            }
                );
        }
        public void CreateMovementCommand_NullStringInserted_ThrowsArgumentNullException()
        {
            string rawCommand = null;

            Assert.Throws <System.ArgumentNullException>(
                delegate
            {
                MovementCommand command = new MovementCommand(rawCommand);
            }
                );
        }
        public void CreateMovementCommand_InvalidSideIdentifier_ThrowsArgumentException()
        {
            string rawCommand = "<XF255F255F255>";

            Assert.Throws <System.ArgumentException>(
                delegate
            {
                MovementCommand command = new MovementCommand(rawCommand);
            }
                , "Command sent: " + rawCommand);
        }
        public void CreateMovementCommand_InvalidMotor2Direction_ThrowsArgumentException()
        {
            string rawCommand = "<RF255X255F255>";

            Assert.Throws <System.ArgumentException>(
                delegate
            {
                MovementCommand command = new MovementCommand(rawCommand);
            }
                , "Command sent: " + rawCommand);
        }
        public void CreateMovementCommand_Motor3SpeedLowerThanMin_ThrowsArgumentException()
        {
            string rawCommand = "<LF255F255F-50>";

            Assert.Throws <System.ArgumentException>(
                delegate
            {
                MovementCommand command = new MovementCommand(rawCommand);
            }
                , "Command sent: " + rawCommand);
        }
Beispiel #26
0
 private void UpdateCommandVariables()
 {
     currentCommand         = patterns[patternIndex].movementCommands[patternCommandIndex];
     startPos               = transform.position;
     point                  = currentCommand.point;
     isDuration             = (currentCommand.movementEnd == MovementEnd.Duration);
     duration               = currentCommand.duration;
     direction              = currentCommand.durationDirection;
     worldPoint             = Game.ToWorld(point);
     durationResultantPoint = Game.ToWorld(direction.normalized * currentCommand.durationMoveSpeed * duration);
 }
 public MovementEntry(byte type, int data01, int data02, byte cmd, int cmdData01, int cmdData02, Vector3 position, Vector3 rotation)
 {
     Data01        = data01;
     Data02        = data02;
     Position      = position;
     Rotation      = rotation;
     Type          = (MovementType)type;
     CommandData01 = cmdData01;
     CommandData02 = cmdData02;
     Command       = (MovementCommand)cmd;
 }
        public void CreateMovementCommand_Motor2SpeedHigherThanMax_ThrowsArgumentException()
        {
            string rawCommand = "<LF255F999F255>";

            Assert.Throws <System.ArgumentException>(
                delegate
            {
                MovementCommand command = new MovementCommand(rawCommand);
            }
                , "Command sent: " + rawCommand);
        }
    public void ApplyCommandOnPlayer(PlayerBody body, MovementCommand command, float deltaTime = -1)
    {
        if(deltaTime < 0)
        {
            deltaTime = Time.deltaTime;
        }

        if(command.HasMovement)
        {
        Debug.Log("Command have ("+command.FrontAxis+","+command.LateralAxis+")");
            Transform cameraReference = body.ActiveCamera.transform;
            Rigidbody rigidbody = body.gameObject.rigidbody;
            Transform playerTransform = body.gameObject.transform;
            //calculate target movement
            Vector3 targetMovement = (command.FrontAxis * cameraReference.forward) + (command.LateralAxis * cameraReference.right);
            targetMovement.y = 0;		//purge vertical component
            targetMovement.Normalize();	//normalize

            Vector2 commandVector = new Vector2(command.FrontAxis, command.LateralAxis);

            //accelerate toward target movement
            rigidbody.AddForce(targetMovement * commandVector.magnitude * body.LinearAcceleration * deltaTime);

            //gradually rotate front toward target

            Vector3 currentFront = playerTransform.forward;
            currentFront.y = 0;
            currentFront.Normalize();	//prevent

            float angle = Vector3.Angle(currentFront, targetMovement);
            if(angle != 0)
            {
                //check if remaining delta is smaller than what's percorrble with current angular velocity
                playerTransform.rotation = Quaternion.LookRotation(Vector3.RotateTowards(playerTransform.forward, targetMovement, body.RotAcceleration * deltaTime, body.LinearAcceleration * deltaTime));
                /*
                float potential = body.RotAcceleration * deltaTime;
                if(angle < potential)
                {
                    playerTransform.rotation = Quaternion.LookRotation(Vector3.RotateTowards(playerTransform.forward, targetMovement, 0, 0));
                }
                else
                {
                    rigidbody.AddTorque(body.transform.up * potential);
                }
                */
            }

        }

        if(command.TestButton(MovementCommand.ActionFlags.Jump))
        {
            body.Jump();
        }
    }
        public void CreateMovementCommand_InvalidMotor1Direction_ThrowsArgumentException()
        {
            string rawCommand = "<RX255F255F255>";

            Assert.Throws<System.ArgumentException>(
                delegate
                {
                    MovementCommand command = new MovementCommand(rawCommand);
                }
            , "Command sent: " + rawCommand);
        }
        public void CreateMovementCommand_GarbageString_ThrowsArgumentException()
        {
            string rawCommand = "K334/.e;fe";

            Assert.Throws<System.ArgumentException>(
                delegate
                {
                    MovementCommand command = new MovementCommand(rawCommand);
                }
            );
        }
Beispiel #32
0
        public void Movement(string direction, Camera2D cam)
        {
            var xmovement = direction.Contains("L") ? -5 : direction.Contains("R") ? 5 : 0;
            var ymovement = direction.Contains("U") ? -5 : direction.Contains("D") ? 5 : 0;
            var command   = new MovementCommand(player, xmovement, ymovement, direction, ICommand.GenerateRandID());

            cam.Move(new Vector2(xmovement, ymovement));
            Thread thread = new Thread(command.Run);

            thread.Start();
            SendMessage(command);
        }
        public void CreateMovementCommand_ValidRightFullForward_InitializesProperly()
        {
            string          rawCommand = "<RF255F255F255>";
            MovementCommand command    = new MovementCommand(rawCommand);

            Assert.AreEqual(command.MotorSide, "R", "Should be \"R\"");
            Assert.AreEqual(command.Motor1Speed, 255, "Should be 255");
            Assert.AreEqual(command.Motor2Speed, 255, "Should be 255");
            Assert.AreEqual(command.Motor3Speed, 255, "Should be 255");
            Assert.AreEqual(command.Motor1Direction, "F", "Should be \"F\"");
            Assert.AreEqual(command.Motor2Direction, "F", "Should be \"F\"");
            Assert.AreEqual(command.Motor3Direction, "F", "Should be \"F\"");
        }
Beispiel #34
0
        internal void DispatchOnKey(Key key)
        {
            IRogueCommand command = null;

            if (Directions.ContainsKey(key))
            {
                bool shouldRun = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);
                command = new MovementCommand(Directions[key], shouldRun);
            }

            _mainWindow.MessageTextblock.Text = string.Empty;
            _game.EnqueueAndProcess(command);
        }
        public void CreateCommandFactory_TooFewSteps_StepsShouldBe1()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("1");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E -3");
            MovementCommand movementCommand = commandFactory._commandSet.MovementCommands[0];

            //assert
            Assert.AreEqual(1, movementCommand.MoveSteps);
        }
    public MovementCommand ParseInputForCommands()
    {
        MovementCommand movCommand = new MovementCommand ();

        //movement axis
        movCommand.LateralAxis = Input.GetAxis (LEFT_RIGHT_AXIS_NAME);
        movCommand.FrontAxis = Input.GetAxis (BACK_FORWARD_AXIS_NAME);

        if(Input.GetAxis(JUMP_AXIS_NAME) > 0)
        {
            movCommand.AddButton(ActionFlags.Jump);
        }

        return movCommand;
    }
        public void CreateMovementCommand_ValidRightFullForward_InitializesProperly()
        {
            string rawCommand = "<RF255F255F255>";
            MovementCommand command = new MovementCommand(rawCommand);

            Assert.AreEqual(command.MotorSide, "R", "Should be \"R\"");
            Assert.AreEqual(command.Motor1Speed, 255, "Should be 255");
            Assert.AreEqual(command.Motor2Speed, 255, "Should be 255");
            Assert.AreEqual(command.Motor3Speed, 255, "Should be 255");
            Assert.AreEqual(command.Motor1Direction, "F", "Should be \"F\"");
            Assert.AreEqual(command.Motor2Direction, "F", "Should be \"F\"");
            Assert.AreEqual(command.Motor3Direction, "F", "Should be \"F\"");
        }
 public void CreateMovementCommand_NullStringInserted_ThrowsArgumentNullException()
 {
     string rawCommand = null;
     Assert.Throws<System.ArgumentNullException>(
         delegate
         {
             MovementCommand command = new MovementCommand(rawCommand);
         }
     );
 }
        public void CreateMovementCommand_Motor3SpeedLowerThanMin_ThrowsArgumentException()
        {
            string rawCommand = "<LF255F255F-50>";

            Assert.Throws<System.ArgumentException>(
                delegate
                {
                    MovementCommand command = new MovementCommand(rawCommand);
                }
            , "Command sent: " + rawCommand);
        }
        public void CreateMovementCommand_Motor2SpeedHigherThanMax_ThrowsArgumentException()
        {
            string rawCommand = "<LF255F999F255>";

            Assert.Throws<System.ArgumentException>(
                delegate
                {
                    MovementCommand command = new MovementCommand(rawCommand);
                }
            , "Command sent: " + rawCommand);
        }
        public void CreateMovementCommand_InvalidSideIdentifier_ThrowsArgumentException()
        {
            string rawCommand = "<XF255F255F255>";

            Assert.Throws<System.ArgumentException>(
                delegate
                {
                    MovementCommand command = new MovementCommand(rawCommand);
                }
            , "Command sent: " + rawCommand);
        }