示例#1
0
        /// <summary>
        /// The function which takes the loaded level and builds it
        /// </summary>
        private void BuildLevel(LightRenderer aLightRenderer)
        {
            collisionLayer = new byte[mapXTiles, mapYTiles];
            backgroundLayer = new byte[mapXTiles, mapYTiles];
            platformLayer = new byte[mapXTiles, mapYTiles];
            specialsLayer = new byte[mapXTiles, mapYTiles];

            mySpecialTiles.Clear();

            byte backgroundValue, platformValue, specialsValue;

            //LOOPS THROUGH THE PLATFORM LAYER
            for (int x = 0; x < mapXTiles; x++)
            {
                for (int y = 0; y < mapYTiles; y++)
                {
                    collisionLayer[x, y] = FileLoader.LoadedCollisionLayer[x, y];

                    backgroundValue = FileLoader.LoadedBackgroundLayer[x, y];
                    platformValue = FileLoader.LoadedPlatformLayer[x, y];
                    specialsValue = FileLoader.LoadedSpecialsLayer[x, y];

                    if (backgroundValue == 25 || platformValue == 25 || specialsValue == 25) //JumpTile
                    {
                        mySpecialTiles.Add(new JumpTile(x, y));
                    }
                    else if (backgroundValue == 26 || platformValue == 26 || specialsValue == 26) //GoalTile
                    {
                        GoalTile temp = new GoalTile(x, y);
                        Camera.AddFocusObject(temp);
                        mySpecialTiles.Add(temp);
                        //LightingManager.PointLights.Add(new PointLight(new Vector2(x * TileSize, y * tileSize), 250, 0.7f, Color.White, false));
                    }
                    else if (backgroundValue == 27 || backgroundValue == 28 || backgroundValue == 29
                            || platformValue == 27 || platformValue == 28 || platformValue == 29
                            || specialsValue == 27 || specialsValue == 28 || specialsValue == 29) //SpikeTile
                    {
                        mySpecialTiles.Add(new SpikeTile(x, y));
                    }

                    if (backgroundValue == 41 || platformValue == 41 || specialsValue == 41) // Torch
                    {
                        myAnimatedTiles.Add(new AnimatedTile(x, y, TextureManager.BurningTorch, 0, 0, 5, 0, 100));
                        //LightingManager.PointLights.Add(new PointLight(new Vector2(x * TileSize, y * tileSize), 150, 0.7f, Color.White, true));
                        //Right now the torch is getting drawn two times:
                        //The first is a static image of the first frame
                        //The second is the acctual animation
                        //This is because i did not want to do alot of if-checks for each backgroundvalue/platformvalue/specialvalue
                        //and set the corresponding layer to 255 if a toirch was found
                        //should figure out something to do this in a pretty way later
                    }

                    backgroundLayer[x, y] = backgroundValue;
                    platformLayer[x, y] = platformValue;
                    specialsLayer[x, y] = specialsValue;

                }
            }

            for (int i = 0; i < FileLoader.LoadedLevelNumPointLights; i++)
            {
                float x = FileLoader.LoadedPointLights[i, 0];
                float y = FileLoader.LoadedPointLights[i, 1];
                float radius = FileLoader.LoadedPointLights[i, 2];
                float power = FileLoader.LoadedPointLights[i, 3];
                int r = (int)FileLoader.LoadedPointLights[i, 4];
                int g = (int)FileLoader.LoadedPointLights[i, 5];
                int b = (int)FileLoader.LoadedPointLights[i, 6];

                Color color = new Color(r, g, b);

                PointLight newLight = new PointLight(new Vector2(x, y), power, radius, color);
                aLightRenderer.pointLights.Add(newLight);
            }
        }
