コード例 #1
0
ファイル: MoveStep.cs プロジェクト: Franziskus/DiamondJam
 /// <summary>
 /// Creates a MoveStep. 
 /// </summary>
 /// <param name="moves">Moves for this step</param>
 /// <param name="time">Maximum time to complete the step (a Gem drops from top to bottom of the field)</param>
 public MoveStep(GemMove[] moves, float time)
 {
     this.moves = moves;
     this.time = time;
 }
コード例 #2
0
        /// <summary>
        /// Bring all gems down. 
        /// </summary>
        /// <param name="updateHorizontalArray">Update horizontal array.</param>
        private GemMove[] FallingDown(int[] updateHorizontalArray)
        {
            int width = updateHorizontalArray.Length;
            List<IntVector2> fallingBlocksStart = new List<IntVector2>();
            List<IntVector2> fallingBlocksSEnd = new List<IntVector2>();

            for(int x = 0; x < width; x++){
                bool firstRun = true;
                if(updateHorizontalArray[x] !=-1){
                    // this column needs an update
                    int currentY = updateHorizontalArray[x];
                    bool somethingToMove = true;
                    while(currentY > -1 && somethingToMove){
                        somethingToMove = false;
                        //if there is a item now we can start one item up
                        if(level.GetItem(new IntVector2(x,currentY)) != null){
                            currentY--;
                        }
                        // if there is space bring them all one down
                        for(int y = currentY-1; y >= 0; y--){
                            IntVector2 currentXY = new IntVector2(x,y+1);
                            IntVector2 currentXYTop = new IntVector2(x,y);
                            if(level.GetItem(currentXY) == null){
                                level.SetItem(currentXY, level.GetItem(currentXYTop));
                                if(level.GetItem(currentXYTop) != null){
                                    if(firstRun){
                                        fallingBlocksStart.Add(currentXYTop);
                                        fallingBlocksSEnd.Add(currentXY);
                                    }else{
                                        int pos = fallingBlocksSEnd.IndexOf(currentXYTop);
                                        if(pos != -1){
                                            fallingBlocksSEnd[pos] = currentXY;
                                        }else{
                                            string s = "try to move a not found object?\n";
                                            s += "Look for "+currentXYTop+"\n";
                                            for(int i = 0; i < fallingBlocksSEnd.Count; i++)
                                                s+= fallingBlocksSEnd[i].ToString() + ", ";
                                            Debug.LogWarning(s);
                                        }
                                }
                                }
                                level.SetItem(currentXYTop, null);
                            }
                        }
                        //if there are items over the currentY pos we need to loop more.
                        for(int y = currentY-1; y >= 0 && !somethingToMove; y--){
                            if(level.GetItem(new IntVector2(x,y+1)) != null)
                                somethingToMove = true;
                        }
                        firstRun = false;
                    }
                }
            }
            GemMove[] fallingMoves = new GemMove[fallingBlocksStart.Count];
            for(int i = 0; i < fallingMoves.Length; i++){
                fallingMoves[i].from = fallingBlocksStart[i];
                fallingMoves[i].to = fallingBlocksSEnd[i];
            }
            return fallingMoves;
        }