Exemple #1
0
    /// <summary>
    /// Prepares the wall object for tile.
    /// </summary>
    /// <returns>
    /// Prepared wall object as dungeon object.
    /// </returns>
    /// <param name='code'>
    /// Code of tile.
    /// </param>
    /// <param name='objectType'>
    /// Object type.
    /// </param>
    /// <param name='prefabReference'>
    /// Prefab string reference to resource.
    /// </param>
    /// <param name='fromI'>
    /// I index of source tile.
    /// </param>
    /// <param name='fromJ'>
    /// J index of source tile.
    /// </param>
    /// <param name='toI'>
    /// I index of target tile.
    /// </param>
    /// <param name='toJ'>
    /// J index of target tile.
    /// </param>
    public static DungeonObject PrepareWallObject(int code, DungeonObjectType objectType, string prefabReference, int fromI, int fromJ, int toI, int toJ)
    {
        DungeonObject newDungeonObject = new DungeonObject(code, objectType, prefabReference);

        newDungeonObject.rotation = DungeonUtils.GetRotationFromToTile(fromI, fromJ, toI, toJ);
        newDungeonObject.offset   = newDungeonObject.rotation * new Vector3(0f, 0f, -DungeonUtils.TileSize * 0.5f);
        return(newDungeonObject);
    }
Exemple #2
0
    /// <summary>
    /// Checks the tile moveability.
    /// </summary>
    /// <returns>
    /// Can creature make move to tile in specified direction from current tile or can not.
    /// </returns>
    /// <param name='moveDirection'>
    /// Absolute direction of target tile relatively to current
    /// </param>
    protected bool CheckTileMoveability(Direction moveDirection)
    {
        DungeonDataTile tile = Dm.CurrentDungeon.Tiles [DungeonUtils.GetCodeOfTileByIndex(_currentI, _currentJ)];
        Quaternion      rot;

        // Get rotation that should have wall to stop moving
        switch (moveDirection)
        {
        case Direction.Forward:
            rot = DungeonUtils.GetRotationFromToTile(0, 0, 0, 1);
            break;

        case Direction.Right:
            rot = DungeonUtils.GetRotationFromToTile(1, 0, 0, 0);
            break;

        case Direction.Backward:
            rot = DungeonUtils.GetRotationFromToTile(0, 1, 0, 0);
            break;

        case Direction.Left:
            rot = DungeonUtils.GetRotationFromToTile(0, 0, 1, 0);
            break;

        default:
            return(false);
        }

        // Check if there is any wall nearly rotated against to movementDirection
        for (int i = 0; i < tile.Objects.Count; i++)
        {
            if (tile.Objects [i].type == DungeonObjectType.Wall && Quaternion.Angle(rot, tile.Objects [i].rotation) < 10)
            {
                return(false);
            }
        }

        return(true);
    }