示例#1
0
        private void onMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (this.action == null)
                {
                    this.action = new MultiAction("Eraser");
                }

                int xt = (int)((e.X - EditorEngine.Instance.xCam) / EditorEngine.Instance.World.Camera.Scale / 16);
                int yt = (int)((e.Y - EditorEngine.Instance.yCam) / EditorEngine.Instance.World.Camera.Scale / 16);

                if (xt != lxt || yt != lyt)
                {
                    int tilesetIndex = TileEditorState.Instance.SelectedTileset;

                    MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(xt, yt, EditorEngine.Instance.SelectedLayer);

                    if (t != null)
                    {
                        SetTileAction tileAction = new SetTileAction(xt, yt, EditorEngine.Instance.SelectedLayer, tilesetIndex, -1);
                        tileAction.Execute();

                        action.Actions.Add(tileAction);
                    }
                }

                lxt = xt;
                lyt = yt;
            }
        }
示例#2
0
 public bool isSameType(MockupTile t)
 {
     if (t == null)
     {
         return(false);
     }
     return(isSameType(new Tuple <string, int>(t.Tileset.Name, t.tileIndex)));
 }
示例#3
0
        private void onMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            if (action == null)
            {
                action = new MultiAction("Tile Update");
            }

            int xt = (int)((e.X - EditorEngine.Instance.xCam) / EditorEngine.Instance.World.Camera.Scale / 16);
            int yt = (int)((e.Y - EditorEngine.Instance.yCam) / EditorEngine.Instance.World.Camera.Scale / 16);

            if (xt != lxt || yt != lyt)
            {
                if (TileEditorState.Instance.SelectedRegion != Rectangle.Empty)
                {
                    MultiAction multiAction = new MultiAction("Tile Update");
                    Rectangle   selection   = TileEditorState.Instance.SelectedRegion;

                    for (int x = 0; x < selection.Width; x++)
                    {
                        for (int y = 0; y < selection.Height; y++)
                        {
                            int currentX = selection.X + x;
                            int currentY = selection.Y + y;

                            int tilesetIndex = TileEditorState.Instance.SelectedTileset;

                            Tileset tilesheet = EditorEngine.Instance.CurrentMap.Tilesets[tilesetIndex].Tileset;
                            int     tileIndex = tilesheet.Texture.GetIndex(currentX, currentY);

                            int        zt = EditorEngine.Instance.SelectedLayer;
                            MockupTile t  = EditorEngine.Instance.CurrentMap.GetTile(xt + x, yt + y, zt);

                            if (t == null)
                            {
                                continue;
                            }

                            SetTileAction tileAction = new SetTileAction(
                                xt + x, yt + y,
                                zt,
                                tilesetIndex,
                                tileIndex);
                            multiAction.Actions.Add(tileAction);
                        }
                    }

                    multiAction.Execute();
                    action.Actions.Add(multiAction);
                }
            }

            lxt = xt;
            lyt = yt;
        }
示例#4
0
文件: Map.cs 项目: oxysoft/PokeSharp
 public void Fill(int spriteindex, int spritesheetindex, int z)
 {
     for (int y = 0; y < Height; y++)
     {
         for (int x = 0; x < Width; x++)
         {
             Tiles[x][y][z] = new MockupTile(this, spriteindex, spritesheetindex);
         }
     }
 }
示例#5
0
        public void Execute()
        {
            MockupTile t = map.GetTile(X, Y, Z);

            if (t != null)
            {
                oldtilesetIndex = t.tilesetIndex;
                oldtileIndex    = t.tileIndex;

                t.tilesetIndex = TilesetIndex;
                t.tileIndex    = TileIndex;
            }
        }
