Exemplo n.º 1
0
        public void OnPlayerMove(PlayerMoveEvent ev)
        {
            var fromChunkX = ev.From.X >> 4;
            var fromChunkY = ev.From.Y >> 4;

            var toChunkX = ev.From.X >> 4;
            var toChunkY = ev.From.Y >> 4;

            var toChunk = Server.Map.GetChunk(toChunkX, toChunkY);

            var nearPlayers = ev.Player.GetPlayersNear();
            var movePacket  = new PlayerMovePacket()
            {
                From   = ev.From,
                To     = ev.To,
                UserId = ev.Player.UserId
            };

            foreach (var nearPlayer in nearPlayers)
            {
                nearPlayer.Tcp.Send(movePacket);
            }

            // Changed chunk
            if (fromChunkX != toChunkX || fromChunkY != toChunkY)
            {
                var fromChunk = Server.Map.GetChunk(fromChunkX, fromChunkY);

                fromChunk.PlayersInChunk.Remove(ev.Player);
                toChunk.PlayersInChunk.Add(ev.Player);
            }
        }
Exemplo n.º 2
0
        private bool PlayerMoveEvent(PlayerLocation from, PlayerLocation to, bool teleport = false)
        {
            PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(this, from, to, teleport);

            EventDispatcher.DispatchEvent(playerMoveEvent);
            return(!playerMoveEvent.IsCancelled);
        }
        private void CheckMoveInput()
        {
            var direction = Vector3.zero;

            if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
            {
                direction += Vector3.forward;
            }

            if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
            {
                direction += Vector3.left;
            }

            if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
            {
                direction += Vector3.back;
            }

            if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
            {
                direction += Vector3.right;
            }

            var playerMoveEvent = new PlayerMoveEvent(direction);

            _eventManager.Publish(playerMoveEvent);
        }
        private void OnPlayerMove(PlayerMoveEvent eventdata)
        {
            if (_playerTransform == null || _cameraTransform == null)
            {
                return;
            }

            _cameraTransform.position = _playerTransform.position;
        }
Exemplo n.º 5
0
    public void Trigger()
    {
        Vector2 move = new Vector2(
            Input.GetAxis(Constants.HORIZONTAL_AXIS),
            Input.GetAxis(Constants.VERTICAL_AXIS)
            );

        PlayerMoveEvent.TriggerEvent(move);
    }
 void Start()
 {
     DeathEvent.ListenForPlayerDeathEvent(Die);
     DeathEvent.ListenForPlayerFallingEvent(DieByFalling);
     PlayerMoveEvent.Listen(MoveByEvent);
     cameraMain = Camera.main;
     rigidbody  = GetComponent <Rigidbody2D>();
     collider   = GetComponent <BoxCollider2D>();
     animator   = GetComponent <Animator>();
     torch      = GameObject.FindWithTag(Constants.TORCH_TAG);
     SetDirection();
 }
        private void OnPlayerMove(PlayerMoveEvent eventData)
        {
            if (_playerSceneObjectComponent == null)
            {
                return;
            }

            var playerTransform = _playerSceneObjectComponent.GameObject.transform;

            playerTransform.Translate(eventData.Direction * _playerMovementComponent.Speed * Time.deltaTime, Space.World);
            playerTransform.LookAt(playerTransform.position + eventData.Direction);
        }
Exemplo n.º 8
0
    public override void MoveTo(Vector3 position, Quaternion rotation)
    {
        //only the server is allowed to move other players
        if (!BoltNetwork.isServer)
        {
            Debug.LogError("Only the server is allowed to move other players!");
            throw new System.NotImplementedException();
        }
        //tell the other player to move!
        PlayerMoveEvent evnt = PlayerMoveEvent.Create(PlayerRegistry.GetConnectionFromUserName(Username), Bolt.ReliabilityModes.ReliableOrdered);

        evnt.NewPosition = position;
        evnt.NewRotation = rotation;
        evnt.Send();
    }
