Exemple #1
0
    public override void SimulateController()
    {
        base.SimulateController();

        IPlayerMoveCommandInput moveCommand = PlayerMoveCommand.Create();

        Vector2 move = new Vector2();

        if (Input.GetKey(KeyCode.A) && isGrounded)
        {
            //Left move
            move += Vector2.left * acceleration;
        }

        if (Input.GetKey(KeyCode.D) && isGrounded)
        {
            //Right move
            move += Vector2.right * acceleration;
        }

        moveCommand.velocity = move;

        if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
        {
            moveCommand.jump = true;
        }

        if (Input.GetKeyDown(KeyCode.Return))
        {
            moveCommand.fire = true;
        }

        entity.QueueInput(moveCommand);
    }
Exemple #2
0
    public static void EnemyAttack()
    {
        foreach (EnemyBehaviour enemy in instance.activeEnemies)
        {
            if (enemy.Active != false)
            {
                Transform target = CharacterObserver.GetEnemyTarget();
                if (target != null)
                {
                    PlayerMoveCommand move = new PlayerMoveCommand();
                    move.AssignMove(enemy.transform, enemy.transform.position, target.position);
                    PlayerCommand.AddCommand(move);

                    AttackCommand attack = new AttackCommand();
                    attack.AssignCommand(10, target.gameObject);
                    attack.AssignAnimation(enemy.gameObject, "Attack", 0f);
                    PlayerCommand.AddCommand(attack);

                    PlayerMoveCommand move2 = new PlayerMoveCommand();
                    move2.AssignMove(enemy.transform, target.position, enemy.transform.position);
                    PlayerCommand.AddCommand(move2);
                }
            }
        }
    }
    public static PlayerMoveCommand Deserialize(string json)
    {
        JSONObject        jsonObject        = new JSONObject(json);
        PlayerMoveCommand playerMoveCommand = new PlayerMoveCommand();

        playerMoveCommand.ClientId  = jsonObject.GetField("clientId").str;
        playerMoveCommand.Direction = jsonObject.GetField("direction").str;
        return(playerMoveCommand);
    }
Exemple #4
0
        public void NoLogWrittenForNullMove()
        {
            player1.JumpTo(0, 1);
            var command = new PlayerMoveCommand {
                Player = player1, Direction = Direction.Left
            };

            command.Execute(game, log);

            Assert.AreEqual(0, log.Messages.Count);
        }
Exemple #5
0
        public void MoveCommandWritesToLog()
        {
            player1.JumpTo(1, 1);
            var command = new PlayerMoveCommand {
                Player = player1, Direction = Direction.Up
            };

            command.Execute(game, log);

            Assert.AreEqual(1, log.Messages.Count);
        }
Exemple #6
0
        public void MoveCommandTriggersPlayerMove()
        {
            player1.JumpTo(1, 1);
            var command = new PlayerMoveCommand {
                Player = player1, Direction = Direction.Up
            };

            command.Execute(game, log);

            Assert.AreEqual(game.Board.SlotAt(1, 0), player1.Position);
        }
Exemple #7
0
        public IEnumerator PlayerMoveCommand(Vector3 endPosition, ResultData <PlayerMoveResult> result)
        {
            var starTime = DateTime.UtcNow;

            var command = new PlayerMoveCommand(_context, endPosition);

            yield return(command.Run());

            result.SetData(command.GetResult());
            var endTime = DateTime.UtcNow;
            var comp    = new Dictionary <string, string>();

            comp["arg"]    = $"<{endPosition}>";
            comp["result"] = $"<{result.GetData().FailMove.ToString()}>";
            _context.SendCommandLog(CommandsId.PlayerMove, starTime, endTime, comp);
        }
Exemple #8
0
        public void Update(UpdaterParameters parameters)
        {
            parameters.ThrowIfNull("parameters");

            if (_worldInstance.WorldTime.Paused || _worldInstance.PlayerInput.Suspended || parameters.Focus != Focus.Player)
            {
                return;
            }

            _keyboardRepeatHelper.InitialInterval   = TimeSpan.FromMilliseconds(Constants.PlayerRenderer.Input.InitialInterval.TotalMilliseconds / _worldInstance.WorldTime.Speed);
            _keyboardRepeatHelper.RepeatingInterval = TimeSpan.FromMilliseconds(Constants.PlayerRenderer.Input.RepeatingInterval.TotalMilliseconds / _worldInstance.WorldTime.Speed);

            _keyboardStateHelper.Update();

            TimeSpan totalWorldTime = _worldInstance.WorldTime.Total;

            if (!_keyboardRepeatHelper.IntervalElapsed(totalWorldTime) || totalWorldTime - _lastKeyDownTotalWorldTime < _keyboardRepeatHelper.RepeatingInterval)
            {
                return;
            }

            PlayerMoveCommand command = null;

            switch (_keyboardStateHelper.LastKeyDown)
            {
            case Constants.PlayerRenderer.Input.MoveUpKey:
                command = Commands.PlayerMove(MoveDirection.Up);
                break;

            case Constants.PlayerRenderer.Input.MoveDownKey:
                command = Commands.PlayerMove(MoveDirection.Down);
                break;

            case Constants.PlayerRenderer.Input.MoveLeftKey:
                command = Commands.PlayerMove(MoveDirection.Left);
                break;

            case Constants.PlayerRenderer.Input.MoveRightKey:
                command = Commands.PlayerMove(MoveDirection.Right);
                break;
            }

            _lastKeyDownTotalWorldTime = totalWorldTime;
            _worldInstance.CurrentCommandQueue.EnqueueCommand(command);
        }
    public override void ActivateAction()
    {
        originPosition = Performer.transform.position;
        PlayerMoveCommand moveCommand = new PlayerMoveCommand();

        moveCommand.AssignMove(Performer, Performer.position, Target.position);
        PlayerCommand.AddCommand(moveCommand);

        AttackCommand attackCommand = new AttackCommand();

        attackCommand.AssignCommand(Damage, Target.gameObject);
        attackCommand.AssignAnimation(Performer.gameObject, animationTrigger, actionDuration);
        PlayerCommand.AddCommand(attackCommand);

        PlayerMoveCommand returnCommand = new PlayerMoveCommand();

        returnCommand.AssignMove(Performer, Target.position, originPosition);
        PlayerCommand.AddCommand(returnCommand);
    }
Exemple #10
0
        public override List <Cell> Attack(PlayerMoveCommand cmd)
        {
            var affectedCells = new List <Cell>();

            cmd.Execute(affectedCells);

            if (player1.Field.NumberOfShips == 0 || player2.Field.NumberOfShips == 0)
            {
                game.State = new GameFinishedState();
            }

            if (player1.Field.NumberOfShips == 0)
            {
                game.Winner = 1;
            }

            if (player2.Field.NumberOfShips == 0)
            {
                game.Winner = 0;
            }

            return(affectedCells);
        }
 private void When(PlayerMoveCommand playerMoveCommand)
 {
     Update(_roomName, world => world.MovePlayer(playerMoveCommand.PlayerId, playerMoveCommand.Position, playerMoveCommand.Rotation));
 }
Exemple #12
0
 public List <Cell> Attack(PlayerMoveCommand move)
 {
     return(State.Attack(move));
 }
Exemple #13
0
 abstract public List <Cell> Attack(PlayerMoveCommand move);
 public override List <Cell> Attack(PlayerMoveCommand move)
 {
     return(new List <Cell>());
 }