Ejemplo n.º 1
0
 public bool GenerateNext()
 {
     if (myfloor.FloorSize < myfloor.PathSize)
     {
         myfloor.CreatePath();
         //Debug.Log("GenerateNext did createpath(): " + loadtest);
         loadtest++;
         return(true);
     }
     else
     {
         if (!GenerateNextShortCircuit)
         {
             if (isNewFloor)
             {
                 //last room was created last frame, so add the next stair case
                 PlaceStairs();
                 //after stairs are created, craft enemies at 30% chance of having enemies per room, with mobs between min and max.
                 PlaceEnemies(rate: 0.9f, min: 1, max: 5);
             }
             //let the floor produce the room models.
             //if webgl use this
             //myfloor.CreateRoomModelsWebGL(roomTexture);
             //for pc use this
             myfloor.CreateRoomModels(myfloor.ThemePath);
             //let the floor do it's first update() run (fixes locations of rooms)
             myfloor.Update();
             //Debug.Log("RandomAssignCalled~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
             myfloor.RandomAssignDoorModels();
             GenerateNextShortCircuit = true;
             isNewFloor = false;
         }
         //let the floor do it's first update() run (fixes locations of rooms)
         //myfloor.Update();
         //playerObject.GetComponent<UnitBehavior>().SetOverworldDestination(Vector3.zero);
         return(false);
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Generates the specified floor level by walking the floor, then assigning models.
    /// Assumes that the floor exists in our "floors" object to load from, otherwise generates a new one.
    /// </summary>
    /// <param name="floorlevel"></param>
    public void EnterFloor(int floorlevel)
    {
        playerObject.GetComponent <UnitBehavior>().SetOverworldDestination(Vector3.zero);
        Debug.Log("enterring floor " + floorlevel + " of " + TotalFloors);
        started = true;
        myfloor.RandomAssignDoorModelsShort = false;
        GenerateNextShortCircuit            = false;
        //if we have previous floors to deal with, save them, then destroy their models.
        if (CurrentFloor >= 0)
        {
            //save the floor we are on (put it inside the floors list)
            //TODO we do this when we generate the floor. do we really need to do it again?
            //if (CurrentFloor < floors.count)
            //use currentfloor for deleting old floor models.
            Debug.Log("DESTROYING A FLOOR~~~~~~~~~~~~~~~");
            foreach (WRoom o in floors[CurrentFloor].map)
            {
                o.DestroyModels();
                //also completely remove
                o.DisposeDeadContents();
            }
        }
        //otherwise we are new and we can assume we had no previous floors
        else
        {
            //if we don't have a label on the player, add one.
            if (playerObject.GetComponent <HealthOverTarget>() == null)
            {
                playerObject.AddComponent <HealthOverTarget>();
            }
        }

        CurrentFloor = floorlevel;
        //if we request a floor greater than our total number of floors, reset our character in the overworld, undo our started aspect, and delete our floors list.
        //if the requested floor exists, load it. (there are no models, it needs to reassign models.)
        //else begin generating a new floor.
        if (CurrentFloor >= TotalFloors || CurrentFloor < 0)
        {
            /*
             * //if we have this tag element, remove it.
             * if (playerObject.GetComponent<HealthOverTarget>() != null)
             * {
             *  HealthOverTarget n = playerObject.GetComponent<HealthOverTarget>();
             *  Destroy(n);
             * }
             */
            playerObject.transform.position = playeroverworldspawnpoint;
            playerObject.GetComponent <UnitBehavior>().SetOverworldDestination(playerObject.transform.position);
            started = false;
            foreach (WFloor f in floors)
            {
                f.DestroyFloor();
            }
            floors.Clear();
            //Destroy(floors);
            floors       = new List <WFloor>();
            CurrentFloor = 0;
            Start();
            playerHasBeenPlaced = true;
            GameObject.Find("Camera").GetComponent <CameraControllerOfflineScript>().Target2 = null;
            Debug.Log("returning to overworld");
            System.GC.Collect();
            //return player to entrance?
            //return;
        }
        // requested floor exists and is not < 0.
        else if (CurrentFloor < floors.Count)
        {
            //GenerateNextShortCircuit = true;
            myfloor         = floors[CurrentFloor];
            myfloor.Yoffset = -20 * (CurrentFloor + 1);
            myfloor.CreateRoomModels(myfloor.ThemePath);
            myfloor.Update();
            playerHasBeenPlaced = false;
        }
        // floor does not exist, must be made.
        else
        {
            myfloor           = new WFloor();
            myfloor.roomWidth = RoomWidth;
            myfloor.minSize   = (int)(MinRooms * Mathf.Pow(PerFloorRoomScaling, CurrentFloor));
            myfloor.maxSize   = (int)(MaxRooms * Mathf.Pow(PerFloorRoomScaling, CurrentFloor));
            myfloor.ThemePath = ThemePath;
            myfloor.Yoffset   = -20 * (CurrentFloor + 1);
            myfloor.Start(roomprefab);
            isNewFloor = true;
            loadtest   = 0; //counts number of times createpath gets called
            GenerateNext();
            floors.Add(myfloor);
            playerHasBeenPlaced = false;
        }
        //Debug.Log("setting player's location to the first room in the map.");
        //playerObject.transform.position= myfloor.map[0].model.transform.position;
    }