示例#6
0
        public SetTileAction Evaluate(int x, int y)
        {
            try {
                MockupTile tu  = EditorEngine.Instance.CurrentMap.GetTile(x, y - 1, EditorEngine.Instance.SelectedLayer);
                MockupTile td  = EditorEngine.Instance.CurrentMap.GetTile(x, y + 1, EditorEngine.Instance.SelectedLayer);
                MockupTile tl  = EditorEngine.Instance.CurrentMap.GetTile(x - 1, y, EditorEngine.Instance.SelectedLayer);
                MockupTile tr  = EditorEngine.Instance.CurrentMap.GetTile(x + 1, y, EditorEngine.Instance.SelectedLayer);
                MockupTile tul = EditorEngine.Instance.CurrentMap.GetTile(x - 1, y - 1, EditorEngine.Instance.SelectedLayer);
                MockupTile tur = EditorEngine.Instance.CurrentMap.GetTile(x + 1, y - 1, EditorEngine.Instance.SelectedLayer);
                MockupTile tdl = EditorEngine.Instance.CurrentMap.GetTile(x - 1, y + 1, EditorEngine.Instance.SelectedLayer);
                MockupTile tdr = EditorEngine.Instance.CurrentMap.GetTile(x + 1, y + 1, EditorEngine.Instance.SelectedLayer);

                bool u  = isSameType(tu);
                bool d  = isSameType(td);
                bool l  = isSameType(tl);
                bool r  = isSameType(tr);
                bool ul = isSameType(tul);
                bool ur = isSameType(tur);
                bool dl = isSameType(tdl);
                bool dr = isSameType(tdr);

                LogicEvalInfo _info = new LogicEvalInfo("", 0);
                script.Invoke("Eval", this, _info, u, d, l, r, ul, ur, dl, dr);

                int        zt = EditorEngine.Instance.SelectedLayer;
                MockupTile t  = EditorEngine.Instance.CurrentMap.GetTile(x, y, zt);
                if (t == null)
                {
                    return(null);
                }

                SetTileAction act = new SetTileAction(x, y, zt, EditorEngine.Instance.World.TilesetContainer.IndexOf(EditorEngine.Instance.GetTilesetByName(_info.s1)), _info.s2);

                return(act);
            } catch (Exception e) {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("-- Error (" + e.GetType() + "): " + e.Message);
                //GameConsole.WriteLine("Info: " + e.Value.Value);
                Console.WriteLine("\r\n\r\n");
                Console.ResetColor();
            }
            return(null);
        }
示例#7
0
        public IEncodable Decode(BinaryInput stream)
        {
            this.Name   = stream.ReadString();
            this.Author = stream.ReadString();

            this.Width  = stream.ReadInt32();
            this.Height = stream.ReadInt32();

            this.Tiles = new MockupTile[Width][][];
            for (int i = 0; i < Width; i++)
            {
                Tiles[i] = new MockupTile[Height][];
                for (int j = 0; j < Height; j++)
                {
                    Tiles[i][j] = new MockupTile[Map.LayerCount];
                }
            }

            int w = Width;
            int h = Height;

            this.Tilesets = stream.ReadList <MockupTileset>();

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    for (int k = 0; k < Map.LayerCount; k++)
                    {
                        Tiles[i][j][k] = stream.ReadObject <MockupTile>();
                    }
                }
            }

            int c = stream.ReadInt32();

            for (int i = 0; i < c; i++)
            {
                Tuple <Int32, Vector2> t = new Tuple <Int32, Vector2>(stream.ReadInt32(), stream.ReadVector2());
                Entities.Add(t);
            }
            return(this);
        }
示例#8
0
文件: Map.cs 项目: oxysoft/PokeSharp
        public IEncodable Decode(General.Encoding.BinaryInput stream)
        {
            Name   = stream.ReadString();
            Author = stream.ReadString();
            Width  = stream.ReadInt32();
            Height = stream.ReadInt32();
            int c1 = stream.ReadInt32();

            for (int i = 0; i < c1; i++)
            {
                Tilesets.Add(stream.ReadObject <MockupTileset>());
            }

            /*Initialize Tiles jagged multidimensional array*/
            this.Tiles = new MockupTile[Width][][];
            for (int i = 0; i < Width; i++)
            {
                Tiles[i] = new MockupTile[Height][];
                for (int j = 0; j < Height; j++)
                {
                    Tiles[i][j] = new MockupTile[Map.LayerCount];
                }
            }

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    for (int z = 0; z < LayerCount; z++)
                    {
                        Tiles[x][y][z] = stream.ReadObject <MockupTile>();
                    }
                }
            }
            int c2 = stream.ReadInt32();

            for (int i = 0; i < c2; i++)
            {
                EntityTemplate e = stream.ReadObject <EntityTemplate>();
                Entities.Add(e.CreateEntity(World.EntityFactory));
            }
            return(this);
        }
