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);
}
}