示例#1
0
    public bool CanJumpByDelta(WorldEntity2D e, IntVector2D v)
    {
        // First Move Up, then Sideways!

        int maxHoriz = v[0];
        int maxVert  = v[1];

        int vertDir  = Mathf.RoundToInt(Mathf.Sign(maxVert));
        int horizDir = Mathf.RoundToInt(Mathf.Sign(maxHoriz));

        int vert = 0;

        while (Mathf.Abs(vert) < Mathf.Abs(maxVert))
        {
            vert += vertDir;
            if (!CanMoveByDelta(e, new IntVector2D(0, vert)))
            {
                return(false);
            }
        }
        int horiz = 0;

        while (Mathf.Abs(horiz) < Mathf.Abs(maxHoriz))
        {
            horiz += horizDir;
            if (!CanMoveByDelta(e, new IntVector2D(horiz, vert)))
            {
                return(false);
            }
        }
        return(true);
    }
示例#2
0
    public void RegisterEntity(WorldEntity2D e)
    {
        List <IntVector2D> all = e.AbsoluteLocations(e.Location);

        _worldEntities2D.Add(e);
        AddEntityTo2DLocations(all, e.Orientation, e);
    }
示例#3
0
    private bool IsEntity2DCovered(WorldEntity2D e)
    {
        List <IntVector2D> locations = e.AbsoluteLocations(e.Location);

        switch (e.Orientation)
        {
        case PlaneOrientation.XY:
            for (int i = 0; i < locations.Count; i++)
            {
                if (!PassableAtXY(locations[i]))
                {
                    return(false);
                }
            }
            break;

        case PlaneOrientation.ZY:
            for (int i = 0; i < locations.Count; i++)
            {
                if (!PassableAtZY(locations[i]))
                {
                    return(false);
                }
            }
            break;

        default:
            break;
        }
        return(true);
    }
示例#4
0
    public bool CanMoveByDelta(WorldEntity2D e, IntVector2D v)
    {
        IntVector2D        resLoc        = e.Location + v;
        List <IntVector2D> occupiedAfter = e.AbsoluteLocations(resLoc);

        // TODO(Julian): Take more than just shadows into account!

        int i;

        switch (e.Orientation)
        {
        case PlaneOrientation.XY:
            for (i = 0; i < occupiedAfter.Count; i++)
            {
                if (!PassableAtXY(occupiedAfter[i]))
                {
                    return(false);
                }
            }
            break;

        case PlaneOrientation.ZY:
            for (i = 0; i < occupiedAfter.Count; i++)
            {
                if (!PassableAtZY(occupiedAfter[i]))
                {
                    return(false);
                }
            }
            break;
        }

        return(true);
    }
示例#5
0
 void Awake()
 {
     _allStates         = (Char2DState[])Enum.GetValues(typeof(Char2DState));
     _animationStateIds = new int[_allStates.Length];
     for (int i = 0; i < _allStates.Length; i++)
     {
         _animationStateIds[i] = Animator.StringToHash(_allStates[i].ToString());
     }
     _animatorRotator = _animator.transform;
     _worldEntity     = GetComponent <WorldEntity2D>();
 }
示例#6
0
    private void Add2DEntityTo(IntVector2D v, PlaneOrientation planeOrientation, WorldEntity2D t)
    {
        HashSet <WorldEntity2D>[,] mapToModify = Map2DForOrientation(planeOrientation);
        var contents = mapToModify[v[0], v[1]];

        if (contents == null)
        {
            contents = new HashSet <WorldEntity2D>();
            mapToModify[v[0], v[1]] = contents;
        }
        contents.Add(t);
    }
示例#7
0
    void Update()
    {
        Profiler.BeginSample("2d sim");
        for (int i = 0; i < _worldEntities2D.Count; i++)
        {
            WorldEntity2D entity = _worldEntities2D[i];
            Profiler.BeginSample("Clear 2d loc");
            RemoveEntityFrom2DLocations(entity.AbsoluteLocations(entity.Location), entity.Orientation, entity);
            Profiler.EndSample();
            Profiler.BeginSample("Simulate 2d entity");
            entity.Simulate();
            Profiler.EndSample();
            Profiler.BeginSample("Fill 2d loc");
            AddEntityTo2DLocations(entity.AbsoluteLocations(entity.Location), entity.Orientation, entity);
            Profiler.EndSample();
        }
        Profiler.EndSample();

        Profiler.BeginSample("3d sim");
        for (int i = 0; i < _worldEntities.Count; i++)
        {
            WorldEntity entity = _worldEntities[i];
            Profiler.BeginSample("Clear 3d loc");
            List <IntVector> all = entity.AbsoluteLocations(entity.Location, entity.Rotation);
            Set3DLocationsToEntity(all, null);
            Profiler.EndSample();
            Profiler.BeginSample("Simulate 3d entity");
            entity.Simulate();
            Profiler.EndSample();
            Profiler.BeginSample("Fill 3d loc");
            all = entity.AbsoluteLocations(entity.Location, entity.Rotation);
            Set3DLocationsToEntity(all, entity);
            Profiler.EndSample();
        }
        Profiler.EndSample();
        Profiler.BeginSample("Shadow Sim");
        UpdateShadows();
        Profiler.EndSample();
    }
示例#8
0
 private void RemoveEntityFrom2DLocations(List <IntVector2D> locations, PlaneOrientation planeOrientation, WorldEntity2D e)
 {
     for (int i = 0; i < locations.Count; i++)
     {
         Remove2DEntityFrom(locations[i], planeOrientation, e);
     }
 }
示例#9
0
 private void AddEntityTo2DLocations(List <IntVector2D> locations, PlaneOrientation planeOrientation, WorldEntity2D e)
 {
     for (int i = 0; i < locations.Count; i++)
     {
         Add2DEntityTo(locations[i], planeOrientation, e);
     }
 }
示例#10
0
 void Awake()
 {
     _worldEntity = GetComponent <WorldEntity2D>();
 }