示例#9
0
        public override void Execute()
        {
            Map     map     = EditorEngine.Instance.CurrentMap;
            Tileset tileset = map.Tilesets[tilesetindex].Tileset;

            if (source.Width > 0 && source.Height > 0)
            {
                int sx = 0;
                int sy = 0;

                for (int x = 0; x < target.Width; x++)
                {
                    if (x % source.Width == 0)
                    {
                        sx = 0;
                    }
                    for (int y = 0; y < target.Height; y++)
                    {
                        if (y % source.Height == 0)
                        {
                            sy = 0;
                        }

                        int xt = target.X + x;
                        int yt = target.Y + y;
                        int zt = EditorEngine.Instance.SelectedLayer;

                        MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(xt, yt, zt);

                        if (t != null)
                        {
                            SetTileAction ta = new SetTileAction(target.X + x, target.Y + y, zt, tilesetindex, tileset.Texture.GetIndex(source.X + sx, source.Y + sy));
                            Actions.Add(ta);
                            sy++;
                        }
                    }
                    sx++;
                }
            }

            base.Execute();
        }
示例#10
0
		public override void Execute() {
			Map map = EditorEngine.Instance.CurrentMap;

			if (x >= 0 && x < map.Width && y >= 0 && y < map.Height) {
				int currentIndex = map.GetTile(x, y, EditorEngine.Instance.SelectedLayer).tileIndex;
				int currentTilesetIndex = map.GetTile(x, y, EditorEngine.Instance.SelectedLayer).tilesetIndex;

				Stack<Vector2> pp = new Stack<Vector2>();
				List<Vector2> hpp = new List<Vector2>();

				pp.Push(new Vector2(x, y));

				while (pp.Count > 0) {
					Vector2 cp = pp.Pop();

					if (!hpp.Contains(cp)) {
						int cx = (int)cp.X;
						int cy = (int)cp.Y;

						MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(cx, cy, EditorEngine.Instance.SelectedLayer);
						SetTileAction ta = new SetTileAction(cx, cy, EditorEngine.Instance.SelectedLayer, tilesetindex, tileindex);

						Actions.Add(ta);

						if (map.GetTile(cx + 1, cy, EditorEngine.Instance.SelectedLayer) != null && cx + 1 < map.Width && map.GetTile(cx + 1, cy, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx + 1, cy, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
							pp.Push(new Vector2(cx + 1, cy));
						if (map.GetTile(cx - 1, cy, EditorEngine.Instance.SelectedLayer) != null && cx - 1 >= 0 && map.GetTile(cx - 1, cy, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx - 1, cy, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
							pp.Push(new Vector2(cx - 1, cy));
						if (map.GetTile(cx, cy + 1, EditorEngine.Instance.SelectedLayer) != null && cy + 1 < map.Width && map.GetTile(cx, cy + 1, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx, cy + 1, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
							pp.Push(new Vector2(cx, cy + 1));
						if (map.GetTile(cx, cy - 1, EditorEngine.Instance.SelectedLayer) != null && cy - 1 < map.Width && map.GetTile(cx, cy - 1, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx, cy - 1, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
							pp.Push(new Vector2(cx, cy - 1));

						hpp.Add(cp);
					}
				}
			}
			base.Execute();
		}
示例#11
0
        public void Draw(GameTime gameTime)
        {
            Map map = EditorEngine.Instance.CurrentMap;

            if (lxt < 0 || lyt < 0 || lxt >= map.Width || lyt >= map.Height)
            {
                return;
            }
            Tileset         tileset    = EditorEngine.Instance.CurrentMap.Tilesets[TileEditorState.Instance.SelectedTileset].Tileset;
            Stack <Vector2> visitStack = new Stack <Vector2>();
            List <Vector2>  visited    = new List <Vector2>();
            List <Vector2>  points     = new List <Vector2>();

            visitStack.Push(new Vector2(lxt, lyt));

            int currentIndex        = map.GetTile(lxt, lyt, EditorEngine.Instance.SelectedLayer).tileIndex;
            int currentTilesetIndex = map.GetTile(lxt, lyt, EditorEngine.Instance.SelectedLayer).tilesetIndex;

            while (visitStack.Count > 0)
            {
                Vector2 point = visitStack.Pop();

                if (!visited.Contains(point))
                {
                    int cx = (int)point.X;
                    int cy = (int)point.Y;

                    MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(cx, cy, EditorEngine.Instance.SelectedLayer);

                    points.Add(point);

                    if (map.GetTile(cx + 1, cy, EditorEngine.Instance.SelectedLayer) != null && cx + 1 < map.Width && map.GetTile(cx + 1, cy, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx + 1, cy, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
                    {
                        visitStack.Push(new Vector2(cx + 1, cy));
                    }
                    if (map.GetTile(cx - 1, cy, EditorEngine.Instance.SelectedLayer) != null && cx - 1 >= 0 && map.GetTile(cx - 1, cy, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx - 1, cy, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
                    {
                        visitStack.Push(new Vector2(cx - 1, cy));
                    }
                    if (map.GetTile(cx, cy + 1, EditorEngine.Instance.SelectedLayer) != null && cy + 1 < map.Width && map.GetTile(cx, cy + 1, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx, cy + 1, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
                    {
                        visitStack.Push(new Vector2(cx, cy + 1));
                    }
                    if (map.GetTile(cx, cy - 1, EditorEngine.Instance.SelectedLayer) != null && cy - 1 < map.Width && map.GetTile(cx, cy - 1, EditorEngine.Instance.SelectedLayer).tileIndex == currentIndex && map.GetTile(cx, cy - 1, EditorEngine.Instance.SelectedLayer).tilesetIndex == currentTilesetIndex)
                    {
                        visitStack.Push(new Vector2(cx, cy - 1));
                    }

                    visited.Add(point);
                }
            }

            SpriteBatch spriteBatch = EditorEngine.Instance.World.ViewData.SpriteBatch;

            foreach (Vector2 point in points)
            {
                Rectangle target = new Rectangle((int)(point.X * 16 * EditorEngine.Instance.World.Camera.Scale), (int)(point.Y * 16 * EditorEngine.Instance.World.Camera.Scale), (int)(16 * EditorEngine.Instance.World.Camera.Scale), (int)(16 * EditorEngine.Instance.World.Camera.Scale));
                Rectangle source = tileset.Texture.GetSource(TileEditorState.Instance.SelectedRegion.X, TileEditorState.Instance.SelectedRegion.Y);
                spriteBatch.Draw(tileset.Texture.Texture, target.Add(EditorEngine.Instance.World.Camera.Location), source, Color.Black * .5f);
            }
        }
示例#12
0
文件: Map.cs 项目: oxysoft/PokeSharp
        public void Draw(GameTime time)
        {
            if (World != null)
            {
                SpriteBatch sbatch = World.ViewData.SpriteBatch;

                Vector2 origin = Vector2.Zero;
                if (World.Player != null)
                {
                    origin = (World.Player.Position / 16);
                }
                const int radius = 9;

                int xs  = World.Player != null ? ((int)origin.X - radius) : Int32.MinValue;
                int ys  = World.Player != null ? ((int)origin.Y - radius) : Int32.MinValue;
                int tpx = World.Player != null ? ((int)origin.X + radius) : Int32.MaxValue;
                int tpy = World.Player != null ? ((int)origin.Y + radius) : Int32.MaxValue;

                if (xs < 0)
                {
                    xs = 0;
                }
                if (ys < 0)
                {
                    ys = 0;
                }
                if (tpx > this.Width)
                {
                    tpx = Width;
                }
                if (tpy > this.Height)
                {
                    tpy = Width;
                }

                for (int x = xs; x < tpx; x++)
                {
                    for (int y = ys; y < tpy; y++)
                    {
                        for (int z = 0; z < LayerCount; z++)
                        {
                            MockupTile mt = GetTile(x, y, z);
                            if (mt != null)
                            {
                                if (mt.Tile != null)
                                {
                                    Tileset t   = GetTile(x, y, z).Tileset;
                                    Vector2 pos = new Vector2(x, y);

                                    Rectangle srcRect = t.Texture.GetSource(mt.Tile.spriteindex);
                                    Rectangle target  = new Rectangle((int)(x * 16 * World.Camera.Scale), (int)(y * 16 * World.Camera.Scale), (int)(16 * World.Camera.Scale), (int)(16 * World.Camera.Scale)).Add(World.Camera.Location);

                                    sbatch.Draw(t.Texture.Texture, target, srcRect, Color.White);
                                }
                            }
                        }
                    }
                }

                List <MapEntity> entitiesToRender = new List <MapEntity>();
                entitiesToRender.AddRange(Entities);

                int renderedEntities = entitiesToRender.Count;
                entitiesToRender.Sort(delegate(MapEntity a, MapEntity b) {
                    float positionA = a.Position.Y + a.Template.Texture.FrameHeight;
                    float positionB = b.Position.Y + b.Template.Texture.FrameHeight;

                    if (a.TopMost && !b.TopMost)
                    {
                        return(1);
                    }
                    if (!a.TopMost && b.TopMost)
                    {
                        return(-1);
                    }

                    if (positionA > positionB)
                    {
                        return(1);
                    }
                    if (positionA < positionB)
                    {
                        return(-1);
                    }

                    if (positionA == positionB)
                    {
                        if (a.Position.X > b.Position.X)
                        {
                            return(-1);
                        }
                        if (a.Position.X < b.Position.X)
                        {
                            return(1);
                        }
                    }

                    return(0);
                });

                sbatch.End();

                foreach (MapEntity entity in entitiesToRender)
                {
                    entity.BeginDraw(time);
                    entity.Draw(time);
                    entity.EndDraw(time);
                }

                sbatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);
            }
        }
示例#13
0
        public override void Execute()
        {
            Stack <Vector2> stack   = new Stack <Vector2>();
            List <Vector2>  visited = new List <Vector2>();

            stack.Push(new Vector2(xt, yt));

            MockupTile mockup = EditorEngine.Instance.CurrentMap.GetTile(xt, yt, EditorEngine.Instance.SelectedLayer);

            if (mockup != null)
            {
                string tilesheetindex = mockup.Tileset.Name;
                int    tileindex      = mockup.tileIndex;

                TileLogicScript sc = null;
                if (sametype)
                {
                    sc = TileLogicManager.Instance.getLogicFromSameType(tilesheetindex, tileindex);
                }


                int i = 0;

                while (stack.Count > 0)
                {
                    Vector2 pop = stack.Pop();

                    if (!visited.Contains(pop))
                    {
                        int x = (int)pop.X;
                        int y = (int)pop.Y;

                        MockupTile u = EditorEngine.Instance.CurrentMap.GetTile(x, y - 1, EditorEngine.Instance.SelectedLayer);
                        MockupTile d = EditorEngine.Instance.CurrentMap.GetTile(x, y + 1, EditorEngine.Instance.SelectedLayer);
                        MockupTile l = EditorEngine.Instance.CurrentMap.GetTile(x - 1, y, EditorEngine.Instance.SelectedLayer);
                        MockupTile r = EditorEngine.Instance.CurrentMap.GetTile(x + 1, y, EditorEngine.Instance.SelectedLayer);

                        if (sametype && sc != null)
                        {
                            if (u != null && TileLogicManager.Instance.getLogicFromSameType(u.Tileset.Name, u.tileIndex) == sc)
                            {
                                stack.Push(new Vector2(x, y - 1));
                            }
                            if (d != null && TileLogicManager.Instance.getLogicFromSameType(d.Tileset.Name, d.tileIndex) == sc)
                            {
                                stack.Push(new Vector2(x, y + 1));
                            }
                            if (l != null && TileLogicManager.Instance.getLogicFromSameType(l.Tileset.Name, l.tileIndex) == sc)
                            {
                                stack.Push(new Vector2(x - 1, y));
                            }
                            if (r != null && TileLogicManager.Instance.getLogicFromSameType(r.Tileset.Name, r.tileIndex) == sc)
                            {
                                stack.Push(new Vector2(x + 1, y));
                            }
                        }
                        else
                        {
                            if (u != null && (u.Tileset.Name == tilesheetindex && u.tileIndex == tileindex))
                            {
                                stack.Push(new Vector2(x, y - 1));
                            }
                            if (d != null && d.Tileset.Name == tilesheetindex && d.tileIndex == tileindex)
                            {
                                stack.Push(new Vector2(x, y + 1));
                            }
                            if (l != null && l.Tileset.Name == tilesheetindex && l.tileIndex == tileindex)
                            {
                                stack.Push(new Vector2(x - 1, y));
                            }
                            if (r != null && r.Tileset.Name == tilesheetindex && r.tileIndex == tileindex)
                            {
                                stack.Push(new Vector2(x + 1, y));
                            }
                        }

                        this.Actions.Add(new LogicSetAction(x, y, logicindex, false));
                        i++;
                        visited.Add(pop);
                    }
                }
            }

            base.Execute();

            foreach (Vector2 vec2 in visited)
            {
                int xr = (int)vec2.X;
                int yr = (int)vec2.Y;

                new LogicSetAction(xr, yr, logicindex).Execute();
            }
        }