Exemplo n.º 9
0
        [EventMethod] // When client finishes updating assets
        public void OnPlayerMovePath(PlayerMovePacket packet)
        {
            var player              = Server.GetPlayerByConnectionId(packet.ClientId);
            var distanceMoved       = player.GetPosition().GetDistance(packet.To);
            var timeToMove          = Formulas.GetTimeToMoveBetweenTwoTiles(player.speed);
            var now                 = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            var lastMovementArrival = now + timeToMove;

            // Player tryng to hack ?
            if (distanceMoved > 1 || now < player.CanMoveAgainTime)
            {
                // send player back to the position client-side
                player.Tcp.Send(new SyncPacket()
                {
                    Position = player.GetPosition()
                });
                return;
            }

            var playerMoveEvent = new PlayerMoveEvent()
            {
                From   = packet.From,
                To     = packet.To,
                Player = player
            };

            ServerEvents.Call(playerMoveEvent);

            if (playerMoveEvent.IsCancelled)
            {
                // send player back to the position client-side
                player.Tcp.Send(new SyncPacket()
                {
                    Position = player.GetPosition()
                });
                return;
            }

            // subtract the player latency for possibility of lag for a smoother movement
            player.CanMoveAgainTime = now + timeToMove - player.Tcp.Latency;

            // Updating player position locally
            player.X = packet.To.X;
            player.Y = packet.To.Y;

            // updating in database
            PlayerService.UpdatePlayerPosition(player, player.X, player.Y);
        }
Exemplo n.º 10
0
    public void Receive(IEvent InEvent)
    {
        PlayerMoveEvent MoveEvent = InEvent as PlayerMoveEvent;

        if (MoveEvent != null)
        {
            ApplyMovement(MoveEvent);
        }

        PlayerPickupEvent PickupEvent = InEvent as PlayerPickupEvent;

        if (PickupEvent != null)
        {
            ApplyPickup(PickupEvent.m_Data);
        }
    }
Exemplo n.º 11
0
    public void onPlayerMove(PlayerMoveEvent ev)
    {
        Location location = ev.getLocation();
        World    world    = location.getWorld();

        Vector3 movement = ev.getMovement();

        Direction moveDirection   = DirectionMethods.getDominantDirection(movement);
        Location  ordinalMovement = moveDirection.ordinal(world) * Chunk.chunkSize;

        ChunkLocation playerChunkLocation = ChunkLocation.asChunkLocation(location + ordinalMovement);

        loadChunksInRange(playerChunkLocation);

        unloadChunksOutOfRange(playerChunkLocation);
    }
Exemplo n.º 12
0
        public void OnPlayerMove(PlayerMoveEvent e)
        {
            if (e.Player.HealthManager.IsDead || e.Player.GameMode == GameMode.Spectator)
            {
                return;
            }

            var pos = new BlockCoordinates(e.Player.KnownPosition);
            // pos.Y -= 1;

            var blockBelow = Game.Level.GetBlock(pos);

            if (blockBelow.IsSolid)
            {
                DestroyBlock(blockBelow);
            }
        }
Exemplo n.º 13
0
    private void ApplyMovement(PlayerMoveEvent InMoveEvent)
    {
        m_PlayerBody.AddForce(m_PlayerBody.transform.forward * InMoveEvent.m_Forward + m_PlayerBody.transform.right * InMoveEvent.m_Right, ForceMode.VelocityChange);

        RaycastHit Hit;

        Physics.Raycast(m_PlayerBody.position, Vector3.down, out Hit);

        if (InMoveEvent.m_Jump && Hit.distance <= 1.0f)
        {
            m_PlayerBody.AddForce(m_PlayerBody.transform.up * m_PlayerData.m_JumpForce);
        }

        Rotation += InMoveEvent.m_LookAt * 4.0f;

        m_PlayerBody.rotation = Quaternion.Euler(0, Rotation, 0);
    }
Exemplo n.º 14
0
    private void HandlePlayerMove(RealmEventBase baseEvent)
    {
        PlayerMoveEvent playerMoveEvent = baseEvent as PlayerMoveEvent;
        Vector2Int      playerPosition  = RealmStateManager.GetRealmState().GetPlayerState(playerMoveEvent.playerId).GetPosition();
        IReadHexState   hexState        = RealmStateManager.GetRealmState().GetMapState().GetHexState(playerPosition);

        if (hexState.IsVisible())
        {
            if (hexState.GetTerrain().Equals("GRASS"))
            {
                instance.tilemap.SetTile((Vector3Int)playerPosition, instance.grassTile);
            }
            else
            {
                instance.tilemap.SetTile((Vector3Int)playerPosition, instance.waterTile);
            }
        }
    }
