Advertisement
Guest User

MazeCreator.cs

a guest
Nov 9th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.38 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MazeCreator{
  5.  
  6.         MazeMatrixS maze;
  7.         //private uint animHandler;
  8.         private int step;
  9.        
  10.    
  11.         void Start() {
  12.             createMaze();
  13.         }
  14.    
  15.         private void createMaze() {
  16.             maze = new MazeMatrixS.MazeMatrix(/*widthSlider.value*/10, /*heightSlider.value*/10, 0, 0, true);
  17.            
  18.             // Clear animation timer if runned
  19.             /*if (animHandler) clearInterval(animHandler);
  20.            
  21.             if (animCb.selected)
  22.             {
  23.                 // Set animation timer
  24.                 animHandler = setInterval(drawStep, 5);
  25.             }
  26.             else
  27.             {*/
  28.                 step = 0;
  29.                 redrawMaze();
  30.             //}
  31.         }
  32.    
  33.         /*private void drawStep()   {
  34.             int i = Mathf.Pow(animSpeedSlider.value, 2);
  35.             while (--i && maze.doStep()) {}
  36.             if (!maze.doStep())
  37.             {
  38.                 clearInterval(animHandler);
  39.                 animHandler = 0;
  40.             }
  41.             redrawMaze();
  42.         }*/
  43.        
  44.         private void redrawMaze(/*UIComponent view = null*/) {
  45.             float lineThick = /*thicknessSlider.value*/2;
  46.             float startX = lineThick / 2;
  47.             float startY = lineThick / 2;
  48.             int cellW = /*sizeSlider.value*/20;
  49.             int cellH = /*sizeSlider.value*/20;
  50.             int cData;
  51.            
  52.             //if (!view) view = mazeView;
  53.             //view.setStyle('borderWeight', lineThick);
  54.            
  55.             //view.graphics.clear();
  56.             //view.width  = cellW * maze.width  + lineThick;
  57.             //view.height = cellH * maze.height + lineThick;
  58.            
  59.             //with (view.graphics)
  60.             {
  61.                 for (int cx = 0; cx < maze.width; ++cx)
  62.                 {
  63.                     for (int cy = 0; cy < maze.height; ++cy)
  64.                     {
  65.                         cData = maze.getCell(cx, cy);
  66.                         //lineStyle(lineThick, (cData & MazeMatrix.CELL_VISITED) ? 0x000000 : 0xCCCCCC);            ???
  67.                         if ((cy > 0) && (cData>0 & MazeMatrixS.WALL_TOP>0)) {
  68.                             Debug.DrawLine(new Vector3(startX + cx * cellW, startY + cy * cellH, 0), new Vector3(startX + cx * cellW + cellW, startY + cy * cellH, 0));
  69.                             /*moveTo(startX + cx * cellW, startY + cy * cellH);
  70.                             lineTo(startX + cx * cellW + cellW, startY + cy * cellH);*/
  71.                         }
  72.                        
  73.                         if ((cx > 0) && (cData>0 & MazeMatrixS.WALL_LEFT>0)) {
  74.                             Debug.DrawLine(new Vector3(startX + cx * cellW, startY + cy * cellH, 0), new Vector3(startX + cx * cellW, startY + cy * cellH + cellH, 0));
  75.                             /*moveTo(startX + cx * cellW, startY + cy * cellH);
  76.                             lineTo(startX + cx * cellW, startY + cy * cellH + cellH);*/
  77.                         }
  78.                     }
  79.                 }
  80.                    
  81.                     // Display routre stack
  82.                     /*for (int i = 0; i < maze.activeRoute.length; ++i)
  83.                     {
  84.                         MazeIndex p = maze.activeRoute[i];
  85.                         lineStyle();
  86.                         beginFill(0xFF9999, 1);
  87.                         drawRect(startX + p.x * cellW + cellW/4, startY + p.y * cellH + cellH/4, cellW/2, cellH/2);
  88.                         endFill();
  89.                     }*/
  90.    
  91.                     /*// Draw start position
  92.                     lineStyle();
  93.                     beginFill(0x55FF11, 1);
  94.                     drawCircle(startX + maze.startX * cellW + cellW / 2, startY + maze.startY * cellH + cellH / 2, cellW / 2.5);
  95.                     endFill();
  96.    
  97.                     // Draw finish position
  98.                     lineStyle();
  99.                     beginFill(0xFF6611, 1);
  100.                     drawRect(startX + maze.finishX * cellW + 2, startY + maze.finishY * cellH + 2, cellW - 4, cellH - 4);
  101.                     endFill();*/
  102.                 }
  103.             }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement