Esempio n. 1
0
 public override void update()
 {
     for (uint i = field.Size.X - 2; i > 1; i--)
     {
         for (uint j = field.Size.Y - 2; j > 1; j--)
         {
             //Console.WriteLine(field.GetPixel(i, j));
             if (field.GetPixel(i, j) == sand)
             {
                 if (field.GetPixel(i, j + 1) == Color.Transparent)
                 {
                     Pixy.MovePixel(i, j, down, field);
                 }
                 else
                 if (field.GetPixel(i - 1, j + 1) == Color.Transparent)
                 {
                     Pixy.MovePixel(i, j, downL, field);
                 }
                 else
                 if (field.GetPixel(i + 1, j + 1) == Color.Transparent)
                 {
                     Pixy.MovePixel(i, j, downR, field);
                 }
             }
         }
     }
 }
 //рисование
 private void paint(string colorName, int length = 5)
 {
     if (colors.ContainsKey(colorName))
     {
         Pixy.drawCube(colors[colorName], image, length);
     }
 }
        public override void update()
        {
            for (uint i = field.Size.X - 2; i > 1; i--)
            {
                for (uint j = field.Size.Y - 2; j > 1; j--)
                {
                    //Console.WriteLine("there");
                    if (InGradientFire(field.GetPixel(i, j), shift))
                    {
                        temPix = field.GetPixel(i, j);
                        // Console.WriteLine(temPix + " " + activeFire);
                        if (baseField.GetPixel(i, j) == water)
                        {
                            field.SetPixel(i, j, Color.Transparent);
                        }
                        else
                        if (temPix == activeFire)
                        {
                            fireable = true;
                            foreach (var pix in Pixy.getNeighbours((int)i, (int)j, baseField))
                            {
                                if (InGradient(baseField.GetPixel((uint)pix.X, (uint)pix.Y)) == true)
                                {
                                    fireable = false;
                                    if (rand.Next() % 50 == 1)
                                    {
                                        field.SetPixel((uint)pix.X, (uint)pix.Y, activeFire);
                                        baseField.SetPixel((uint)pix.X, (uint)pix.Y, Color.Transparent);
                                    }
                                }
                            }

                            if (fireable)
                            {
                                field.SetPixel(i, j, passiveFire);
                            }
                        }
                        else if (temPix == color)
                        {
                            if (rand.Next() % 70 == 1)
                            {
                                field.SetPixel(i, j, Color.Transparent);
                            }
                        }
                        else
                        {
                            if (rand.Next() % 30 == 1)
                            {
                                field.SetPixel(i, j, color);
                            }
                        }
                    }
                }
            }
        }
        public override void update()
        {
            for (uint i = field.Size.X - 2; i > 1; i--)
            {
                for (uint j = field.Size.Y - 2; j > 1; j--)
                {
                    if (baseField.GetPixel(i, j) == triggerColor)
                    {
                        if (rand.Next() % 2 == 1)
                        {
                            field.SetPixel(i, j + 1, color);
                        }
                    }
                    temp = field.GetPixel(i, j);

                    if (temp.G == color.G)
                    {
                        if (temp.A <= 0)
                        {
                            field.SetPixel(i, j, Color.Transparent);
                        }

                        else
                        {
                            int a = rand.Next() % 100;
                            if (a < 50)
                            {
                                Pixy.MovePixel(i, j, up, field);
                            }
                            else
                            if (a < 60)
                            {
                                Pixy.MovePixel(i, j, upL, field);
                            }
                            else
                            if (a < 70)
                            {
                                Pixy.MovePixel(i, j, upR, field);
                            }

                            if (a > 25)
                            {
                                field.SetPixel(i, j, alphaGradient[(temp.A / 15) - 1]);
                            }
                        }
                    }
                }
            }
        }
 public static void drawCube(Color color, Image image, int length)
 {
     if (ViewSystem.Instance.MouseInBounds(image))
     {
         Vector2i mouse = ViewSystem.Instance.getImageMouseCoor(image);
         Console.WriteLine(image.Pixels[mouse.X + mouse.Y * image.Size.Y]);
         for (int i = mouse.X - length / 2; i < mouse.X + length / 2; i++)
         {
             for (int j = mouse.Y - length / 2; j < mouse.Y + length / 2; j++)
             {
                 if (Pixy.InImageBounds(i, j, image))
                 {
                     image.SetPixel((uint)i, (uint)j, color);
                 }
             }
         }
     }
 }
