Пример #1
0
        public void ShowPath(IList <Position> pathPoints, float score)
        {
            if (!pathPoints.Any())
            {
                return;
            }
            var line         = new GameObject("PathFragment");
            var lineRenderer = line.AddComponent <LineRenderer>();

            SetupLineRenderer(pathPoints, lineRenderer);
            int      middlePathPointIndex = pathPoints.Count / 2;
            Position labelPositionInGrid  = pathPoints[middlePathPointIndex];
            Vector3  labelPosition        = _unityGridInfoProvider.GetCellCenterWorld(labelPositionInGrid);

            line.transform.position = labelPosition;
            var label = line.AddComponent <Label>();

            label.Text = score.ToString();

            foreach (var Position in pathPoints)
            {
                var            node       = new GameObject("MyPathNode");
                SpriteRenderer nodeSprite = node.AddComponent <SpriteRenderer>();
                nodeSprite.sortingLayerName   = "HUD";
                nodeSprite.transform.position = _unityGridInfoProvider.GetCellCenterWorld(Position);
                nodeSprite.sprite             = Resources.Load <Sprite>(@"Sprites\Characters\Misc_tiles\19");
                Object.Destroy(node.gameObject, 10.0f);
            }

            Object.Destroy(line.gameObject, 8.0f);
        }
Пример #2
0
        public void MoveTo(Position sourceLogicalPosition, Position targetLogicalPosition)
        {
            InitialPosition  = _unityGridInfoProvider.GetCellCenterWorld(sourceLogicalPosition);
            AffectedPosition = _unityGridInfoProvider.GetCellCenterWorld(targetLogicalPosition);
            _animator.Play("GenericMove", 0, 0f);

            _animationState = EntityAnimationState.Moving;
        }
Пример #3
0
        private Collider2D[] GetCollidersInRange(Position targetPosition, int cellsRangeInVision, int layerMask)
        {
            Vector2 targetWorldPosition2D = _unityGridInfoProvider.GetCellCenterWorld(targetPosition);
            float   toCornerOfArea        = cellsRangeInVision * _unityGridInfoProvider.CellSize;
            var     bottomLeftCorner      = targetWorldPosition2D + new Vector2(-toCornerOfArea, -toCornerOfArea);
            var     topRightCorner        = targetWorldPosition2D + new Vector2(toCornerOfArea, toCornerOfArea);

            Collider2D[] hitColliders = Physics2D.OverlapAreaAll(bottomLeftCorner, topRightCorner, layerMask);
            return(hitColliders);
        }
Пример #4
0
        public void MoveTo(Position sourceLogicalPosition, Position targetLogicalPosition)
        {
            InitialPosition  = _unityGridInfoProvider.GetCellCenterWorld(sourceLogicalPosition);
            AffectedPosition = _unityGridInfoProvider.GetCellCenterWorld(targetLogicalPosition);
            if (_animator == null)
            {
                Debug.LogWarning("missing animator; start executed = " + _startExecuted);
            }
            else
            {
                _animator.Play("GenericMove", 0, 0f);
            }

            _animationState = EntityAnimationState.Moving;
        }
Пример #5
0
        // Update is called once per frame
        void Update()
        {
            Vector3  mousePositionOnScreen = Input.mousePosition;
            Vector3  worldMousePosition    = Camera.main.ScreenToWorldPoint(mousePositionOnScreen);
            Position mousePosition         = _unityGridInfoProvider.WorldToCell(worldMousePosition).ToPosition();
            Vector3  selectorWorldPosition = _unityGridInfoProvider.GetCellCenterWorld(mousePosition);

            if (_lastMousePositionOnScreen != mousePositionOnScreen)
            {
                _lastMousePositionOnScreen         = mousePositionOnScreen;
                _selectionImage.transform.position = selectorWorldPosition;

                if (!_contextManager.Current.PositionFlags.IsWithinBounds(mousePosition))
                {
                    return;
                }
                var        positionText   = new StringBuilder();
                GameEntity entityAtCursor = GetEntityAtCursor(mousePosition);
                if (entityAtCursor != null)
                {
                    positionText.Append(entityAtCursor.recipee.RecipeeName + Environment.NewLine);
                }

                _uiFacade.ShowEntityDetails(entityAtCursor);
                AddTerrainText(mousePosition, positionText);
                _uiFacade.SetHoveredPositionText(positionText.ToString());
            }
        }
Пример #6
0
        private void Play(AudioClip soundToPlay)
        {
            Position playerPosition      = _context.GetPlayerEntity().position.Position;
            Vector3  playerWorldPosition = _unityGridInfoProvider.GetCellCenterWorld(playerPosition);

            AudioSource.PlayClipAtPoint(soundToPlay, playerWorldPosition);
        }
