Exemplo n.º 1
0
        void DrawTile(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName)
        {
            if (!string.IsNullOrEmpty(selectedTileName))
            {
                var point = new Vector2((int)((camera.Position.X + position.X) / 32), (int)((camera.Position.Y + position.Y) / 32));

                if (layer.Tiles.ContainsKey(point))
                    layer.Tiles.Remove(point);

                layer.Tiles.Add(point, TileRepository.GetTile(selectedTileName));

                /*UndoService.Current[map].AddChange(new DelegateChange(null, new Action(() =>
                {
                    layer.Tiles.Remove(point);
                }), new Action(() =>
                {
                    layer.Tiles.Add(point, TileRepository.GetTile(selectedTileName));
                }), selectedTileName), "Draw a tile");*/

                /*MainForm.MapPanel.AddShadowForObject(Texture2D.FromStream(MainForm.MapPanel.GraphicsDevice, TileRepository.GetTile(selectedTileName).Texture),
                    point);*/

                base.OnMouseMove(map, layer, camera, position, selectedTileName);
            }
        }
Exemplo n.º 2
0
        public static Map Load(Stream stream, Texture2D lightTexture)
        {
            var map = new Map();
            var xml = XDocument.Load(stream).Element("Map");

            var ambientColorElement = xml.Element("AmbientColor");
            map.AmbientColor = new Color(int.Parse(ambientColorElement.Attribute("R").Value), int.Parse(ambientColorElement.Attribute("G").Value), int.Parse(ambientColorElement.Attribute("B").Value));
            map.Bluriness = float.Parse(xml.Element("Bluriness").Value);

            foreach (var light in xml.Element("Lights").Elements("Light"))
            {
                map.Lights.Add(new Light2D()
                {
                    Angle = float.Parse(light.Attribute("Angle").Value),
                    Texture = lightTexture,
                    Position = new Vector2(float.Parse(light.Attribute("X").Value), float.Parse(light.Attribute("Y").Value)),
                    IsOn = bool.Parse(light.Attribute("IsOn").Value),
                    ShadowType = (ShadowType)Enum.Parse(typeof(ShadowType), light.Attribute("ShadowType").Value),
                    Range = float.Parse(light.Attribute("Range").Value),
                    Fov = float.Parse(light.Attribute("Fov").Value),
                    Intensity = float.Parse(light.Attribute("Intensity").Value),
                    Color = new Color(int.Parse(light.Attribute("R").Value), int.Parse(light.Attribute("G").Value), int.Parse(light.Attribute("B").Value))
                });
            }

            foreach (var layer in xml.Element("Layers").Elements("Layer"))
            {
                map.Layers.Add(Layer.LoadFromXml(layer));
            }

            return map;
        }
Exemplo n.º 3
0
        public override void OnMouseClick(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName)
        {
            if (!string.IsNullOrEmpty(selectedTileName))
            {
                var orginal = new Vector2((int)((camera.Position.X + position.X) / 32), (int)((camera.Position.Y + position.Y) / 32));

                Tile target = null;
                layer.Tiles.TryGetValue(orginal, out target);

                FloodFill(layer, orginal, orginal, target, TileRepository.GetTile(selectedTileName));
            }
        }
Exemplo n.º 4
0
        public override void OnMouseMove(Map map, GameData.Layer layer, Camera2D camera, Microsoft.Xna.Framework.Vector2 position, string selectedTileName)
        {
            if (_lastX != -1 && _lastY != -1)
            {
                var direction = Vector3.Zero;

                direction.X = position.X - _lastX;
                direction.Y = position.Y - _lastY;

                var delta = camera.Position - direction;

                if (delta.X > 0 && delta.Y > 0)
                    camera.Position = delta;
            }

            _lastX = position.X;
            _lastY = position.Y;

            base.OnMouseMove(map, layer, camera, position, selectedTileName);
        }
Exemplo n.º 5
0
        public override void OnMouseClick(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName)
        {
            bool add = true;

            foreach (Light2D light in MainForm.MapPanel.Krpyton.Lights)
            {
                var mouse = (new Vector2(camera.Position.X, camera.Position.Y) + position).ToPoint();

                for (int i = 0; i < MainForm.MapPanel._lightSymbolPixelData.Length; i++)
                {
                    int x = i % MainForm.MapPanel._lightSymbolTexture.Width;
                    int y = i / MainForm.MapPanel._lightSymbolTexture.Width;
                 //   System.Windows.Forms.MessageBox.Show(mouse.ToString() + " , " + x + (int)light.Position.X + " " + y + (int)light.Position.Y);
                    if (new Rectangle(x + (int)light.Position.X, y + (int)light.Position.Y, 16, 16).Contains(mouse))
                    {
                        add = false;
                        ((MainForm)MainForm.ActiveForm).OpenProperties(light);
                        MainForm.MapPanel.SelectedLight = light;
                    }
                }
            }

            if (add)
            {
                var light = new Light2D()
                {
                    Position = new Vector2(camera.Position.X + position.X, camera.Position.Y + position.Y),
                    Color = Color.White,
                    Texture = MapPanel.LightTexture,
                    Range = 100,
                    IsOn = true,
                    Intensity = 1.5f,
                    ShadowType = ShadowType.Occluded
                };

                MainForm.MapPanel.Krpyton.Lights.Add(light);
                ((MainForm)MainForm.ActiveForm).OpenProperties(light);
                MainForm.MapPanel.SelectedLight = light;
            }
        }
Exemplo n.º 6
0
        public override void OnMouseMove(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName)
        {
            foreach (Light2D light in MainForm.MapPanel.Krpyton.Lights)
            {
                var mouse = (new Vector2(camera.Position.X, camera.Position.Y) + position).ToPoint();

                for (int i = 0; i < MainForm.MapPanel._lightSymbolPixelData.Length; i++)
                {
                    int x = i % MainForm.MapPanel._lightSymbolTexture.Width;
                    int y = i / MainForm.MapPanel._lightSymbolTexture.Width;

                    if (MainForm.MapPanel._movingLight == light || new Rectangle(x + (int)light.Position.X, y + (int)light.Position.Y, 1, 1)
                            .Contains(mouse))
                    {
                        if (MainForm.MapPanel._movingLight == null)
                            MainForm.MapPanel._movingLight = light;

                        light.Position = (new Vector2(camera.Position.X, camera.Position.Y) + position);
                    }
                }
            }

            base.OnMouseMove(map, layer, camera, position, selectedTileName);
        }
Exemplo n.º 7
0
 public virtual void OnMouseMove(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName)
 {
 }
Exemplo n.º 8
0
 public override void OnMouseMove(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName)
 {
     Erase(layer, camera, position, selectedTileName);
     base.OnMouseMove(map, layer, camera, position, selectedTileName);
 }
Exemplo n.º 9
0
 public override void OnMouseClick(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName)
 {
     PickTile(layer, camera, position);
 }
Exemplo n.º 10
0
 public MapPanel()
     : base()
 {
     contentManager = new ContentManager(this.Services, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/"));
     Map = new Map();
 }