Пример #1
0
        private void LoadTiles(CollisionLayer colLayer)
        {
            globalX = colLayer.Width;
            globalY = colLayer.Height;

            tiles = new Tile[colLayer.Width, colLayer.Height];

            for (int x = 0; x < colLayer.Width; ++x)
            {
                for (int y = 0; y < colLayer.Height; ++y)
                {
                    tiles[x, y] = LoadTile(colLayer.GetCellIndex(x, y), x, y);
                }
            }

            //if (exits.Count == 0)
            //    throw new NotSupportedException("A level must have an exit.");
        }
        private void Logic()
        {
            camera.Position.X = hScrollBar1.Value * Engine.TileWidth;
            camera.Position.Y = vScrollBar1.Value * Engine.TileHeight;

            int mx = Mouse.GetState().X;
            int my = Mouse.GetState().Y;

            if (currentCollisionLayer != null)
            {
                if (mx >= 0 && mx < tileDisplay1.Width &&
                    my >= 0 && my < tileDisplay1.Height)
                {
                    collideCellX = mx / Engine.TileWidth;
                    collideCellY = my / Engine.TileHeight;

                    collideCellX += hScrollBar1.Value;
                    collideCellY += vScrollBar1.Value;

                    collideCellX = (int)MathHelper.Clamp(collideCellX, 0, currentCollisionLayer.Width - 1);
                    collideCellY = (int)MathHelper.Clamp(collideCellY, 0, currentCollisionLayer.Height - 1);
                }
            }

            if (currentLayer != null)
            {
                if (mx >= 0 && mx < tileDisplay1.Width &&
                    my >= 0 && my < tileDisplay1.Height)
                {
                    cellX = mx / Engine.TileWidth;
                    cellY = my / Engine.TileHeight;

                    cellX += hScrollBar1.Value;
                    cellY += vScrollBar1.Value;

                    cellX = (int)MathHelper.Clamp(cellX, 0, currentLayer.Width - 1);
                    cellY = (int)MathHelper.Clamp(cellY, 0, currentLayer.Height - 1);

                    if (MouseDown && coolBool == false)
                    {
                        if (drawRadioButton.Checked && textureListBox != null)
                        {
                            Texture2D texture = textureDict[textureListBox.SelectedItem as string];

                            int index = currentLayer.isUsingTexture(texture);

                            if (index == -1)
                            {
                                currentLayer.AddTexture(texture);
                                index = currentLayer.isUsingTexture(texture);
                            }

                            if (fillCheckBox.Checked)
                            {
                                FillCounter = 500;
                                FillCell(cellX, cellY, index);
                            }
                            else
                            {
                                currentLayer.SetCellIndex(cellX, cellY, index);
                            }
                        }
                        else if (eraseRadioButton.Checked)
                        {
                            if (fillCheckBox.Checked)
                            {
                                FillCounter = 500;
                                FillCell(cellX, cellY, -1);
                            }
                            else
                            {
                                currentLayer.SetCellIndex(cellX, cellY, -1);
                            }
                        }
                    }
                }
                else
                {
                    cellX = cellY = -1;
                }
            }

            if (MouseDown && coolBool == true)
            {
                tileNumber = currentCollisionLayer.GetCellIndex(collideCellX, collideCellY);

                if (drawRadioButton.Checked && textureListBox != null)
                {
                    int colIndex = collisionTiles.SelectedIndex;

                    if (colIndex == 0 && collisionTiles.SelectedItem != null && AssociateBox.SelectedIndex == 0)
                    {
                        currentCollisionLayer.SetCellIndex(collideCellX, collideCellY, colIndex.ToString());
                    }

                    spriteBatch.Begin();

                    if (colIndex == 1 && AssociateBox.SelectedIndex == 0)
                    {
                        currentCollisionLayer.SetCellIndex(collideCellX, collideCellY, colIndex.ToString());
                    }

                    if (colIndex == 2 && AssociateBox.SelectedIndex == 0)
                    {
                        currentCollisionLayer.SetCellIndex(collideCellX, collideCellY, colIndex.ToString());
                    }

                    if (colIndex == 3 && AssociateBox.SelectedIndex == 0)
                    {
                        currentCollisionLayer.SetCellIndex(collideCellX, collideCellY, colIndex.ToString());
                    }

                    if (colIndex == 4 && AssociateBox.SelectedIndex == 0)
                    {
                        currentCollisionLayer.SetCellIndex(collideCellX, collideCellY, form.spawnNumber.ToString());
                    }

                    if (AssociateBox.SelectedIndex == 1)
                    {
                        string TileName = tileNumber + "#" + numForm.actualNumber.Text;
                        int    count    = TileName.Count(f => f == '#');

                        if (count <= 1 && int.Parse(tileNumber) > 3)
                        {
                            currentCollisionLayer.SetCellIndex(collideCellX, collideCellY, TileName);
                        }
                        else
                        {
                            TileName = null;
                        }
                    }

                    else if (AssociateBox.SelectedIndex == 2)
                    {
                        int  tileNumberType;
                        bool isNum = int.TryParse(tileNumber, out tileNumberType);

                        if (!isNum)
                        {
                            string[] numbers = tileNumber.Split('#');
                            currentCollisionLayer.SetCellIndex(collideCellX, collideCellY, numbers[0]);
                        }
                        else
                        {
                            currentCollisionLayer.SetCellIndex(collideCellX, collideCellY, tileNumber);
                        }
                    }
                    spriteBatch.End();
                }
            }
        }
Пример #3
0
        private void tileDisplay1_MouseDown(object sender, MouseEventArgs e)
        {
            if (currentCollisionLayer != null)
            {
                tileNumber = currentCollisionLayer.GetCellIndex(collideCellX, collideCellY);
                int  tileNumberTypeCheckthing;
                bool isNumCheckthing = int.TryParse(tileNumber, out tileNumberTypeCheckthing);
                int  colIndex        = collisionTiles.SelectedIndex;

                if (!isNumCheckthing && tileNumber != null)
                {
                    string[] retrieve = tileNumber.Split('#');
                }

                if (collisionTiles.SelectedIndex == 8 && AssociateBox.SelectedIndex == 0 && form.spawnNumber == "12")
                {
                    somethingElseX = collideCellX;
                    somethingElseY = collideCellY;
                }
            }

            MouseDown = true;
        }