Пример #1
0
        public void Init(LightRenderer aLightRenderer)
        {
            pointLightHitBoxes.Clear();
            for (int i = 0; i < aLightRenderer.pointLights.Count; i++)
            {
                Rectangle hitBox = new Rectangle((int)aLightRenderer.pointLights[i].Position.X - 10, (int)aLightRenderer.pointLights[i].Position.Y - 10, 20, 20);
                pointLightHitBoxes.Add(hitBox);
            }

            spotLightHitBoxes.Clear();
            for(int i = 0; i < aLightRenderer.spotLights.Count; i++)
            {
                Rectangle hitBox = new Rectangle((int)aLightRenderer.spotLights[i].Position.X - 10, (int)aLightRenderer.spotLights[i].Position.Y - 10, 20, 20);
                spotLightHitBoxes.Add(hitBox);
            }

            //ambientLightHitBoxes.Clear();
            //int startX = 10;
            //int startY = 10;
            //for (int i = 0; i < LightingManager.AmbientLights.Count; i++)
            //{
            //    startX += startX * 0 + 40;

            //    Rectangle hitBox = new Rectangle(startX + (int)EditorMapManager.Offset.X, startY + (int)EditorMapManager.Offset.Y, 20, 20);
            //    ambientLightHitBoxes.Add(hitBox);
            //}
        }
Пример #2
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);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
        public void Initialize(LightRenderer aLightRenderer)
        {
            tileSize = FileLoader.LoadedLevelTileSize;
            mapYTiles = FileLoader.LoadedLevelMapHeight;
            mapXTiles = FileLoader.LoadedLevelMapWidth;

            tileSize = 40;
            mapHeight = mapYTiles * tileSize;
            mapWidth = mapXTiles * tileSize;

            //PerformanceCheck();

            BuildLevel(aLightRenderer);
        }
Пример #5
0
 private void RemovePointLight(Point aMousePos, LightRenderer aLightRenderer)
 {
     for (int i = 0; i < pointLightHitBoxes.Count; i++)
     {
         if (pointLightHitBoxes[i].Contains(aMousePos))
         {
             aLightRenderer.pointLights.RemoveAt(i);
             pointLightHitBoxes.RemoveAt(i);
             return;
         }
     }
 }
Пример #6
0
 private void RemoveAmbientLight(Point aMousePos, LightRenderer aLightRenderer)
 {
     for (int i = 0; i < ambientLightHitBoxes.Count; i++)
     {
         if (ambientLightHitBoxes[i].Contains(aMousePos))
         {
             //LightingManager.AmbientLights.RemoveAt(i);
             ambientLightHitBoxes.RemoveAt(i);
             return;
         }
     }
 }
Пример #7
0
        public EditorMapManager(ContentManager Content, SpriteBatch spriteBatch)
        {
            this.Content = Content;
            Spritebatch = spriteBatch;

            Initialized = false;
            PlayerPlaced = false;
            GoalPlaced = false;

            TileSize = 40;

            xTiles = 80;
            yTiles = 50;

            collisionLayer = new byte[xTiles, yTiles];
            backgroundLayer = new byte[xTiles, yTiles];
            platformLayer = new byte[xTiles, yTiles];
            specialsLayer = new byte[xTiles, yTiles];
            selectedLayer = backgroundLayer;
            selectedLayerNum = 0;

            SelectedTileValue = 0;

            selectionTopLeft = new Point(0, 0);
            selectionBottomRight = new Point(0, 0);

            //myTileSetTexture = Content.Load<Texture2D>("Tiles/TileSet");
            //myTileSetTexture = Content.Load<Texture2D>("Tiles/LabTileSet");
            myTileSetTexture = Content.Load<Texture2D>("Tiles/LabTileSet40x40");

            myLightRenderer = new LightRenderer(Game1.graphics);
            myLightRenderer.Initialize((int)Offset.X, (int)Offset.Y, xTiles * 20, yTiles * 20);
            myLightRenderer.LoadContent(Content);

            myLightRenderer.minLight = 0.20f;
            myLightRenderer.lightBias = 10f;
        }
