Example #1
0
        public void SetTile(int x, int y, Tile tile)
        {
            if (tile == null)
                tile = Tile.UnLocatedTile["Grass"];
            if (x < 0 || x >= Width)
                return;
            if (y < 0 || y >= Height)
                return;

            // Check if it breaks a multiTile
            if (Tiles[x, y] is MultiTileTile)
            {
                MultiTileTile mTile = (MultiTileTile)Tiles[x, y];
                for (int i = -mTile.BlockCenter.X + (int)mTile.X; i < mTile.BlockWidth - mTile.BlockCenter.X + mTile.X; i++)
                {
                    for (int j = -mTile.BlockCenter.Y + (int)mTile.Y; j < mTile.BlockHeight - mTile.BlockCenter.Y + mTile.Y; j++)
                    {
                        if (i < 0 || i >= Width)
                            continue;
                        if (j < 0 || j >= Height)
                            continue;
                        Tiles[i, j] = Tile.UnLocatedTile["Grass"];
                    }
                }
            }

            // Put new tile
            if (tile is LocatedTile)
                ((LocatedTile)tile).MoveTo(x, y);
            Tiles[x, y] = tile;
            if (tile is MultiTileTile)
            {
                MultiTileTile mTile = (MultiTileTile)tile;
                for (int i = -mTile.BlockCenter.X + x; i < mTile.BlockWidth - mTile.BlockCenter.X + x; i++)
                {
                    for (int j = -mTile.BlockCenter.Y + y; j < mTile.BlockHeight - mTile.BlockCenter.Y + y; j++)
                    {
                        if (i < 0 || i >= Width)
                            continue;
                        if (j < 0 || j >= Height)
                            continue;
                        Tiles[i, j] = tile;
                    }
                }
            }
        }
Example #2
0
        public override void Update(GameTime gameTime, bool isInForeground)
        {
            base.Update(gameTime, isInForeground);

            if (!isInForeground)
                return;

            panel.Update(gameTime);

            if (addTileButton.IsPressed())
            {
                if (!String.IsNullOrWhiteSpace(tileName.Text))
                {
                    Tile tile = Tile.GetTile(tileType.List[tileType.CurrentIndex], Resources.World);
                    Form form = tile.GetEditingForm();
                    currentFormScreen = new FormScreen(Manager, form, Resources.World);
                    currentTile = tile;
                    Manager.OpenScreen(currentFormScreen);
                    return;
                }
            }
            if (currentFormScreen != null && currentFormScreen.IsSubmitted && currentTile != null)
            {
                if (currentTile is LocatedTile)
                {
                    currentTile.SubmitForm(currentFormScreen.Form);
                    currentFormScreen = null;
                    Manager.CloseScreen();
                }
                else
                {
                    currentTile.SubmitForm(currentFormScreen.Form);
                    if (!Tile.UnLocatedTile.ContainsKey(tileName.Text))
                        Tile.UnLocatedTile.Add(tileName.Text, currentTile);
                    currentFormScreen = null;
                    currentTile = null;
                }
            }

            if (submitButton.IsPressed())
            {
                IsSubmitted = true;
                Manager.CloseScreen();
                return;
            }
        }
Example #3
0
 public static string GetTileType(Tile tile)
 {
     return tile.GetType().Name;
 }