Exemplo n.º 15
0
 // Update is called once per frame
 protected override void BaseUpdate()
 {
     //Fire Event on moving the player
     if (Input.GetKey(KeyCode.D))
     {
         PlayerMoveEvent.FireEvent(new PlayerMoveEvent());
         playerBody.velocity += new Vector3(1 * moveSpeed, 0, 0);
     }
     if (Input.GetKey(KeyCode.A))
     {
         PlayerMoveEvent.FireEvent(new PlayerMoveEvent());
         playerBody.velocity += new Vector3(1 * -moveSpeed, 0, 0);
     }
     if (Input.GetKey(KeyCode.W))
     {
         PlayerMoveEvent.FireEvent(new PlayerMoveEvent());
         playerBody.velocity += new Vector3(0, 0, 1 * moveSpeed);
     }
     if (Input.GetKey(KeyCode.S))
     {
         PlayerMoveEvent.FireEvent(new PlayerMoveEvent());
         playerBody.velocity += new Vector3(0, 0, 1 * -moveSpeed);
     }
 }
 private void MoveByEvent(Hashtable h)
 {
     rigidbody.velocity = PlayerMoveEvent.Read(h);
     FlipSpriteAndLightIfNeeded(rigidbody.velocity.x);
 }
Exemplo n.º 17
0
 public override void OnEvent(PlayerMoveEvent evnt)
 {
     GameManager.instance.CurrentPlayer.MoveTo(evnt.NewPosition, evnt.NewRotation);
 }
Exemplo n.º 18
0
    private void HandlePlayerMove(RealmEventBase baseEvent)
    {
        PlayerMoveEvent playerMoveEvent = baseEvent as PlayerMoveEvent;

        Debug.Log("Player Moved: " + playerMoveEvent.direction);
    }
Exemplo n.º 19
0
    public void HandlePlayerMove(RealmEventBase baseEvent)
    {
        PlayerMoveEvent playerMoveEvent = baseEvent as PlayerMoveEvent;

        if (playerMoveEvent.playerId.Equals(playerId))
        {
            Vector3Int currentCell     = mapGrid.WorldToCell(transform.position);
            Vector3Int destinationCell = currentCell;

            switch (playerMoveEvent.direction)
            {
            case "1":
                destinationCell.x = currentCell.x + 1;
                destinationCell.y = currentCell.y;
                break;

            case "2":
                if (currentCell.y % 2 == 0)
                {
                    destinationCell.x = currentCell.x;
                }
                else
                {
                    destinationCell.x = currentCell.x + 1;
                }
                destinationCell.y = currentCell.y - 1;
                break;

            case "3":
                if (currentCell.y % 2 == 0)
                {
                    destinationCell.x = currentCell.x - 1;
                }
                else
                {
                    destinationCell.x = currentCell.x;
                }
                destinationCell.y = currentCell.y - 1;
                break;

            case "4":
                destinationCell.x = currentCell.x - 1;
                destinationCell.y = currentCell.y;
                break;

            case "5":
                if (currentCell.y % 2 == 0)
                {
                    destinationCell.x = currentCell.x - 1;
                }
                else
                {
                    destinationCell.x = currentCell.x;
                }
                destinationCell.y = currentCell.y + 1;
                break;

            case "6":
                if (currentCell.y % 2 == 0)
                {
                    destinationCell.x = currentCell.x;
                }
                else
                {
                    destinationCell.x = currentCell.x + 1;
                }
                destinationCell.y = currentCell.y + 1;
                break;

            default:
                break;
            }

            this.transform.position = mapGrid.CellToWorld(destinationCell);
        }
    }