Пример #8
0
        public static void Update(LightRenderer aLightRenderer)
        {
            Point Offset = new Point((int)EditorMapManager.Offset.X, (int)EditorMapManager.Offset.Y);
            mouseX = ConvertPixelsToIndex(KeyMouseReader.GetMousePos()).X;
            mouseY = ConvertPixelsToIndex(KeyMouseReader.GetMousePos()).Y;

            Console.WriteLine(KeyMouseReader.GetMousePos() - Offset);

            if (KeyMouseReader.isKeyDown(Keys.LeftAlt) && KeyMouseReader.LeftClick())
            {
                EditorMapManager.SetCursorTexture(EditorMapManager.SelectedLayer[mouseX, mouseY]);
            }

            #region Selection
            if (KeyMouseReader.isKeyDown(Keys.LeftShift))
            {
                Selector.Update();
            }
            #endregion

            else
            {
                #region TileCreation
                if (EditorScreen.EditMode == 0)
                {
                    CopyPaster.Update(mouseX, mouseY);

                    if (!CopyPaster.Active)
                        TileCreator.Update(mouseX, mouseY);
                }
                #endregion

                #region Collision-Flagging
                else if (EditorScreen.EditMode == 1)
                {
                    ColliderMaker.Update(mouseX, mouseY);
                }
                #endregion

                #region JumpThroughAble-Flagging
                else if (EditorScreen.EditMode == 2)
                {
                    JumpThroughMaker.Update(mouseX, mouseY);
                }
                #endregion

                #region Lights
                else if (EditorScreen.EditMode == 4)
                {
                    if (prevEditMode != 4)
                        LightPlacer.Init(aLightRenderer);

                    LightPlacer.Update(aLightRenderer);
                }
                #endregion

            }

            if (KeyMouseReader.isKeyDown(Keys.LeftControl) && KeyMouseReader.KeyClick(Keys.D))
                ClearSelection();

            prevEditMode = EditorScreen.EditMode;
        }
Пример #9
0
        public static void SaveLevel(string LevelName, LightRenderer aLightRenderer)
        {
            int MapHeight = EditorMapManager.NumYTiles;
            int MapWidth = EditorMapManager.NumXTiles;

            byte[,] CollisionLayer = EditorMapManager.CollisionLayer;
            byte[,] BackgroundLayer = EditorMapManager.BackgroundLayer;
            byte[,] PlatformLayer = EditorMapManager.PlatformLayer;
            byte[,] SpecialsLayer = EditorMapManager.SpecialsLayer;

            float[,] PointLights = new float[aLightRenderer.pointLights.Count, 7];

            for (int y = 0; y < aLightRenderer.pointLights.Count; y++)
            {
                PointLights[y, 0] = aLightRenderer.pointLights[y].Position.X - EditorMapManager.Offset.X;
                PointLights[y, 1] = aLightRenderer.pointLights[y].Position.Y - EditorMapManager.Offset.Y;
                PointLights[y, 2] = aLightRenderer.pointLights[y].Radius;
                PointLights[y, 3] = aLightRenderer.pointLights[y].Power;
                PointLights[y, 4] = aLightRenderer.pointLights[y].Color.R;
                PointLights[y, 5] = aLightRenderer.pointLights[y].Color.G;
                PointLights[y, 6] = aLightRenderer.pointLights[y].Color.B;
            }

            //float[,] AmbientLights = new float[LightingManager.AmbientLights.Count, 8];

            //for (int y = 0; y < LightingManager.AmbientLights.Count; y++)
            //{
            //    AmbientLights[y, 0] = LightingManager.AmbientLights[y].Position.X;
            //    AmbientLights[y, 1] = LightingManager.AmbientLights[y].Position.Y;
            //    AmbientLights[y, 2] = LightingManager.AmbientLights[y].Width;
            //    AmbientLights[y, 3] = LightingManager.AmbientLights[y].Height;
            //    AmbientLights[y, 4] = LightingManager.AmbientLights[y].Color.R;
            //    AmbientLights[y, 5] = LightingManager.AmbientLights[y].Color.G;
            //    AmbientLights[y, 6] = LightingManager.AmbientLights[y].Color.B;
            //    AmbientLights[y, 7] = LightingManager.AmbientLights[y].Power;
            //}

            //First we read the GameData file so that we get access to the MapList
            //We will use that to propperly name the new map
            string GameDataPath = SaveFilesDirectoryPath + @"\GameData.xml";
            GameData TempGameData;
            FileStream GameDataStream = File.Open(GameDataPath, FileMode.Open);

            try
            {
                XmlSerializer GameDataSerializer = new XmlSerializer(typeof(GameData));
                TempGameData = (GameData)GameDataSerializer.Deserialize(GameDataStream);
            }
            finally
            {
                GameDataStream.Close();
            }

            //Now we make sure that we have a Levels directory
            System.IO.Directory.CreateDirectory(LevelDirectoryPath);

            //Get all the necessary LevelData
            LevelData LevelData = new LevelData();
            LevelData.TileSize = 20;
            LevelData.MapHeight = MapHeight;
            LevelData.MapWidth = MapWidth;
            LevelData.CollisionLayer = ConvertToJaggedArray(CollisionLayer);
            LevelData.BackgroundLayer = ConvertToJaggedArray(BackgroundLayer);
            LevelData.PlatformLayer = ConvertToJaggedArray(PlatformLayer);
            LevelData.SpecialsLayer = ConvertToJaggedArray(SpecialsLayer);
            LevelData.PointLights = ConvertToJaggedArray(PointLights);
            LevelData.NumPointLights = aLightRenderer.pointLights.Count;
            //LevelData.AmbientLights = ConvertToJaggedArray(AmbientLights);
            //LevelData.NumAmbientLights = LightingManager.AmbientLights.Count;

            //And now its time to build the SavePath
            //The new level we want to save should get number "MapList.Count + 1"
            //So if the MapList is empty, that is we have no maps,
            //then the new map we save will get number "0 + 1 = 1"
            //If there are 8 maps in the list then the new map will get number "8 + 1 = 9"
            string savePath = LevelDirectoryPath + @"\" + LevelName + ".xml";
            FileStream stream = File.Open(savePath, FileMode.Create);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(LevelData));
                serializer.Serialize(stream, LevelData);
            }
            finally
            {
                stream.Close();
            }

            //After we have saved the new level we need to update the GameData file (update the MapList)
            TempGameData.MapList = gameData.MapList;
            if (!TempGameData.MapList.Contains(LevelName))
                TempGameData.MapList.Add(LevelName);

            GameDataStream = File.Open(GameDataPath, FileMode.Create);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(GameData));
                serializer.Serialize(GameDataStream, TempGameData);
            }
            finally
            {
                GameDataStream.Close();
            }

            gameData = TempGameData;
        }