Пример #7
0
        public void Update()
        {
            if (_aim.activeInHierarchy == false)
            {
                Position playerPosition      = _context.GetPlayerEntity().position.Position;
                Vector3  playerWorldPosition = _unityGridInfoProvider.GetCellCenterWorld(playerPosition);
                _aim.transform.position = playerWorldPosition;
            }

            _aim.SetActive(true);

            bool noKeyIsPressed = !Input.anyKeyDown;

            if (noKeyIsPressed)
            {
                return;
            }


            _uiFacade.UiElementSelector.Deselect();
            Position direction = ReadDirection();

            if (direction == Position.Zero)
            {
                SwitchBackToDecisionMaking();
                return;
            }

            PlayerDecisionComponent decision = _context.playerDecision;

            _context.ReplacePlayerDecision(decision.Decision, direction, decision.Position);

            SwitchBackToDecisionMaking();
        }
Пример #8
0
        private PositionEffect FetchPositionEffectAtPosition(Position position)
        {
            if (_positionEffectPrefab == null)
            {
                _positionEffectPrefab = Resources.Load <PositionEffect>("Prefabs/UI/" + nameof(PositionEffect));
            }
            Vector3        position3            = _unityGridInfoProvider.GetCellCenterWorld(position);
            GameObject     positionEffectObject = PoolingManager.Fetch(PoolingManager.PositionEffect, position3, Quaternion.identity);
            PositionEffect positionEffect       = positionEffectObject.GetComponent <PositionEffect>();

            return(positionEffect);
        }
Пример #9
0
    public void Show(IFloodArea floodArea)
    {
        if (!gameObject.activeInHierarchy)
        {
            return;
        }
        List <Text> numbersInPoolBeforeStart = _numbersInPool.ToList();

        foreach (Position position in floodArea.Bounds.AllPositions())
        {
            Position numberPosition           = position;
            Vector3  worldPositionOfNewNumber = _unityGridInfoProvider.GetCellCenterWorld(numberPosition);
            Text     textChild = PlaceChild(numbersInPoolBeforeStart, worldPositionOfNewNumber);
            int      value     = floodArea.GetValueAtPosition(position);
            textChild.text = value == int.MaxValue ? "-" : value.ToString();
        }
    }
Пример #10
0
        public void Update()
        {
            Position playerPosition = _context.GetPlayerEntity().position.Position;

            if (_aim.activeInHierarchy == false)
            {
                Vector3 playerWorldPosition = _unityGridInfoProvider.GetCellCenterWorld(playerPosition);
                _aim.transform.position = playerWorldPosition;
            }

            _aim.SetActive(true);

            bool noKeyIsPressed = !Input.anyKey && !Input.anyKeyDown;            //osnowatodo && _contextManager.Current.SimulatedKeyDown == KeyCode.None;

            if (noKeyIsPressed)
            {
                _inputWithRepeating.ResetTime();
                return;
            }

            _uiFacade.UiElementSelector.Deselect();
            Position direction = ReadDirection();

            if (direction == Position.MinValue)             // escape
            {
                SwitchBackToDecisionMaking();
                return;
            }

            if (direction == Position.Zero)
            {
                // SwitchBackToDecisionMaking();
                return;
            }

            PlayerDecisionComponent decision = _context.playerDecision;
            Position newMarkerPosition       = decision.Position + direction;

            _context.ReplacePlayerDecision(decision.Decision, direction, newMarkerPosition);
            PresentSelectionPath(playerPosition, newMarkerPosition);

            // SwitchBackToDecisionMaking();
        }
Пример #11
0
        public virtual void Process()
        {
            Position position = _entity.position.Position;
            bool     visibleActorsAreClose = _entity.isPlayerControlled &&
                                             _entityDetector.DetectEntities(position, 4)
                                             .Any(e => e != _entity && e.hasEnergy && e.hasView && e.view.Controller.IsVisible);

            if (visibleActorsAreClose)
            {
                DateTime potentialBlockedUntil = DateTime.UtcNow + TimeSpan.FromMilliseconds(150);
                if (_entity.hasBlockedUntil)
                {
                    if (potentialBlockedUntil > _entity.blockedUntil.BlockedUntil)
                    {
                        _entity.ReplaceBlockedUntil(potentialBlockedUntil);
                    }
                }
                else
                {
                    _entity.AddBlockedUntil(potentialBlockedUntil);
                }
            }

            IViewController view           = _entity.view.Controller;
            IEntityAnimator entityAnimator = view.Animator;

            if (view.IsVisible)
            {
                bool playerActorIsNear = _entityDetector.DetectEntities(position, 5).Any(a => a.isPlayerControlled);
                if (playerActorIsNear)
                {
                    entityAnimator.MoveTo(PreviousPosition, position);
                }
            }
            Vector3 animationTargetPosition = _unityGridInfoProvider.GetCellCenterWorld(position);

            view.Transform.position = animationTargetPosition;
        }
Пример #12
0
 public void RefreshWorldPosition()
 {
     transform.position = _unityGridInfoProvider.GetCellCenterWorld(Entity.position.Position);
 }