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();
                }
            }
        }
Example #2
0
        private void Logic()
        {
            int colIndex = collisionTiles.SelectedIndex;

            camera.Position.X = hScrollBar1.Value * TileInformation.TileWidth;
            camera.Position.Y = vScrollBar1.Value * TileInformation.TileHeight;

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

            Vector2 worldPosition = Vector2.Transform(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Matrix.Invert(camera.TransformMatrix));

            int mx = (int)worldPosition.X;
            int my = (int)worldPosition.Y;


            if (currentCollisionLayer != null)
            {
                if (mx >= 0 && mx < tileDisplay1.Width + (int)camera.Position.X &&
                    my >= 0 && my < tileDisplay1.Height + (int)camera.Position.Y)
                {
                    collideCellX = mx / TileInformation.TileWidth;
                    collideCellY = my / TileInformation.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 + (int)camera.Position.X &&
                    my >= 0 && my < tileDisplay1.Height + (int)camera.Position.Y)
                {
                    cellX = mx / TileInformation.TileWidth;
                    cellY = my / TileInformation.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 = null;

                            if (textureListBox.SelectedIndex > -1)
                            {
                                texture = textureDict[textureListBox.SelectedItem as string];
                            }
                            else
                            {
                                return;
                            }

                            int index = currentLayer.isUsingTexture(texture);

                            if (index == -1)
                            {
                                currentLayer.AddTexture(texture);
                                index = currentLayer.isUsingTexture(texture);
                            }
                            else
                            {
                                currentLayer.SetCellIndex(cellX, cellY, index);
                            }

                            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());


                        for (int i = 0; i < CamReferences.Count; i++)
                        {
                            if (CamReferences[i].X == collideCellX && CamReferences[i].Y == collideCellY)
                            {
                                CamReferences.RemoveAt(i);
                            }
                        }
                    }

                    spriteBatch.Begin(SpriteSortMode.Texture,
                                      BlendState.AlphaBlend,
                                      null, null, null, null,
                                      camera.TransformMatrix);

                    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)
                    {
                        CamReferences.Add(new CameraNodes(collideCellX, collideCellY));
                    }

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

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

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

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

                    if (colIndex == 8 && AssociateBox.SelectedIndex == 0)
                    {
                        if (form.spawnNumber != "12")
                        {
                            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();
                }
            }
        }