DodongosQuest.Screens.Gameplay.SideBar.IntersectsWith C# (CSharp) Method

IntersectsWith() public method

public IntersectsWith ( Vector2 position ) : bool
position Vector2
return bool
        public bool IntersectsWith(Vector2 position)
        {
            if (position.X >= _position.X && position.X <= _position.X + _width)
                if (position.Y >= _position.Y && position.Y <= _position.Y + _height)
                    return true;

            return false;
        }

Usage Example

示例#1
0
        private void TouchOrMouse(Vector2 pos)
        {
            if (_messageBox.IntersectsWith(new Vector2(pos.X, pos.Y)))
            {
                Announcer.Instance.Announce("Clicked message box.", MessageTypes.Other);
            }
            else if (_sideBar.IntersectsWith(new Vector2(pos.X, pos.Y)))
            {
                Announcer.Instance.Announce("Clicked side bar.", MessageTypes.Other);
            }
            else if (_inventory.IntersectsWith(new Vector2(pos.X, pos.Y)))
            {
                Announcer.Instance.Announce("Clicked inventory.", MessageTypes.Other);
            }
            else if (_spells.IntersectsWith(new Vector2(pos.X, pos.Y)))
            {
                //Announcer.Instance.Announce("Clicked spells.", MessageTypes.Other);
                int spellOffset = _spells.GetSpellAt(new Vector2(pos.X, pos.Y));
                if (spellOffset > -1)
                {
                    Announcer.Instance.Announce("Clicked spells: " + spellOffset, MessageTypes.Other);
                    AttemptToUseSpell(spellOffset);
                }
            }
            else
            {
                // clicked the map
                Vector2 clickedWorldIndex = _world.ConvertScreenPositionToTileIndex(pos.X, pos.Y);

                if (_state == GameState.PlayerTurn)
                {
                    ICreature target = _world.GetCreatureAtIndex(clickedWorldIndex);
                    if (target != null)
                    {
                        _world.Player.AttackCreature(ref target);
                        _state = GameState.ComputerTurn;
                    }
                    else
                    {
                        if (_world.PlayerCanSeeWorldIndex(clickedWorldIndex))
                        {
                            // a cheese hack toward getting touch sort of working
                            Vector2 delta = clickedWorldIndex - _world.Player.WorldIndex;
                            if (delta.X < 0)
                            {
                                if (_world.MovePlayerInDirectionSuccessful(Direction.West))
                                {
                                    _state = GameState.ComputerTurn;
                                }
                            }
                            if (delta.X > 0)
                            {
                                if (_world.MovePlayerInDirectionSuccessful(Direction.East))
                                {
                                    _state = GameState.ComputerTurn;
                                }
                            }
                            if (delta.Y < 0)
                            {
                                if (_world.MovePlayerInDirectionSuccessful(Direction.North))
                                {
                                    _state = GameState.ComputerTurn;
                                }
                            }
                            if (delta.Y > 0)
                            {
                                if (_world.MovePlayerInDirectionSuccessful(Direction.South))
                                {
                                    _state = GameState.ComputerTurn;
                                }
                            }
                            _world.CenterCameraOnPlayer();
                        }
                    }
                }
                else if (_state == GameState.PlayerTurnSelectingDoorToClose)
                {
                    if (_world.CloseDoorAtPositionSuccessful(clickedWorldIndex, _world.Player.WorldIndex))
                    {
                        _state = GameState.ComputerTurn;
                    }
                    else
                    {
                        Announcer.Instance.Announce("Door at location does not exist or can't be closed.", MessageTypes.Other);
                        _state = GameState.PlayerTurn;
                    }
                }
                else if (_state == GameState.PlayerTurnSelectingTargetForSpell)
                {
                    Vector2 targetIndex = clickedWorldIndex;
                    if (_selectedSpell.TargetCanMove == false)
                    {
                        targetIndex = _world.Player.WorldIndex;
                    }
                    if (_selectedSpell.CastSpell(_world.Player, targetIndex) == true)
                    {
                        _state = GameState.ComputerTurn;
                    }
                    else
                    {
                        _state = GameState.PlayerTurn;
                    }
                }

                Announcer.Instance.Announce(clickedWorldIndex.X + ", " + clickedWorldIndex.Y, MessageTypes.Other);
            }
        }