Exemple #1
0
    bool checkWalkable(Vector3 position, Vector3 direction)
    {
        Vector3 walkPosition      = position + direction;
        Vector3 floorCubePosition = walkPosition + new Vector3(0, -1, 0);

        SimplePathElement walkElement  = null;
        SimplePathElement floorElement = null;

        level.GetAllElements().TryGetValue(walkPosition, out walkElement);
        level.GetAllElements().TryGetValue(floorCubePosition, out floorElement);

        if (floorElement != null)
        {
            if (floorElement.topBarrier == Barrier.Walkable)
            {
                if (walkElement != null)
                {
                    if (walkElement.getBarrierByDirection(-direction) == Barrier.Walkable)
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Exemple #2
0
    //Liste aller benachbarten PathElements
    List <AStarObject> findAdjacents(AStarObject ao)
    {
        List <AStarObject> adjacents = new List <AStarObject>();

        //Check if curretn Position is PathElement
        SimplePathElement currentPositionElement = null;

        level.GetAllElements().TryGetValue(ao.getPosition(), out currentPositionElement);

        Vector3[] directions =
        {
            Vector3.forward,
            Vector3.back,
            Vector3.left,
            Vector3.right
        };

        if (currentPositionElement != null)
        {
            foreach (Vector3 direction in directions)
            {
                if (currentPositionElement.getBarrierByDirection(direction) == Barrier.Walkable)
                {
                    AStarObject newAO = getAdjacent(ao, ao.getPosition(), direction);
                    if (newAO != null)
                    {
                        adjacents.Add(newAO);
                    }
                }
            }
        }
        else
        {
            foreach (Vector3 direction in directions)
            {
                AStarObject newAO = getAdjacent(ao, ao.getPosition(), direction);
                if (newAO != null)
                {
                    adjacents.Add(newAO);
                }
            }
        }

        return(adjacents);
    }
Exemple #3
0
    AStarObject getAdjacent(AStarObject ao, Vector3 position, Vector3 direction)
    {
        Vector3 walkPosition      = position + direction;
        Vector3 floorCubePosition = walkPosition + new Vector3(0, -1, 0);

        SimplePathElement walkElement  = null;
        SimplePathElement floorElement = null;

        level.GetAllElements().TryGetValue(walkPosition, out walkElement);
        level.GetAllElements().TryGetValue(floorCubePosition, out floorElement);


        //Normal Walk
        if (walkElement != null)
        {
            if (walkElement.bottomBarrier == Barrier.Walkable && walkElement.getBarrierByDirection(-direction) == Barrier.Walkable)
            {
                //Adjazenz Block existiert
                return(new AStarObject(ao, position + direction));
            }
        }
        else
        {
            if (floorElement != null)
            {
                if (floorElement.topBarrier == Barrier.Walkable)
                {
                    //Adjazenz Block existiert
                    return(new AStarObject(ao, position + direction));
                }
            }
        }

        //Stairs Up
        if (walkElement != null)
        {
            if (walkElement.getBarrierByDirection(-direction) == Barrier.Stairs)
            {
                SimplePathElement aboveStairEntry         = null;
                Vector3           aboveStairEntryPosition = position + Vector3.up;
                level.GetAllElements().TryGetValue(aboveStairEntryPosition, out aboveStairEntry);
                if (aboveStairEntry == null)
                {
                    //checke Treppen Ende
                    return(getAdjacent(ao, position + direction + Vector3.up, direction));
                }
            }
        }

        //Stairs Down
        if (walkElement == null)
        {
            if (floorElement != null)
            {
                if (floorElement.topBarrier == Barrier.Stairs)
                {
                    if (floorElement.getBarrierByDirection(direction) == Barrier.Stairs)
                    {
                        SimplePathElement aboveStairExit         = null;
                        Vector3           aboveStairExitPosition = walkPosition + direction;
                        level.GetAllElements().TryGetValue(aboveStairExitPosition, out aboveStairExit);
                        if (aboveStairExit == null)
                        {
                            //checke Treppen Start
                            return(getAdjacent(ao, position + direction + Vector3.down, direction));
                        }
                    }
                }
            }
        }

        return(null);
    }