Exemple #1
0
 public void OnPointerClick(PointerEventData eventData)
 {
     if (HasItem())
     {
         if (cursorManager.isUsingUIObject)
         {
             if (isValidItemMatch(GetComponent <RawImage>().texture.name, cursorManager.itemName))
             {
                 string str = PerformTrade(GetComponent <RawImage>().texture.name, cursorManager.itemName);
                 GameObject.Find("Hero").GetComponent <MainCharacter>().Say(new string[] {
                     str
                 });
                 cursorManager.isUsingUIObject = false;
                 cursorManager.ResetCursor();
             }
             else
             {
                 GameObject.Find("Hero").GetComponent <MainCharacter>().Say(new string[] {
                     "That's a stupid idea, how is this getting through my head?"
                 });
             }
         }
         else
         {
             cursorManager.isUsingUIObject = true;
             cursorManager.SetCustomCursor(GetComponent <RawImage>().texture.name);
         }
     }
 }
Exemple #2
0
 void OnMouseExit()
 {
     if (!cursorManager.isUsingUIObject)
     {
         cursorManager.ResetCursor();
     }
     else
     {
         if (requiresItemForUse && validItemName == cursorManager.itemName)
         {
             cursorManager.SetInvalidCursorColor();
         }
     }
 }
Exemple #3
0
 void Update()
 {
     if (currentScene == Scene.TitleScreen)
     {
         if (Input.GetMouseButtonDown(0))
         {
             InteractiveObject interactive = cursorManager.GetCurrentTarget();
             if (interactive != null && GameObject.Find("StartGameButton") == interactive.gameObject)
             {
                 // start game
                 cursorManager.ResetCursor();
                 black.FadeIn(() => {
                     LoadScene(Scene.IntroText);
                 });
             }
         }
     }
     else if (currentScene == Scene.IntroText)
     {
         if (Input.GetMouseButton(0))
         {
             black.FadeIn(() => {
                 LoadScene(Scene.IntroMurder);
             });
         }
     }
     else if (currentScene == Scene.IntroMurder)
     {
         timer += Time.deltaTime;
         if (timer > 2 && timer < 27)
         {
             if (Camera.main.transform.position.x < 4.19)
             {
                 Camera.main.transform.Translate(new Vector3(Time.deltaTime, 0, 0));
             }
             else
             {
                 GameObject.Find("Killer").GetComponent <Killer>().Activate();
             }
         }
         else if (timer > 27)
         {
             black.FadeIn(() => {
                 LoadScene(Scene.IntroPoliceStation);
             });
         }
     }
     else if (currentScene == Scene.Ending)
     {
         timer += Time.deltaTime;
         if (timer > 3)
         {
             LoadScene(Scene.FinalEnd);
         }
     }
 }
