示例#1
0
    // ----------------------------------------------------------------
    //  Doers
    // ----------------------------------------------------------------
    public void UpdateBeamView()
    {
        int numBeamSegments;

        // Oh, if my Beam has been destroyed, say it's got no segments; just stop rendering it completely. (There will be a small visual inconsistency, but it's almost impossible to notice.)
        if (!MyBeam.IsInPlay)
        {
            numBeamSegments = 0;
        }
        else
        {
            numBeamSegments = MyBeam.NumSegments;
        }
        // Make more segments if we need them!
        int numNewSegmentViews = numBeamSegments - segmentViews.Count;

        for (int i = 0; i < numNewSegmentViews; i++)
        {
            segmentViews.Add(GetNewSegmentView());
        }
        // Activate/deactivate the right ones!
        for (int i = 0; i < numBeamSegments; i++)
        {
            BoardOccupant   sourceOccupant = MyBeam.GetSegment(i).SourceOccupant;
            BoardObjectView sourceView     = MyBoardView.TEMP_GetObjectView(sourceOccupant);
            segmentViews[i].Activate(sourceView);
        }
        for (int i = numBeamSegments; i < segmentViews.Count; i++)
        {
            segmentViews[i].Deactivate();
        }
    }
示例#2
0
    //public int LastCol { get { return spacesOver[spacesOver.Count-1].Col; } }
    //public int LastRow { get { return spacesOver[spacesOver.Count-1].Row; } }

    public BeamSegment(Beam _myBeam, BoardOccupant _sourceOccupant)
    {
        MyBeam         = _myBeam;
        SourceOccupant = _sourceOccupant;
        spacesOver     = new List <BoardSpace>();
        AddSpace(SourceOccupant.MySpace);          // start with the space this segment originates from.
    }
示例#3
0
 public void RemoveMyOccupant(BoardOccupant _bo)
 {
     if (MyOccupant != _bo)
     {
         throw new UnityException("Oops! We're trying to remove a " + _bo.GetType() + " from a space that doesn't own it! " + Col + " " + Row + ".");
     }
     MyOccupant = null;
 }
示例#4
0
 public void SetMyOccupant(BoardOccupant _bo)
 {
     if (MyOccupant != null)
     {
         throw new UnityException("Oops! Trying to set a Space's Occupant, but that Space already has an Occupant! original: " + MyOccupant.GetType() + ", new: " + _bo.GetType().ToString() + ". " + Col + ", " + Row);
     }
     MyOccupant = _bo;
 }
    // ----------------------------------------------------------------
    //  Initialize / Destroy
    // ----------------------------------------------------------------
    override public void Initialize(BoardView _myBoardView, BoardObject bo)
    {
        MyBoardOccupant = bo as BoardOccupant;
        base.Initialize(_myBoardView, bo);

        // Make my beamRendererCollider!
        beamRendererCollider = new BeamRendererCollider(MyBoardView, this);

        //ApplyFundamentalVisualProperties ();
    }
示例#6
0
 /** Brute-force finds the corresponding BoardOccupantView. */
 public BoardObjectView TEMP_GetObjectView(BoardOccupant bo)
 {
     foreach (BoardObjectView objectView in allObjectViews)
     {
         if (objectView.MyBoardObject == bo)
         {
             return(objectView);
         }         // as BoardOccupantView; }
     }
     return(null); // oops.
 }
示例#7
0
    public static MoveResults MoveOccupant(Board b, BoardOccupant bo, Vector2Int dir)
    {
        // No dir?? Do nothing; return success!
        if (dir == Vector2Int.zero)
        {
            return(MoveResults.Success);
        }

        TranslationInfo ti        = GetTranslationInfo(b, bo.ColRow, dir);
        BoardSpace      spaceFrom = GetSpace(b, ti.from);
        BoardSpace      spaceTo   = GetSpace(b, ti.to);

        // Someone's null? Return Fail.
        if (bo == null || spaceTo == null)
        {
            return(MoveResults.Fail);
        }
        // We can't EXIT this space? Return Fail.
        if (!spaceFrom.MayOccupantEverExit(ti.dirOut))
        {
            return(MoveResults.Fail);
        }
        // We can't ENTER this space? Return Fail.
        if (!spaceTo.MayOccupantEverEnter(ti.dirIn))
        {
            return(MoveResults.Fail);
        }

        // Always remove its footprint first. We're about to move it!
        bo.RemoveMyFootprint();

        // Next space is OCCUPIED? Ok, try to move THAT fella, and return if fail!
        if (spaceTo.HasOccupant)
        {
            MoveResults result = MoveOccupant(b, ti.to, ti.dirOut);
            if (result != MoveResults.Success)
            {
                return(result);
            }
        }

        // Okay, we're good to move our original fella! Do!
        //int newSideFacing = GetNewSideFacing(b, bo.SideFacing, occPos, dir);
        bo.SetColRow(ti.to, ti.dirOut);
        bo.ChangeSideFacing(ti.sideDelta);
        bo.ChangeChirality(ti.chirDeltaH, ti.chirDeltaV);
        // Put footprint back down.
        bo.AddMyFootprint();

        // Return success!
        return(MoveResults.Success);
    }
示例#8
0
    private string Debug_GetPrintoutSpaceChar(int col, int row)
    {
        BoardOccupant occupant = GetOccupant(col, row);

        if (occupant == null)
        {
            return(".");
        }
        if (occupant is Player)
        {
            return("@");
        }
        if (occupant is Crate)
        {
            return("o");
        }
        return("?");
    }
示例#9
0
    private void AddSegmentRecursively(BoardOccupant _sourceOccupant)       //int _col,int _row, int _sideExiting) {
    // Create empty segment to populate, and add it to our list.
    {
        BeamSegment newSegment = new BeamSegment(this, _sourceOccupant);

        segments.Add(newSegment);
        int exitSide = _sourceOccupant.SideFacing;         // assume that we ALWAYS come OUT of any Occupant's SideFacing.

        //// HACK for chirality.
        //if (_sourceOccupant.ChirH < 0) {
        //    if (exitSide == Sides.L) { exitSide = Sides.R; }
        //    else if (exitSide == Sides.R) { exitSide = Sides.L; }
        //}
        //if (_sourceOccupant.ChirV < 0) {
        //    if (exitSide == Sides.B) { exitSide = Sides.T; }
        //    else if (exitSide == Sides.T) { exitSide = Sides.B; }
        //}
        AddSegmentSpaceRecursively(newSegment, exitSide);          // populate the segment (and maybe make more segments)!
    }