Esempio n. 1
0
        private Vector2Int GetOtherDirection(AbstractMovementManager other)
        {
            Vector3 heading   = transform.position - other.transform.position;
            float   distance  = heading.magnitude;
            Vector3 direction = heading / distance;

            return(new Vector2Int(Mathf.RoundToInt(direction.x), Mathf.RoundToInt(direction.z)));
        }
Esempio n. 2
0
        private AbstractMovementManager GetEntityToPush(MovementInstruction instruction)
        {
            Vector3    instructionDirection = new Vector3(instruction.Direction.x, GetOffset().y, instruction.Direction.y);
            RaycastHit entity;

            Physics.Raycast(transform.position, instructionDirection, out entity, 1f, interactionMask);

            if (entity.collider == null)
            {
                return(null);
            }

            AbstractMovementManager entityMovementManager = entity.collider.GetComponent <AbstractMovementManager>();

            return(entityMovementManager);
        }
Esempio n. 3
0
        private void CreateEntity(AbstractMovementManager prefab, Vector2Int position)
        {
            AbstractMovementManager entity           = Instantiate(prefab, transform);
            IEntityWithOffset       entityWithOffset = entity as IEntityWithOffset;

            entity.grid = this;

            if (entityWithOffset != null)
            {
                entityWithOffset.SetPosition(new Vector3(position.x, 0, position.y));

                return;
            }

            entity.transform.position = new Vector3(position.x, 0, position.y);
        }
Esempio n. 4
0
        public override bool IsValidMove(MovementInstruction instruction, int?playerLayer = null)
        {
            if (!base.IsValidMove(instruction))
            {
                return(false);
            }

            AbstractMovementManager entityToPush = GetEntityToPush(instruction);

            if (entityToPush == null)
            {
                return(true);
            }

            // Determine where the pushed entity will land
            MovementInstruction pushedEntityDirection = new MovementInstruction(instruction.Direction * 2);

            // Validate the position the pushed entity will land
            return(base.IsValidMove(pushedEntityDirection, entityToPush.gameObject.layer));
        }
Esempio n. 5
0
        private void Update()
        {
            if (OnRepel == null)
            {
                return;
            }

            AbstractMovementManager other = Detect();

            if (other != null)
            {
                MovementInstruction instruction = new MovementInstruction(GetOtherDirection(other));

                // TODO: This is broken

                if (movementManager.IsValidMove(instruction))
                {
                    OnRepel?.Invoke(instruction.Direction);
                }
            }
        }