Exemple #4
0
    void Update()
    {
        // If mouse is in the actual map area
        if (Input.mousePosition.x >= GameScreenScaler.VIEWPORT_PADDING_LEFT &&
            Input.mousePosition.y >= GameScreenScaler.VIEWPORT_PADDING_BOTTOM &&
            Input.mousePosition.x <= Screen.width - GameScreenScaler.VIEWPORT_PADDING_RIGHT &&
            Input.mousePosition.y <= Screen.height - GameScreenScaler.VIEWPORT_PADDING_TOP &&
            !m_TownScreen.Enabled)
        {
            Vector3    _WorldMousePos    = m_Camera.ScreenToWorldPoint(Input.mousePosition - new Vector3(0, 8, 0));
            Vector2Int _WorldMouseCoords = new Vector2Int
                                           (
                (int)(_WorldMousePos.x + 0.5f),
                (int)(-_WorldMousePos.y + 0.5f)
                                           );

            // If mouse has moved onto a different tile in the world
            if (m_PreviousWorldMouseCoords != _WorldMouseCoords ||
                m_UpdateCursor)
            {
                // If mouse coords are within the bounds of the map
                if (_WorldMouseCoords.x >= 0 &&
                    _WorldMouseCoords.y >= 0 &&
                    _WorldMouseCoords.x < m_GameSettings.Scenario.Size &&
                    _WorldMouseCoords.y < m_GameSettings.Scenario.Size)
                {
                    m_HoveredTown = null;
                    m_HoveredHero = null;

                    MapHero _SelectedHero = m_LocalOwnership.SelectedHero;

                    m_PreviousWorldMouseCoords = _WorldMouseCoords;
                    m_UpdateCursor             = false;

                    Pathfinding.Node _Node = m_Pathfinding.GetNode(_WorldMouseCoords, false);

                    List <MapObjectBase> _Objects = new List <MapObjectBase>(_Node.BlockingObjects.Count + _Node.InteractionObjects.Count);

                    for (int i = 0; i < _Node.BlockingObjects.Count; i++)
                    {
                        _Objects.Add(_Node.BlockingObjects[i]);
                    }

                    for (int i = 0; i < _Node.InteractionObjects.Count; i++)
                    {
                        _Objects.Add(_Node.InteractionObjects[i]);
                    }

                    // Flag used to break out of logic if an earlier bit of logic has already determined what the cursor should be
                    bool _CursorSelected = false;

                    int _TurnCost = 0;

                    if (_SelectedHero != null)
                    {
                        _TurnCost = _SelectedHero.GetPathingTurnCost(_WorldMouseCoords.x, _WorldMouseCoords.y);
                    }

                    // Check if any of the objects are heroes
                    for (int i = 0; i < _Objects.Count; i++)
                    {
                        MapHero _Hero = _Objects[i] as MapHero;

                        if (_Hero != null)
                        {
                            m_HoveredObject = _Hero;

                            if (_SelectedHero != null)
                            {
                                if (_SelectedHero == _Hero)
                                {
                                    CursorManager.SetCursor(m_HeroCursor, new Vector2(-12, 10));
                                }
                                else if (_Hero.IsPrison)
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break;

                                    case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break;

                                    case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break;

                                    default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break;
                                    }
                                }
                                else if (_Hero.PlayerIndex == m_GameSettings.LocalPlayerIndex)
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_TradeCursor, new Vector2(-8, 9)); break;

                                    case 2: CursorManager.SetCursor(m_TradeCursor2, new Vector2(-8, 9)); break;

                                    case 3: CursorManager.SetCursor(m_TradeCursor3, new Vector2(-8, 9)); break;

                                    default: CursorManager.SetCursor(m_TradeCursor4, new Vector2(-8, 9)); break;
                                    }
                                }
                                else
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_AttackCursor, new Vector2(-13, 13)); break;

                                    case 2: CursorManager.SetCursor(m_AttackCursor2, new Vector2(-13, 13)); break;

                                    case 3: CursorManager.SetCursor(m_AttackCursor3, new Vector2(-13, 13)); break;

                                    default: CursorManager.SetCursor(m_AttackCursor4, new Vector2(-13, 13)); break;
                                    }
                                }

                                _CursorSelected = true;
                            }
                            else if (!_Hero.IsPrison &&
                                     _Hero.PlayerIndex == m_GameSettings.LocalPlayerIndex)
                            {
                                CursorManager.SetCursor(m_HeroCursor, new Vector2(-12, 10));
                                m_HoveredHero = _Hero;

                                _CursorSelected = true;
                            }

                            break;
                        }
                    }

                    // Check if any of the objects are towns
                    if (!_CursorSelected)
                    {
                        for (int i = 0; i < _Objects.Count; i++)
                        {
                            MapTown _Town = _Objects[i] as MapTown;

                            if (_Town != null)
                            {
                                m_HoveredObject = _Objects[i];

                                int _XIndex = 8 - Mathf.Clamp(Mathf.CeilToInt(_Objects[i].transform.position.x - _WorldMousePos.x), 0, 7);
                                int _YIndex = 6 - Mathf.Clamp(Mathf.CeilToInt(_WorldMousePos.y - _Objects[i].transform.position.y), 0, 5);

                                // If the cursor is specifically on the castle's entrance, horse rear cursor
                                if (_SelectedHero != null &&
                                    _XIndex == 5 &&
                                    _YIndex == 5)
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break;

                                    case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break;

                                    case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break;

                                    default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break;
                                    }
                                }
                                else if (_Town.PlayerIndex == m_GameSettings.LocalPlayerIndex)
                                {
                                    CursorManager.SetCursor(m_CastleCursor, new Vector2(-12, 12));
                                    m_HoveredTown = _Town;
                                }
                                else
                                {
                                    CursorManager.ResetCursor();
                                }

                                _CursorSelected = true;

                                break;
                            }
                        }
                    }

                    // If a hero is currently selected, set movement cursor
                    if (_SelectedHero != null)
                    {
                        if (!_CursorSelected)
                        {
                            // If the mouse is on an interaction tile, horse rear cursor
                            if (_Objects.Count > 0)
                            {
                                int _XIndex = 8 - Mathf.Clamp(Mathf.CeilToInt(_Objects[0].transform.position.x - _WorldMousePos.x), 0, 7);
                                int _YIndex = 6 - Mathf.Clamp(Mathf.CeilToInt(_WorldMousePos.y - _Objects[0].transform.position.y), 0, 5);

                                if ((_Objects[0].InteractionCollision[_YIndex] & 1 << _XIndex) != 0)
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break;

                                    case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break;

                                    case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break;

                                    default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break;
                                    }

                                    _CursorSelected = true;
                                }
                            }
                        }

                        if (!_CursorSelected)
                        {
                            // If the mouse is on the end point of the current selected destination, horse rear cursor
                            if (_SelectedHero.GetTargetDestination() == _WorldMouseCoords)
                            {
                                switch (_TurnCost)
                                {
                                case 0: CursorManager.ResetCursor(); break;

                                case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break;

                                case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break;

                                case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break;

                                default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break;
                                }
                            }
                            else
                            {
                                switch (_TurnCost)
                                {
                                case 0: CursorManager.ResetCursor(); break;

                                case 1: CursorManager.SetCursor(m_MoveCursor, new Vector2(-15, 13)); break;

                                case 2: CursorManager.SetCursor(m_MoveCursor2, new Vector2(-15, 13)); break;

                                case 3: CursorManager.SetCursor(m_MoveCursor3, new Vector2(-15, 13)); break;

                                default: CursorManager.SetCursor(m_MoveCursor4, new Vector2(-15, 13)); break;
                                }
                            }

                            _CursorSelected = true;
                        }
                    }

                    if (!_CursorSelected)
                    {
                        CursorManager.ResetCursor();
                    }
                }
                else
                {
                    CursorManager.ResetCursor();
                }
            }

            if (Input.GetMouseButtonDown(0))
            {
                if (m_HoveredTown != null)
                {
                    if (m_HoveredTown != m_LocalOwnership.SelectedTown)
                    {
                        m_LocalOwnership.SelectTown(m_HoveredTown);
                    }
                    else
                    {
                        m_TownScreen.OpenTown(m_HoveredTown);
                    }
                }
                else if (m_LocalOwnership.SelectedHero != null)
                {
                    if (m_LocalOwnership.SelectedHero.IsMoving)
                    {
                        m_LocalOwnership.SelectedHero.CancelMovement();
                    }
                    else
                    {
                        m_LocalOwnership.SelectedHero.OnLeftClick(_WorldMouseCoords.x, _WorldMouseCoords.y, m_HoveredObject);
                    }
                }
                else if (m_HoveredHero != null)
                {
                    m_LocalOwnership.SelectHero(m_HoveredHero);
                }

                m_UpdateCursor = true;
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (m_LocalOwnership.SelectedHero != null)
                {
                    if (m_LocalOwnership.SelectedHero.IsMoving)
                    {
                        m_LocalOwnership.SelectedHero.CancelMovement();
                    }
                }
            }

            m_UpdateCursor = true;
            CursorManager.ResetCursor();
        }

        if (!m_TownScreen.Enabled)
        {
            if (Input.mousePosition.x <= 2)
            {
                if (Input.mousePosition.y <= 2)
                {
                    CursorManager.SetCursor(m_BottomLeftCursor, new Vector2(0, 18));
                }
                else if (Input.mousePosition.y >= Screen.height - 3)
                {
                    CursorManager.SetCursor(m_TopLeftCursor, new Vector2(0, 1));
                }
                else
                {
                    CursorManager.SetCursor(m_LeftCursor, new Vector2(0, 5));
                }
            }
            else if (Input.mousePosition.x >= Screen.width - 3)
            {
                if (Input.mousePosition.y <= 2)
                {
                    CursorManager.SetCursor(m_BottomRightCursor, new Vector2(-18, 18));
                }
                else if (Input.mousePosition.y >= Screen.height - 3)
                {
                    CursorManager.SetCursor(m_TopRightCursor, new Vector2(-18, 1));
                }
                else
                {
                    CursorManager.SetCursor(m_RightCursor, new Vector2(-23, 6));
                }
            }
            else
            {
                if (Input.mousePosition.y <= 2)
                {
                    CursorManager.SetCursor(m_BottomCursor, new Vector2(-6, 23));
                }
                else if (Input.mousePosition.y >= Screen.height - 3)
                {
                    CursorManager.SetCursor(m_TopCursor, new Vector2(-6, 0));
                }
            }
        }
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        float horizontalMovement = 0;

        if (canMove && !cursorManager.isUsingUIObject)
        {
            horizontalMovement = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
        }

        if (Input.GetMouseButtonDown(0) && !cursorManager.isHoveringUI)
        {
            if (chatManager.IsActive())
            {
                chatManager.Next();
            }
            else
            {
                nextTarget = cursorManager.GetCurrentTarget();
                if (cursorManager.isUsingUIObject)
                {
                    if (cursorManager.isValidItemUsage)
                    {
                        walkingToTarget = false;
                    }
                    else
                    {
                        cursorManager.isUsingUIObject = false;
                        cursorManager.ResetCursor();
                        Say(new string[] { "That's not gonna work." });
                    }
                }
                else
                {
                    if (nextTarget == null)
                    {
                        nextMovePositionX = Camera.main.ScreenToWorldPoint(Input.mousePosition).x;
                        walkingToTarget   = true;
                    }
                    else
                    {
                        walkingToTarget = false;
                    }
                }
            }
        }

        if (Math.Abs(horizontalMovement) > 0)
        {
            // clear target and give control back as user is using keyboard
            walkingToTarget = false;
            nextTarget      = null;
        }

        if (walkingToTarget && Math.Abs(nextMovePositionX - transform.position.x) > threshold)
        {
            horizontalMovement = speed * Time.deltaTime *
                                 (nextMovePositionX < transform.position.x ? -1 : 1);
        }
        else if (nextTarget != null)
        {
            InteractiveObject actor        = nextTarget;
            float             distToTarget = Math.Abs(nextTarget.transform.position.x - transform.position.x);
            if (((actor.canInspect || actor.canUse || actor.canEnter) && distToTarget > threshold) ||
                (actor.canTalk && distToTarget > 1.5))
            {
                horizontalMovement = speed * Time.deltaTime *
                                     (nextTarget.transform.position.x < transform.position.x ? -1 : 1);
            }
            else
            {
                // we reached the target, time to act upon it
                nextTarget = null;
                actor.Act();
                if (actor.canInspect || actor.canUse)
                {
                    SetSprite(faceUp);
                }
            }
        }

        if (horizontalMovement == 0 && state != State.Whistling && state != State.Idle)
        {
            state       = State.Idle;
            idleCounter = 0;
        }
        else if (horizontalMovement < 0 && state != State.WalkingLeft)
        {
            state              = State.WalkingLeft;
            animCounter        = 0;
            currentSpriteIndex = 0;
        }
        else if (horizontalMovement > 0 && state != State.WalkingRight)
        {
            state              = State.WalkingRight;
            animCounter        = 0;
            currentSpriteIndex = 0;
        }

        if (Math.Abs(horizontalMovement) > 0 && !chatManager.IsActive())
        {
            transform.Translate(horizontalMovement, 0, 0);
            bool isStopped = false;
            if (horizontalMovement < 0 && transform.position.x < leftBound.position.x + leftBound.localScale.x)
            {
                transform.position = new Vector3(leftBound.position.x + leftBound.localScale.x,
                                                 transform.position.y, transform.position.z);
                isStopped = true;
            }
            if (horizontalMovement > 0 && transform.localPosition.x > rightBound.localPosition.x)
            {
                transform.position = new Vector3(rightBound.position.x, transform.position.y, transform.position.z);
                isStopped          = true;
            }
            if (isStopped)
            {
                walkingToTarget = false;
            }
        }

        if (chatManager.IsActive())
        {
        }
        else
        {
            // set correct sprite
            if (state == State.Idle)
            {
                SetSprite(idle);
                idleCounter += Time.deltaTime;
                if (idleCounter > idleMaxTime)
                {
                    state = State.Whistling;
                    SetSprite(whistle[0]);
                    currentSpriteIndex = 0;
                    animCounter        = 0;
                }
            }
            else
            {
                Sprite[] spriteArray;
                if (state == State.WalkingLeft)
                {
                    spriteArray = walkLeft;
                }
                else if (state == State.WalkingRight)
                {
                    spriteArray = walkRight;
                }
                else
                {
                    spriteArray = whistle;
                }
                if (animCounter > animSpeed || animCounter == 0)
                {
                    animCounter        = 0;
                    currentSpriteIndex = (currentSpriteIndex + 1) % 2;
                    SetSprite(spriteArray[currentSpriteIndex]);
                }
                animCounter += Time.deltaTime;
            }
        }
    }