示例#1
0
        protected override void Initialize()
        {
            // graphics settings
            _graphics.PreferredBackBufferWidth  = graphicState.windowWidth;
            _graphics.PreferredBackBufferHeight = graphicState.windowHeight;
            _graphics.ApplyChanges();

            base.Initialize();
            this.Window.AllowUserResizing = false;

            // elements setup
            Element.SetupElements();

            // gamemaps setting up
            gameMap = new GameMap(graphicState.windowWidth / graphicState.particleSize,
                                  graphicState.windowHeight / graphicState.particleSize - 20);
            partMap = gameMap.GetParticleMap();
            tempMap = gameMap.GetTemperatureMap();
            /* fluidMap = gameMap.GetFluidMap(); */

            // custom graphics class setup
            graphics = new Graphics(this, gameMap, spriteBatch);

            uiManager.Setup(this, partMap, tempMap);
        }
示例#2
0
        public void Update(ParticleMap partMap, TemperatureMap tempMap)
        {
            UpdateReaction(partMap, tempMap);

            if (!stable)
            {
                UpdatePosition(partMap);
            }
            else
            {
                stableTime++;
            }

            if (Element.elements[ID].MaxLifeTime > 0)
            {
                lifeTime++;
            }
        }
示例#3
0
        void UpdateReaction(ParticleMap partMap, TemperatureMap tempMap)
        {
            bool pass;

            if (!stable)
            {
                pass = stable;
            }
            else
            {
                // even if stable check for reactions regularly (tanks performance)
                pass = !(stableTime % 10 == 0);
            }
            ElementID result = Element.elements[ID].UpdateReaction(pos, lifeTime, pass, partMap, tempMap);

            if (result != this.ID)
            {
                SetStable(false);
                partMap.UnstableSurroundingParticles(this.pos);
                unstableTimeout = 0;

                if (result == ElementID.VOID) // void == deleted
                {
                    partMap.DeleteLater(this.pos, 0);
                    SetStable(true); //dont update pos after deleting
                }
                else if (result == ElementID.EXPLOSION)
                {
                    partMap.DeleteLater(this.pos, 0);
                    partMap.SpawnLater(ElementID.FIRE, this.pos, Element.elements[ID].ExplosivePwr);
                    SetStable(true); //dont update pos after deleting
                }
                else
                {
                    this.ID       = result;
                    this.lifeTime = 0;
                }
            }
        }
示例#4
0
 public void DrawTemperature(TemperatureMap tempMap)
 {
     shapes.Begin();
     tempMap.Render(shapes, particleSize);
     shapes.End();
 }
示例#5
0
        public ElementID UpdateReaction(Point pos, int lifeTime, bool stable, ParticleMap partMap, TemperatureMap tempMap)
        {
            if (!stable)
            {
                foreach (Reaction r in this.reactions) // evaluate all possible reactions
                {
                    if (r.Eval(pos, partMap, out List <ElementID> result, out Point destroy))
                    {
                        //spawn other results around this particle
                        for (int i = 1; i < result.Count; i++)
                        {
                            if (partMap.Type(new Point(pos.X, pos.Y - 1)) == ElementID.AIR)
                            {
                                partMap.SpawnLater(result[i], new Point(pos.X, pos.Y - 1), 1);
                            }

                            else if (partMap.Type(new Point(pos.X, pos.Y + 1)) == ElementID.AIR)
                            {
                                partMap.SpawnLater(result[i], new Point(pos.X, pos.Y + 1), 1);
                            }

                            else if (partMap.Type(new Point(pos.X - 1, pos.Y)) == ElementID.AIR)
                            {
                                partMap.SpawnLater(result[i], new Point(pos.X - 1, pos.Y), 1);
                            }

                            else if (partMap.Type(new Point(pos.X + 1, pos.Y)) == ElementID.AIR)
                            {
                                partMap.SpawnLater(result[i], new Point(pos.X + 1, pos.Y), 1);
                            }
                        }

                        if (partMap.InBounds(destroy))
                        {
                            partMap.DeleteLater(destroy, 0);
                        }

                        return(result[0]);
                    }
                }
            }

            // evaluate preset transitional reactons
            if (lowLevelTempTransition != null && tempMap.Get(pos) <= lowLevelTemp)
            {
                if (lowLevelTempTransition.Eval(pos, partMap, out List <ElementID> result, out Point destroy))
                {
                    tempMap.Set(pos, 0, tempMap.Get(pos) * 1.05f);
                    return(result[0]);
                }
            }
            if (highLevelTempTransition != null && tempMap.Get(pos) >= highLevelTemp)
            {
                if (highLevelTempTransition.Eval(pos, partMap, out List <ElementID> result, out Point destroy))
                {
                    tempMap.Set(pos, 0, tempMap.Get(pos) * 0.95f);
                    return(result[0]);
                }
            }

            if (endOfLifeTransition != null && lifeTime > this.maxLifeTime)
            {
                if (endOfLifeTransition.Eval(pos, partMap, out List <ElementID> result, out Point destroy))
                {
                    return(result[0]);
                }
            }

            return(this.ID);
        }
