Exemple #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            screenWidth  = graphics.PreferredBackBufferWidth;
            screenHeight = graphics.PreferredBackBufferHeight;

            mainTarget = DefaultTarget;

            tileTarget     = DefaultTarget;
            entityTarget   = DefaultTarget;
            postTileTarget = DefaultTarget;
            screenTarget   = DefaultTarget;

            drawingTarget = DefaultTarget;

            random = new Random();


            cameraPosition = Point.Zero;

            mousePos = new Point();

            TextureHandler.Initialize();

            GameID.Initialize();

            NpcHandler.Initialize();
            LevelHandler.Initialize();
            TileHandler.Initialize();

            base.Initialize();
        }
    void Start()
    {
        Manager = this;

        // If we find data from a previous floor, load it in
        GameObject     retainer          = GameObject.FindGameObjectWithTag("DataRetainer");
        PersistentData previousFloorData = null;

        if (retainer != null)
        {
            previousFloorData = retainer.GetComponent <DataRetainer>().data;
            Destroy(retainer);
        }

        // Initialize the sprite manager (possibly based on the previous floor's data)
        Sprites = GameObject.FindGameObjectWithTag("SpriteManager").GetComponent <SpriteManager>();
        if (previousFloorData != null)
        {
            Sprites.InitializeColors(previousFloorData.colors);
        }
        else
        {
            Sprites.InitializeColors();
        }

        // Initialize the tile handler
        TileHandler.Initialize();

        // Update the floor number if there was a previous floor
        Floor = (previousFloorData != null) ? previousFloorData.floor : FLOOR_START;

        // Victory condition
        if (Floor == 0)
        {
            SceneManager.LoadScene("Victory");
        }

        // Generate the new level
        Level = new Level(Floor, Random.Range(30, 40), Random.Range(30, 40));

        // Find the newly created player
        Player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();

        // Retreive the player's data if there was a previous floor
        if (previousFloorData != null)
        {
            Player.oldStats            = previousFloorData.playerStats;
            Player.oldPower            = previousFloorData.playerPower;
            Player.poisonDuration      = previousFloorData.poisonDuration;
            Player.poisonDamagePerTurn = previousFloorData.poisonDamage;
        }

        // Update the floor number on the UI
        Text floorText = GameObject.FindGameObjectWithTag("FloorValue").GetComponent <Text>();

        floorText.text = Floor.ToString();

        // Get a handle on the intro panel
        introPanel = GameObject.FindGameObjectWithTag("IntroPanel");
        if (previousFloorData != null)
        {
            introPanel.SetActive(false);
        }

        ShowPlayer();
    }