示例#2
0
        /// <summary>
        /// The function which takes the loaded level and builds it
        /// </summary>
        private void BuildLevel()
        {
            collisionLayer = new byte[mapXTiles, mapYTiles];
            backgroundLayer = new byte[mapXTiles, mapYTiles];
            platformLayer = new byte[mapXTiles, mapYTiles];
            specialsLayer = new byte[mapXTiles, mapYTiles];

            specialBlockList.Clear();

            byte backgroundValue, platformValue, specialsValue;

            //LOOPS THROUGH THE PLATFORM LAYER
            for (int x = 0; x < mapXTiles; x++)
            {
                for (int y = 0; y < mapYTiles; y++)
                {
                    collisionLayer[x, y] = FileLoader.LoadedCollisionLayer[x, y];

                    backgroundValue = FileLoader.LoadedBackgroundLayer[x, y];
                    platformValue = FileLoader.LoadedPlatformLayer[x, y];
                    specialsValue = FileLoader.LoadedSpecialsLayer[x, y];

                    #region BackgroundLayer
                    if (backgroundValue == 16)
                    {
                        specialBlockList.Add(new JumpTile(x, y));
                        backgroundLayer[x, y] = backgroundValue;
                    }

                    else if (backgroundValue == 17)
                    {
                        GoalTile temp = new GoalTile(x, y);
                        Camera.AddFocusObject(temp);
                        specialBlockList.Add(temp);
                        backgroundLayer[x, y] = backgroundValue;
                        GoalPos = new Vector2(x * tileSize, y * tileSize);
                        LightingManager.PointLights.Add(new PointLight(new Vector2(x * TileSize, y * tileSize), 250, 0.7f, Color.White));
                    }
                    else if (backgroundValue == 29)
                    {
                        playerStartPos = new Vector2(x * tileSize, y * tileSize);
                        backgroundLayer[x, y] = 255;
                    }
                    else if (backgroundValue == 30)
                    {
                        EnemyManager.AddEnemy(new SimpleEnemy(x, y, false));
                        backgroundLayer[x, y] = 255;
                    }
                    else if (backgroundValue == 31)
                    {
                        specialBlockList.Add(new TeleportTile(x, y));
                        backgroundLayer[x, y] = backgroundValue;
                    }
                    else
                    {
                        backgroundLayer[x, y] = backgroundValue;

                    }

                    #endregion

                    #region PlatformLayer
                    if (platformValue == 16)
                    {
                        specialBlockList.Add(new JumpTile(x, y));
                        platformLayer[x, y] = platformValue;
                    }
                    else if (platformValue == 31)
                    {
                        specialBlockList.Add(new TeleportTile(x, y));
                        platformLayer[x, y] = platformValue;
                    }
                    else if (platformValue == 17)
                    {
                        GoalTile temp = new GoalTile(x, y);
                        Camera.AddFocusObject(temp);
                        specialBlockList.Add(temp);
                        platformLayer[x, y] = platformValue;
                        GoalPos = new Vector2(x * tileSize, y * tileSize);
                        LightingManager.PointLights.Add(new PointLight(new Vector2(x * TileSize, y * tileSize), 250, 0.7f, Color.White));
                    }
                    else if (platformValue == 29)
                    {
                        playerStartPos = new Vector2(x * tileSize, y * tileSize);
                        platformLayer[x, y] = 255;
                    }
                    else if (platformValue == 30)
                    {
                        EnemyManager.AddEnemy(new SimpleEnemy(x, y, false));
                        platformLayer[x, y] = 255;
                    }
                    else
                        platformLayer[x, y] = platformValue;

                    //if (platformValue != 255 && platformValue != 15)
                    //{
                    //    LightingManager.PointLights.Add(new PointLight(new Vector2(x * TileSize + TileSize/2, y * tileSize + TileSize/2), 20, 0.5f, Color.White));
                    //}

                    #endregion

                    #region SpecialsLayer
                    if (specialsValue == 16)
                    {
                        specialBlockList.Add(new JumpTile(x, y));
                        specialsLayer[x, y] = specialsValue;
                    }
                    else if (specialsValue == 31)
                    {
                        specialBlockList.Add(new TeleportTile(x, y));
                        specialsLayer[x, y] = specialsValue;
                    }
                    else if (specialsValue == 17)
                    {
                        GoalTile temp = new GoalTile(x, y);
                        Camera.AddFocusObject(temp);
                        specialBlockList.Add(temp);
                        specialsLayer[x, y] = specialsValue;
                        GoalPos = new Vector2(x * tileSize, y * tileSize);
                        LightingManager.PointLights.Add(new PointLight(new Vector2(x * TileSize, y * tileSize), 250, 0.7f, Color.White));
                    }
                    else if (specialsValue == 29)
                    {
                        playerStartPos = new Vector2(x * tileSize, y * tileSize);
                        specialsLayer[x, y] = 255;
                    }
                    else if (specialsValue == 30)
                    {
                        EnemyManager.AddEnemy(new SimpleEnemy(x, y, false));
                        specialsLayer[x, y] = 255;
                    }
                    else
                        specialsLayer[x, y] = specialsValue;
                    #endregion

                }
            }
        }