示例#6
0
        public void Setup(MainGame game, ParticleMap partMap, TemperatureMap tempMap)
        {
            this.partMap = partMap;
            this.tempMap = tempMap;

            ElementID[]   specialCategory = new ElementID[] { ElementID.WALL, ElementID.FIRE, ElementID.HOT, ElementID.COLD, ElementID.ERASE, ElementID.ERASEP };
            List <UIItem> solids          = new List <UIItem>();
            List <UIItem> liquids         = new List <UIItem>();
            List <UIItem> gasses          = new List <UIItem>();
            List <UIItem> specials        = new List <UIItem>();

            List <UIItem> elementSelectMenu = new List <UIItem>();
            List <UIItem> drawStylesMenu    = new List <UIItem>();
            List <UIItem> optionsMenu       = new List <UIItem>();
            List <UIItem> fileFunctionsMenu = new List <UIItem>();
            List <UIItem> defaultMenu       = new List <UIItem>();

            // X buttons
            Vector2 backButtonPos   = new Vector2(graphicState.windowWidth - 30, graphicState.windowHeight - 95);
            int     backButtonWidth = 25;

            elementSelectMenu.Add(new MenuButton(defaultMenu, "menu",
                                                 "X",
                                                 "smallButtonFont",
                                                 backButtonPos,
                                                 backButtonWidth,
                                                 backButtonWidth,
                                                 2,
                                                 Color.White,
                                                 Color.DimGray,
                                                 "default"));

            optionsMenu.Add(new MenuButton(defaultMenu, "menu",
                                           "X",
                                           "smallButtonFont",
                                           backButtonPos,
                                           backButtonWidth,
                                           backButtonWidth,
                                           2,
                                           Color.White,
                                           Color.DimGray));


            // elementButtons
            Vector2 startPosition = new Vector2(230, graphicState.windowHeight - 82);
            int     butWidth      = 70;
            int     butHeight     = 25;
            int     borderWidth   = 2;
            Vector2 butXOffset    = new Vector2(butWidth + 6, 0);
            Vector2 butYOffset    = new Vector2(0, butHeight + 6);

            foreach (ElementID id in specialCategory)
            {
                if (Element.elements.ContainsKey(id))
                {
                    Element elem = Element.elements[id];

                    specials.Add(new ElementButton(id,
                                                   elem.Short,
                                                   "smallButtonFont",
                                                   startPosition + specials.Count * butXOffset,
                                                   butWidth, butHeight, borderWidth,
                                                   elem.Color,
                                                   elem.Color));
                }
            }

            foreach (ElementID id in Enum.GetValues(typeof(ElementID)))
            {
                if (Element.elements.ContainsKey(id) && id != ElementID.AIR && id != ElementID.VOID)
                {
                    Element elem = Element.elements[id];
                    if (elem.UIExclude)
                    {
                        continue;
                    }

                    if (!specialCategory.Contains(id))
                    {
                        switch (elem.State)
                        {
                        case 0:
                            solids.Add(new ElementButton(id,
                                                         elem.Short,
                                                         "smallButtonFont",
                                                         startPosition + (solids.Count % 7) * butXOffset + (solids.Count / 7) * butYOffset,
                                                         butWidth, butHeight, borderWidth,
                                                         elem.Color,
                                                         elem.Color));
                            break;

                        case 1:
                            liquids.Add(new ElementButton(id,
                                                          elem.Short,
                                                          "smallButtonFont",
                                                          startPosition + (liquids.Count % 7) * butXOffset + (liquids.Count / 7) * butYOffset,
                                                          butWidth, butHeight, borderWidth,
                                                          elem.Color,
                                                          elem.Color));
                            break;

                        case 2:
                            gasses.Add(new ElementButton(id,
                                                         elem.Short,
                                                         "smallButtonFont",
                                                         startPosition + (gasses.Count % 7) * butXOffset + (gasses.Count / 7) * butYOffset,
                                                         butWidth, butHeight, borderWidth,
                                                         elem.Color,
                                                         elem.Color));
                            break;
                        }
                    }
                }
            }

            // ELEMENT SELECT MENU
            elementSelectMenu.Add(new MenuButton(solids, "active",
                                                 "Solids",
                                                 "buttonFont",
                                                 new Vector2(7, graphicState.windowHeight - 85),
                                                 92, 30, 2,
                                                 Color.White,
                                                 Color.DimGray));

            elementSelectMenu.Add(new MenuButton(liquids, "active",
                                                 "Liquids",
                                                 "buttonFont",
                                                 new Vector2(109, graphicState.windowHeight - 85),
                                                 92, 30, 2,
                                                 Color.White,
                                                 Color.DimGray));

            elementSelectMenu.Add(new MenuButton(gasses, "active",
                                                 "Gasses",
                                                 "buttonFont",
                                                 new Vector2(7, graphicState.windowHeight - 45),
                                                 92, 30, 2,
                                                 Color.White,
                                                 Color.DimGray));

            elementSelectMenu.Add(new MenuButton(specials, "active",
                                                 "Specials",
                                                 "buttonFont",
                                                 new Vector2(109, graphicState.windowHeight - 45),
                                                 92, 30, 2,
                                                 Color.White,
                                                 Color.DimGray));

            // DRAWSTYLES MENU
            startPosition = new Vector2(graphicState.windowWidth - 220, graphicState.windowHeight - 87);
            drawStylesMenu.Add(new DrawStyleButton(GraphicState.DRAWSTYLES.PARTICLE,
                                                   "Particles - (F1)",
                                                   "smallButtonFont",
                                                   startPosition,
                                                   200, 35, borderWidth,
                                                   Color.White,
                                                   Color.Green));

            drawStylesMenu.Add(new DrawStyleButton(GraphicState.DRAWSTYLES.TEMPERATURE,
                                                   "Temperatures - (F2)",
                                                   "smallButtonFont",
                                                   startPosition + new Vector2(-10, 41),
                                                   220, 35, borderWidth,
                                                   Color.White,
                                                   Color.DarkRed));

            // OPTIONS MENU
            startPosition = new Vector2(45, graphicState.windowHeight - 67);

            optionsMenu.Add(new RadioButton(gameState.SetDescriptor,
                                            "drawBoard",
                                            false,
                                            "Show map board",
                                            "smallButtonFont",
                                            startPosition,
                                            185, 34, borderWidth,
                                            Color.White,
                                            Color.DimGray));


            optionsMenu.Add(new RadioButton(gameState.SetDescriptor,
                                            "selectedId",
                                            false,
                                            "Show selected",
                                            "smallButtonFont",
                                            startPosition + new Vector2(200, 0),
                                            160, 34, borderWidth,
                                            Color.White,
                                            Color.DimGray));

            optionsMenu.Add(new RadioButton(gameState.SetDescriptor,
                                            "cellPos",
                                            false,
                                            "Cell pos",
                                            "smallButtonFont",
                                            startPosition + new Vector2(375, 0),
                                            100, 34, borderWidth,
                                            Color.White,
                                            Color.DimGray));

            optionsMenu.Add(new RadioButton(gameState.SetDescriptor,
                                            "cellId",
                                            false,
                                            "Cell ID",
                                            "smallButtonFont",
                                            startPosition + new Vector2(490, 0),
                                            90, 34, borderWidth,
                                            Color.White,
                                            Color.DimGray));

            optionsMenu.Add(new RadioButton(gameState.SetDescriptor,
                                            "cellTemp",
                                            false,
                                            "Cell temp",
                                            "smallButtonFont",
                                            startPosition + new Vector2(595, 0),
                                            110, 34, borderWidth,
                                            Color.White,
                                            Color.DimGray));



            // FILE FUNCTIONALITIES MENU
            startPosition = new Vector2(graphicState.windowWidth - 180, graphicState.windowHeight - 87);
            fileFunctionsMenu.Add(new LoadSaveButton(game.SaveGame,
                                                     "Save project",
                                                     "smallButtonFont",
                                                     startPosition,
                                                     150, 35, borderWidth,
                                                     Color.White,
                                                     Color.DimGray));

            fileFunctionsMenu.Add(new LoadSaveButton(game.LoadGame,
                                                     "Load project",
                                                     "smallButtonFont",
                                                     startPosition + new Vector2(0, 41),
                                                     150, 35, borderWidth,
                                                     Color.White,
                                                     Color.DimGray));

            // DEFALUT MENU WITH ALL OPTIONS
            startPosition = new Vector2(15, graphicState.windowHeight - 70);
            defaultMenu.Add(new MenuButton(elementSelectMenu, "menu",
                                           "Elements",
                                           "buttonFont",
                                           startPosition,
                                           110, 40, borderWidth,
                                           Color.White,
                                           Color.DimGray,
                                           "elements"));

            defaultMenu.Add(new MenuButton(drawStylesMenu, "active",
                                           "Draw options",
                                           "buttonFont",
                                           startPosition + new Vector2(120, 0),
                                           150, 40, borderWidth,
                                           Color.White,
                                           Color.DimGray));

            defaultMenu.Add(new MenuButton(optionsMenu, "menu",
                                           "Options",
                                           "buttonFont",
                                           startPosition + new Vector2(280, 0),
                                           100, 40, borderWidth,
                                           Color.White,
                                           Color.DimGray));

            defaultMenu.Add(new MenuButton(fileFunctionsMenu, "active",
                                           "Files",
                                           "buttonFont",
                                           startPosition + new Vector2(390, 0),
                                           100, 40, borderWidth,
                                           Color.White,
                                           Color.DimGray));



            SetMenuElements(defaultMenu);
        }
示例#7
0
        public void Spawn(ElementID element, Point position, int size = 1)
        {
            if (!InBounds(position))
            {
                return;
            }

            tempMap = gameMap.GetTemperatureMap();

            if (size == 0)
            {
                if (!InBounds(position))
                {
                    return;
                }

                if (Type(position) == ElementID.AIR)
                {
                    if (!Element.elements.ContainsKey(element))
                    {
                        throw new Exception("Element: " + element + " not introduced in the elements dictionary yet.\nTry adding to ElementsSetup first.\n");
                    }

                    Particle p = new Particle(element, position);
                    particles[GetParticleID(position)] = p;
                    tempMap.Set(position, 0, Element.elements[element].STemp);
                }
            }
            else
            {
                int offset;
                if (size < 20)
                {
                    offset = 4;
                }
                else if (size < 50)
                {
                    offset = 6;
                }
                else
                {
                    offset = 10;
                }

                for (int y = size; y > -size; y--)
                {
                    for (int x = -size; x < size; x++)
                    {
                        if (size + offset >= x * x + y * y)
                        {
                            int   _x        = position.X + x;
                            int   _y        = position.Y + y;
                            Point _position = new Point(_x, _y);

                            if (!InBounds(_position))
                            {
                                continue;
                            }

                            if (Type(_position) == ElementID.AIR)
                            {
                                if (!Element.elements.ContainsKey(element))
                                {
                                    throw new Exception("Element: " + element + " not introduced in the elements dictionary yet.\nTry adding to ElementsSetup first.\n");
                                }

                                Particle p = new Particle(element, _position);
                                particles[GetParticleID(_position)] = p;
                                tempMap.Set(_position, 0, Element.elements[element].STemp);
                            }
                        }
                    }
                }
            }
        }