Esempio n. 6
0
        private void liq_simulation()
        {
            //эта часть алгоритма отвечает за покадровую смену направления прохождения по массиву пикселей
            uint i;

            int iterator;

            if (DirectionSwap)
            {
                iterator = 1;
                CycleDir = DirLeft;
                i        = 0;
            }
            else
            {
                iterator = -1;
                CycleDir = DirRight;
                i        = field.Size.X - 2;
            }


            for (; CycleDir.Invoke(i); i += (uint)iterator)
            {
                for (uint j = field.Size.Y - 2; j > 0; j--)
                {
                    if (field.GetPixel(i, j) == liquid) //если пиксель отвечает за воду
                    {
                        //проверяем возможность движения вниз
                        if (field.GetPixel(i, j + 1) == Color.Transparent)
                        {
                            if (rand.Next() % 40 == 1)
                            {
                                if (field.GetPixel(i - 1, j) == Color.Transparent)
                                {
                                    Pixy.MovePixel(i, j, Left, field);
                                }
                                else
                                if (field.GetPixel(i + 1, j) == Color.Transparent)
                                {
                                    Pixy.MovePixel(i, j, Right, field);
                                }
                            }
                            else
                            {
                                Pixy.MovePixelWithCols(i, j, down, field, 2);
                            }
                        }


                        else//проверяем возможность движения вниз-влево и вниз-вправо
                        if (field.GetPixel(i - 1, j + 1) == Color.Transparent)
                        {
                            Pixy.MovePixel(i, j, downL, field);
                        }
                        else
                        if (field.GetPixel(i + 1, j + 1) == Color.Transparent)
                        {
                            Pixy.MovePixel(i, j, downR, field);
                        }
                        else
                        {
                            //проверяем возможность движения влево и вправо (расползание)
                            if (field.GetPixel(i + 1, j) == Color.Transparent || field.GetPixel(i - 1, j) == Color.Transparent)
                            {
                                Vector2i dir = FindWaterBalanceDirection(i, j);
                                if (field.GetPixel(i - 1, j) == Color.Transparent && (dir == Left))
                                {
                                    Pixy.MovePixelWithCols(i, j, dir, field, rand.Next(1, 5));
                                }
                                else
                                if (field.GetPixel(i + 1, j) == Color.Transparent && (dir == Right))
                                {
                                    Pixy.MovePixelWithCols(i, j, dir, field, rand.Next(1, 5));
                                }
                            }
                        }
                    }
                }
            }
            //изменить направление прохождения по массиву
            DirectionSwap = !DirectionSwap;
        }
        public Scene createScene()
        {
            bool sceneCreated = false;

            //GUI
            Gui SC_gui = new Gui(window);

            mainPanel.Renderer.BackgroundColor = Color.Black;
            mainPanel.Renderer.BorderColor     = Color.White;
            mainPanel.PositionLayout           = new Layout2d("2.5%", "5%");
            mainPanel.SizeLayout       = new Layout2d("95%", "90%");
            mainPanel.Renderer.Borders = new Outline(5, 5, 5, 5);

            Button createButton = new Button("CREATE");

            createButton.Clicked       += (e, a) => { sceneCreated = true; };
            createButton.PositionLayout = new Layout2d("80%", "90%");

            mainPanel.Add(createButton);
            SC_gui.Add(mainPanel);


            //SIMULATIONS GUI
            Panel simulationsPanel = new Panel();

            simulationsPanel.Renderer.BackgroundColor = Color.Black;
            simulationsPanel.Renderer.BorderColor     = Color.White;
            simulationsPanel.PositionLayout           = new Layout2d("3%", "5%");
            simulationsPanel.SizeLayout       = new Layout2d("25%", "80%");
            simulationsPanel.Renderer.Borders = new Outline(2, 2, 2, 2);

            Panel AddedSimuationsPanel = new Panel(simulationsPanel);

            AddedSimuationsPanel.PositionLayout = new Layout2d("73%", "5%");

            //origin widgets
            originPanel.Renderer.BackgroundColor = Color.Black;
            originPanel.Renderer.BorderColor     = Color.White;
            originPanel.PositionLayout           = new Layout2d("30.5%", "5%");
            originPanel.SizeLayout       = new Layout2d("40%", "80%");
            originPanel.Renderer.Borders = new Outline(2, 2, 2, 2);

            originLabel = new Label();
            originLabel.Renderer.TextColor = Color.White;

            Label SimulationsNote = new Label("Simulations: ");

            SimulationsNote.Renderer       = originLabel.Renderer;
            SimulationsNote.PositionLayout = new Layout2d("3%", "1%");
            Label AddedSimulationsNote = new Label("Added: ");

            AddedSimulationsNote.Renderer       = originLabel.Renderer;
            AddedSimulationsNote.PositionLayout = new Layout2d("73%", "1%");

            mainPanel.Add(SimulationsNote);
            mainPanel.Add(AddedSimulationsNote);
            mainPanel.Add(simulationsPanel);
            mainPanel.Add(AddedSimuationsPanel);


            /////LAYER CREATING/////////
            image = Pixy.drawBorder(image);

            RenderObject picture       = new RenderObject(image);
            RenderObject flame_picture = new RenderObject(flame_field);
            RenderObject fire_picture  = new RenderObject(fire_field);

            Layer main_layer  = new Layer(1, "main");
            Layer Fire_layer  = new Layer(2, "fire_layer");
            Layer flame_layer = new Layer(3, "flame_layer");


            scene = new Scene(window);
            main_layer.setLayerRenderObject(picture);
            Fire_layer.setLayerRenderObject(fire_picture);
            flame_layer.setLayerRenderObject(flame_picture);
            scene.AddLayer(main_layer);
            scene.AddLayer(Fire_layer);
            scene.AddLayer(flame_layer);



            //SIMULATION CREATING PANELS
            SandSimulationPanelInit();
            LiquidSimulationPanelInit();
            FireSimulationPanelInit();
            flameSimulationPanelInit();
            lightningSimulationPanelInit();
            rainSimulationPanelInit();

            AddedSimsList            = new ListBox();
            AddedSimsList.SizeLayout = new Layout2d("100%", "100%");
            AddedSimuationsPanel.Add(AddedSimsList);
            ListBox SimulationsList = new ListBox();

            SimulationsList.AddItem("Sand Simulation", "Sand Simulation");
            SimulationsList.AddItem("Liquid Simulation", "Liquid Simulation");
            SimulationsList.AddItem("Fire Simulation", "Fire Simulation");
            SimulationsList.AddItem("Flame Simulation", "Flame Simulation");
            SimulationsList.AddItem("Lightning Simulation", "Lightning Simulation");
            SimulationsList.AddItem("Rain Simulation", "Rain Simulation");
            SimulationsList.ItemSelected += (e, a) =>
            {
                switch (SimulationsList.GetSelectedItemId())
                {
                case ("Sand Simulation"):
                    currentToolPanel.Visible = false;
                    currentToolPanel         = sandSimulationPanel;
                    currentToolPanel.Visible = true;
                    break;

                case ("Liquid Simulation"):
                    currentToolPanel.Visible = false;
                    currentToolPanel         = liquidSimulationPanel;
                    currentToolPanel.Visible = true;
                    break;

                case ("Fire Simulation"):
                    currentToolPanel.Visible = false;
                    currentToolPanel         = fireSimulationPanel;
                    currentToolPanel.Visible = true;
                    break;

                case ("Flame Simulation"):
                    currentToolPanel.Visible = false;
                    currentToolPanel         = flameSimulationPanel;
                    currentToolPanel.Visible = true;
                    break;

                case ("Lightning Simulation"):
                    currentToolPanel.Visible = false;
                    currentToolPanel         = lightningSimulationPanel;
                    currentToolPanel.Visible = true;
                    break;

                case ("Rain Simulation"):
                    currentToolPanel.Visible = false;
                    currentToolPanel         = rainSimulationPanel;
                    currentToolPanel.Visible = true;
                    break;
                }
            };
            simulationsPanel.Add(SimulationsList);

            while (window.IsOpen && !sceneCreated)
            {
                window.DispatchEvents();
                window.Clear(SFML.Graphics.Color.Black);
                //Draw here
                SC_gui.Draw();
                window.Display();
            }

            //Scene created!
            foreach (var obj in simulations)
            {
                scene.AddObject(obj);
            }
            SC_gui.RemoveAllWidgets();
            return(scene);
        }