Пример #10
0
        public void Initialize()
        {
            LightRenderer = new LightRenderer(Game1.graphics);
            EnemyManager.Reset();
            Camera.ClearFocusList();

            if (mapManager == null)
                mapManager = new MapManager();

            mapManager.Initialize(LightRenderer);
            finalRenderTarget = new RenderTarget2D(ScreenManager.Game.GraphicsDevice, MapManager.MapWidth, MapManager.MapHeight);

            if (Player == null)
                Player = new Player();

            Player.SetStartPos(mapManager.PlayerStartPos);
            lightPos = mapManager.PlayerStartPos;

            Camera.ResetValues(mapManager.PlayerStartPos);
            Camera.DefaultFocus = Player;
            Camera.Position = mapManager.PlayerStartPos;
            Camera.Limits = new Rectangle(0, 0, MapManager.MapWidth, MapManager.MapHeight);

            pointLightHandles = new List<PointLight>();
            spotLightHandles = new List<SpotLight>();

            LightRenderer.Initialize(0, 0, MapManager.MapWidth, MapManager.MapHeight);

            LightRenderer.minLight = 0.15f;
            LightRenderer.lightBias = 10f;
            spotLightDir = Vector2.UnitX * -1.00001f;

            //pointLightHandles.Add(new PointLight(new Vector2(200, 200), 1f, 300f, Color.White));

            pointLightHandles.Add(new PointLight(new Vector2(200, 200), 1f, 200f, Color.Red));
            pointLightHandles.Add(new PointLight(new Vector2(200, 200), 1f, 250f, Color.LightGreen));
            pointLightHandles.Add(new PointLight(new Vector2(200, 200), 1f, 250f, Color.LightGreen));

            spotLightHandles.Add(new SpotLight(new Vector2(200, 200), spotLightDir, 1f, 2f, 0.5f, 500f, Color.LightBlue));
            spotLightHandles.Add(new SpotLight(new Vector2(200, 200), spotLightDir, 1f, 2f, 0.5f, 500f, Color.Red));

            //LightRenderer.pointLights.Add(pointLightHandles[0]);
            //LightRenderer.pointLights.Add(pointLightHandles[1]);
            //LightRenderer.pointLights.Add(pointLightHandles[2]);
            //LightRenderer.spotLights.Add(spotLightHandles[0]);
            //LightRenderer.spotLights.Add(spotLightHandles[1]);

            LightRenderer.LoadContent(ScreenManager.Game.Content);
            Console.WriteLine("PointLights.Count: " + LightRenderer.pointLights.Count);
            myAffectLightDir = false;
            myCurrLight = 0;
        }