Example #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);
            }
        }
Example #2
0
        private void UnwrapShadowCasters(PointLight pLight)
        {
            graphics.GraphicsDevice.SetRenderTarget(unwrapTarget);
            graphics.GraphicsDevice.Clear(Color.Transparent);

            unwrap.Parameters["LightPos"].SetValue(pLight.Position);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.PointClamp, null, null, unwrap);
            spriteBatch.Draw(midGroundTarget, new Rectangle(0, 0, fullScreen.Width, fullScreen.Width), Color.White);
            spriteBatch.End();
        }
Example #3
0
        public void Update(LightRenderer aLightRenderer)
        {
            //POINTLIGHTS
            if (ToolManager.HasActiveSelection && KeyMouseReader.LeftClick())
            {
                int x1 = ToolManager.SelectionTopLeftIndex.X * EditorMapManager.TileSize;
                int y1 = ToolManager.SelectionTopLeftIndex.Y * EditorMapManager.TileSize;

                int x2 = ToolManager.SelectionBottomRightIndex.X * EditorMapManager.TileSize;
                int y2 = ToolManager.SelectionBottomRightIndex.Y * EditorMapManager.TileSize;

                int centerx = x1 + ((x2 - x1) / 2);
                int centery = y1 + ((y2 - y1) / 2);

                float radius = (x2 - x1) / 2;
                Vector2 pos = new Vector2(centerx, centery);

                PointLight tempPointLight = new PointLight(pos, 1f, radius, EditorScreen.ColorPicker.SelectedColor);
                aLightRenderer.pointLights.Add(tempPointLight);

                Rectangle hitBox = new Rectangle((int)tempPointLight.Position.X - 10, (int)tempPointLight.Position.Y - 10, 20, 20);
                pointLightHitBoxes.Add(hitBox);
            }
            else if (KeyMouseReader.KeyClick(Keys.Q))
            {
                //LightingManager.AmbientLights.Add(new AmbientLight(0, 0, EditorMapManager.NumXTiles * 20, EditorMapManager.NumYTiles * 20, EditorScreen.ColorPicker.SelectedColor, 0.5f));

                //int x = 10 + (LightingManager.AmbientLights.Count * 30);
                //int y = 10;

                //Rectangle hitBox = new Rectangle(x + (int)EditorMapManager.Offset.X, y + (int)EditorMapManager.Offset.Y, 20, 20);
                //ambientLightHitBoxes.Add(hitBox);
            }

            else if (KeyMouseReader.LeftClick())
            {
                Vector2 mousePos = new Vector2(KeyMouseReader.GetMousePos().X, KeyMouseReader.GetMousePos().Y);
                Rectangle hitBox = new Rectangle((int)mousePos.X - 10, (int)mousePos.Y - 10, 20, 20);
                PointLight tempPointLight = new PointLight(mousePos, 1f, 250f, EditorScreen.ColorPicker.SelectedColor);
                aLightRenderer.pointLights.Add(tempPointLight);
                pointLightHitBoxes.Add(hitBox);
            }
            else if (KeyMouseReader.RightClick())
            {
                RemovePointLight(KeyMouseReader.GetMousePos(), aLightRenderer);
                RemoveAmbientLight(KeyMouseReader.GetMousePos(), aLightRenderer);
            }
        }
Example #4
0
        private void CreateLightMap(PointLight pLight)
        {
            graphics.GraphicsDevice.SetRenderTarget(postProcessTarget);
            graphics.GraphicsDevice.Clear(Color.Transparent);

            //Set params
            pointLight.Parameters["LightPos"].SetValue(pLight.Position);
            pointLight.Parameters["LightPow"].SetValue(pLight.Power);
            pointLight.Parameters["Radius"].SetValue(pLight.Radius);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.PointClamp, null, null, pointLight);
            spriteBatch.Draw(occlusionMap, fullScreen, Color.White);
            spriteBatch.End();
        }
Example #5
0
        public static void BuildMap()
        {
            ResetMap();

            collisionLayer = FileLoader.LoadedCollisionLayer;
            backgroundLayer = FileLoader.LoadedBackgroundLayer;
            platformLayer = FileLoader.LoadedPlatformLayer;
            specialsLayer = FileLoader.LoadedSpecialsLayer;

            for (int i = 0; i < FileLoader.LoadedLevelNumPointLights; i++)
            {
                float x = FileLoader.LoadedPointLights[i, 0] + Offset.X;
                float y = FileLoader.LoadedPointLights[i, 1] + Offset.Y;
                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);
                myLightRenderer.pointLights.Add(newLight);
            }

            GoalPlaced = false;
            PlayerPlaced = false;
        }