Esempio n. 8
0
        public void loadScene1()
        {
            //COLORS

            Color sand1      = new Color(252, 235, 145);
            Color emptyP     = new Color(0, 0, 0);
            Color waterP     = new Color(101, 175, 182, 150);
            Color lightning  = new Color(108, 233, 236);
            Color fire       = new Color(191, 106, 2);
            byte  fireoffset = 42;
            Color fireActive = new Color(191, 148, 2);
            Color wood       = new Color(53, 33, 21);
            byte  woodoffset = 29;

            //MAIN__FIELD
            //Image image = new Image("C:/Users/Пользователь/Desktop/SandySharp/SandySharp/FirstScene.png");
            Image image       = new Image(160, 120, Color.Transparent);
            Image flame_field = new Image(160, 120, Color.Transparent);
            Image fire_field  = new Image(160, 120, Color.Transparent);

            image = Pixy.drawBorder(image);

            RenderObject picture       = new RenderObject(image);
            RenderObject flame_picture = new RenderObject(flame_field);
            RenderObject fire_picture  = new RenderObject(fire_field);

            //starts



            //SCENES AND LAYERS
            Scene scene       = new Scene(window);
            Layer main_layer  = new Layer(1, "main");
            Layer Fire_layer  = new Layer(2, "fire_layer");
            Layer flame_layer = new Layer(3, "flame_layer");



            //SIMULATIONS
            SandSimulation      sandSim      = new SandSimulation(sand1, image, "sand_sim");
            LiquidSimulation    liqSim       = new LiquidSimulation(waterP, image, "liquid_sim");
            FireSimulation      fireSim      = new FireSimulation(fire, fireoffset, wood, woodoffset, fire_field, image, waterP, "fire_sim");
            FlameSimulation     flameSim     = new FlameSimulation(fire, fireSim.getActiveFire(), fire_field, flame_field, "flame_sim");
            LightningSimulation lightningSim = new LightningSimulation(lightning, fireSim.getActiveFire(), fire_field, image, "lightning_sim");
            RainSimulation      rainSim      = new RainSimulation(waterP, lightning, image, fire_field, 0.1f, 0.08f, "rain_sim");


            scene.AddLayer(main_layer);
            scene.AddLayer(Fire_layer);
            scene.AddLayer(flame_layer);


            scene.AddObject(fireSim);
            scene.AddObject(flameSim);
            scene.AddObject(liqSim);
            scene.AddObject(sandSim);
            //scene.AddObject(lightningSim);
            //scene.AddObject(rainSim);

            main_layer.setLayerRenderObject(picture);
            Fire_layer.setLayerRenderObject(fire_picture);
            flame_layer.setLayerRenderObject(flame_picture);
            scene.initialisation();



            //SYSTEMS INICIALIZATION
            SceneManager.instance().setCurrentScene(scene);
            TimeManager.instance().start();
            ViewSystem.instance().start(picture.sprite);


            BrushManager.instance().start(image);
            BrushManager.instance().AddColor(waterP, "water");
            BrushManager.instance().AddColor(fireSim.getActiveFire(), "fire");
            BrushManager.instance().AddColor(sand1, "sand");
            BrushManager.instance().AddColor(wood, "wood");

            UI_SYSTEM.instance().start();

            //testPHYSICS
        }