Esempio n. 1
0
 private static int CheckForDuplicateRooms(Room[,] rooms, Point p)
 {
     int foundRooms = 0;
     foreach (Room room in rooms)
     {
         if (room != null)
         {
             if (room.Location.X == p.X && room.Location.Y == p.Y)
                 foundRooms++;
         }
     }
     return foundRooms;
 }
Esempio n. 2
0
    public void Spawn(Vector3 trapPos, Vector3 leverPos)
    {
        GameStateManager gs = GameObject.Find("GameState").GetComponent <GameStateManager> ();
        MapGen           mg = GameObject.Find("TileGenParent").GetComponent <MapGen> ();

        int          layerMask = 1 << LayerMask.NameToLayer("Default");
        RaycastHit2D hit       = Physics2D.Raycast(trapPos, Vector2.up, Mathf.Infinity, layerMask);

        GameObject    trap     = gs.CreateOverNetworkInstant(trapPrefab, trapPos);
        SpringJoint2D joint    = trap.GetComponent <SpringJoint2D> ();
        Rigidbody2D   trapBody = trap.GetComponent <Rigidbody2D> ();

        Rigidbody2D colliderRigidbody = hit.collider.gameObject.AddComponent <Rigidbody2D> ();

        joint.connectedBody           = colliderRigidbody;
        joint.connectedAnchor         = joint.connectedBody.transform.InverseTransformPoint(hit.point);
        colliderRigidbody.constraints = RigidbodyConstraints2D.FreezeAll;

        GameObject   lever    = gs.CreateOverNetworkInstant(leverPrefab, leverPos);
        TrapDeployer deployer = lever.GetComponent <TrapDeployer> ();

        deployer.droppingTrap = trap;
        deployer.raisingTrap  = trap;

        MapGen.Room room   = mg.GetRandomRoom();
        float       deltaX = Random.value * mg.roomWidth;
        float       deltaY = Random.value * mg.roomHeight;
        Vector2     pos    = new Vector2(room.x + deltaX, room.y - deltaY);

        GameObject enemy = gs.CreateOverNetworkInstant(enemyPrefab, pos);

        tm = trap.GetComponent <TrapManager> ();
        tm.AddTarget(enemy, ((manager) => {
            Debug.Log("Captured enemy");
            GameObject.Find("GameState").GetComponent <GameStateManager>().ResetGame();
            return(true);
        }));
    }
Esempio n. 3
0
        private static Map GetStaticMap()
        {
            Room[,] rooms = new Room[3, 3];
            for (int x = 0; x < rooms.GetLength(0); x++)
                for (int y = 0; y < rooms.GetLength(1); y++)
                    rooms[x, y] = new Room(new Point(x, y));

            rooms[0, 0].SouthExit = new Exit(Directions.South);
            rooms[0, 0].EastExit = new Exit(Directions.East);

            rooms[1, 0].WestExit = new Exit(Directions.West);
            rooms[1, 0].EastExit = new Exit(Directions.East);

            rooms[2, 0].WestExit = new Exit(Directions.West);
            rooms[2, 0].SouthExit = new Exit(Directions.South);

            rooms[0, 1].NorthExit = new Exit(Directions.North);
            rooms[0, 1].EastExit = new Exit(Directions.East);
            rooms[0, 1].SouthExit = new Exit(Directions.South);

            rooms[0, 2].NorthExit = new Exit(Directions.North);
            rooms[0, 2].EastExit = new Exit(Directions.East);

            rooms[1, 1].WestExit = new Exit(Directions.West);

            rooms[1, 2].WestExit = new Exit(Directions.West);
            rooms[1, 2].EastExit = new Exit(Directions.East);

            rooms[2, 1].NorthExit = new Exit(Directions.North);
            rooms[2, 1].SouthExit = new Exit(Directions.South);

            rooms[2, 2].NorthExit = new Exit(Directions.North);
            rooms[2, 2].WestExit = new Exit(Directions.West);

            return new Map(rooms);
        }