Exemplo n.º 20
0
        public override bool ProcessKeyboard(KeyboardInfo info)
        {
            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.N)))
            {
                NewGameEvent?.Invoke(this, new EventArgs());
                return(true);
            }

            if (!_game.Player.IsAlive)
            {
                return(false);
            }

            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.T)))
            {
                PlayerTeleportEvent?.Invoke(this, new EventArgs());
                return(true);
            }

            var keyHit    = false;
            var direction = new Point();

            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Up)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad8)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad7)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad9)))
            {
                direction.Y = -1;
                keyHit      = true;
            }
            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Down)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad2)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad1)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad3)))
            {
                direction.Y += 1;
                keyHit       = true;
            }
            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Left)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad4)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad7)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad1)))
            {
                direction.X -= 1;
                keyHit       = true;
            }
            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Right)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad6)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad9)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad3)))
            {
                direction.X += 1;
                keyHit       = true;
            }

            if (keyHit)
            {
                PlayerMoveEvent?.Invoke(this, new PlayerMoveEventArgs(direction));
            }

            return(keyHit);
        }
Exemplo n.º 21
0
 public void Trigger()
 {
     PlayerMoveEvent.TriggerEvent(new Vector2(1, 0));
 }
 public override void OnEvent(PlayerMoveEvent evnt)
 {
     GameManager.instance.CurrentPlayer.MoveTo(evnt.NewPosition, evnt.NewRotation);
 }
Exemplo n.º 23
0
    // Update is called once per frame
    void Update()
    {
        if (eventsManager == null)
        {
            eventsManager = gameManager.getEventsManager();
        }

        //Get the key pressed and multiply it by the speed modifier, also smooth the movement with deltaTime;
        float horizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
        float vertical   = Input.GetAxis("Vertical") * speed * Time.deltaTime;
        //The position is Vector3 so we ignore z by setting it to 0
        Vector3 movement = new Vector3(horizontal, 0f, vertical);

        if (movement.magnitude == 0)
        {
            animator.SetInteger("State", 0);
            return;
        }
        if (world == null)
        {
            world = gameManager.getWorld();
        }

        Location location = new Location(world, transform.position);

        //Call the player move event and only continue with the code if the event isn't cancelled
        PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(location, movement);

        eventsManager.callEvent(playerMoveEvent);

        if (playerMoveEvent.isCanceled())
        {
            return;
        }

        //Add it to the current position
        this.transform.position += movement;

        if (horizontal > 0)
        {
            animator.SetInteger("State", -1);
            if (horizontal == 0)
            {
                animator.SetInteger("State", 5);
            }
            // else
            // animator.SetInteger("State", -1);
        }
        else if (horizontal < 0)
        {
            animator.SetInteger("State", 4);
            if (horizontal == 0)
            {
                animator.SetInteger("State", 1);
            }
            //else
            // animator.SetInteger("State", 4);
        }
        if (vertical > 0)
        {
            animator.SetInteger("State", 2);
            if (vertical == 0)
            {
                animator.SetInteger("State", 0);
            }
            // else
            // animator.SetInteger("State", 2);
        }
        else if (vertical < 0)
        {
            animator.SetInteger("State", 6);
            if (vertical == 0)
            {
                animator.SetInteger("State", 3);
            }
            //else
            // animator.SetInteger("State", 6);
        }
        //if(horizontal == 0 && vertical == 0) {
        //    animator.SetInteger("State", 0);
        //}



        //See the difference?
        //        //if(Input.GetAxis("Horizontal")) This can be used instead of GetKey, as it allows you to change the keys in Unity.
        //		if (Input.GetKey (KeyCode.W))
        //		{
        //			transform.position += new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);
        //			animator.SetInteger ("State", 2);
        //		}
        //		if (Input.GetKey (KeyCode.S))
        //		{
        //			transform.position -= new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);
        //			animator.SetInteger ("State", 6);
        //		}
        //		if (Input.GetKey (KeyCode.D))
        //		{
        //			transform.position += new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
        //			animator.SetInteger ("State", -1);
        //		}
        //		if (Input.GetKey (KeyCode.A))
        //		{
        //			transform.position -= new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
        //			animator.SetInteger ("State", 4);
        //		}
    }