예제 #1
0
        // tile constructor, pass a gamecontent manager and tiledata to load from
        public Tile(GameContent content_, GraphicsDevice graphicsDevice_, TileData tileData_)
        {
            Content         = content_;
            GraphicsDevice_ = graphicsDevice_;
            TileData        = tileData_;
            Position        = tileData_.Position;
            TileIndex       = tileData_.TileIndex;
            TerrainId       = tileData_.TerrainId;
            // set object from tiledata if not null, otherwise generate default tileobject
            Object = tileData_.Object ?? new TileObject();
            // get the texture to render from the gamecontent manager using the TextureIndex from the tile's tileobject - if not null, otherwise default to 3 (grass)

            int texture_for_terrain = 0;

            switch (TerrainId)
            {
            case 0:
                texture_for_terrain = 1;
                break;

            case 1:
                texture_for_terrain = 2;
                break;

            case 2:
                texture_for_terrain = 4;
                break;
            }

            Texture = content_.GetTileTexture(texture_for_terrain);

            FX_Destroyed_Anim_Texture = content_.GetTileTexture(-1);

            IsVisible = tileData_.IsVisible;

            // set DebugRect data (optional w debug options)
            DebugRect = new Texture2D(graphicsDevice_, 1, 1);
            DebugRect.SetData(new[] { Color.Red });

            // initialize previous mouse state w current mouse state (not really that big of a deal as it will only make one frame behave odd and that frame is over with before user even notices unless their pc is literally a piece of shit)
            _previousMouseState = Mouse.GetState();
        }