Example #1
0
 // Use this for initialization
 void Start()
 {
     laserToggle  = GetComponent <LaserToggle>();
     lineRenderer = GetComponent <LineRenderer>();
     i            = 0;
     wellDone     = false;
     templates[0].transform.position = showing.transform.position;
     for (int j = 1; j < templates.Length; ++j)
     {
         templates[j].transform.position = hiding.transform.position;
     }
 }
Example #2
0
        //Create Laser + Toggle pairs
        private void CreateLasers()
        {
            Wall laser;

            Color[] colors = new Color[11] {
                Color.Plum, Color.Gold, Color.LightGreen, Color.Tomato, Color.Orange, Color.Orchid,
                Color.PaleTurquoise, Color.Purple, Color.RoyalBlue, Color.SkyBlue, Color.YellowGreen
            };
            int  laserCount = 0;
            bool hasToggle  = false;

            LaserToggle toggle = new LaserToggle(game);

            for (int y = 0; y < boardInfo.height - 1; y++)
            {
                if (laserCount < boardInfo.nLasers)
                {
                    for (int x = 0; x < boardInfo.width - 1; x++)
                    {
                        if (laserCount < boardInfo.nLasers)
                        {
                            //If the node is not a hole and not the first cell
                            if (nodes[x, y] != null && !(y == 1 && x == 1))
                            {
                                //If the node is empty
                                if (nodes[x, y].isEmpty)
                                {
                                    //Create a vector
                                    Vector2 pos1     = new Vector2(x, y);
                                    bool    occupied = false;

                                    //Check all the enemies
                                    foreach (EnemyObject enemy in enemyObjects)
                                    {
                                        //this node is already taken!
                                        if (enemy.position == pos1)
                                        {
                                            occupied = true;
                                            break;
                                        }
                                    }

                                    if (!occupied)
                                    {
                                        //Check all the win objects
                                        foreach (WinObject winObj in winObjects)
                                        {
                                            //this node is already taken!
                                            if (winObj.position == pos1)
                                            {
                                                occupied = true;
                                                break;
                                            }
                                        }

                                        if (!occupied)
                                        {
                                            if (portals.Count > 0)
                                            {
                                                //Check all the previously created portals
                                                foreach (Portal port in portals)
                                                {
                                                    //this node can't be taken - it's too close to another portal!
                                                    if ((Math.Abs(port.pos1.X - pos1.X) < 2 && Math.Abs(port.pos1.Y - pos1.Y) < 2) ||
                                                        (Math.Abs(port.pos2.X - pos1.X) < 2 && Math.Abs(port.pos2.Y - pos1.Y) < 2))
                                                    {
                                                        occupied = true;
                                                        break;
                                                    }
                                                }
                                            }

                                            if (!occupied)
                                            {
                                                if (!hasToggle)
                                                {
                                                    //Create toggle
                                                    toggle.position = new Vector2(x, y);
                                                    hasToggle       = true;
                                                }
                                                else
                                                {
                                                    LaserToggle toggleCopy = new LaserToggle(game);
                                                    toggleCopy.position = toggle.position;

                                                    //Create laser
                                                    laser          = new Wall(this, game);
                                                    laser.position = new Vector2(x, y);
                                                    laser.color    = colors[lasers.Count];
                                                    this.Node(laser.position).isEmpty = false;

                                                    //Create Laser-Toggle pair
                                                    lasers.Add(toggleCopy, laser);
                                                    laserCount++;

                                                    hasToggle = false;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }