private void Button_convert_toNo_Click(object sender, RoutedEventArgs e) { ElementID eid = new ElementID(TextBox_ElementIDStr.Text); Tuple <UInt64, UInt64> eidNo = eid.ElementIDNo; TextBox_ElementIDNo.Text = "[ " + eidNo.Item1.ToString() + ", " + eidNo.Item2.ToString() + " ]"; }
public static string Color(ElementID iElement) { var stringBuilder = new StringBuilder("\\cf"); stringBuilder.Append((int)iElement); stringBuilder.Append(" "); return(stringBuilder.ToString()); }
private void AddElement(ElementID e) { activeElements.AddElement(e); if (!inventory.GetInventory().Contains(e.elementID)) { inventory.AddToInventory(e.elementID); grid.AddLastToGrid(); } }
public Reaction(ElementID FROM, List <ElementID> TO, ElementID NEED, int minNEEDAmount, float probability, bool destroyOther = false) { this.FROM = FROM; this.TO = TO; this.NEED = NEED; this.minNEEDAmount = minNEEDAmount; this.probability = probability; this.destroyOther = destroyOther; this.random = MainGame.random; }
public Particle(ElementID ID, Point position) { this.ID = ID; this.pos = position; this.stable = false; this.unstableTimeout = 0; this.stableTime = 0; this.lifeTime = 0; }
public void Set(Point position, int size, ElementID element) { if (InBounds(position)) { map[position.X, position.Y] += 10f; } else { new Exception("Out of bounds exception - fluidMap - set"); } }
public ElementButton(ElementID toSelect, string text, string font, Vector2 position, int width, int height, int borderWidth, Color textColor, Color borderColor) : base(text, font, position, width, height, borderWidth, textColor, borderColor) { this.toSelect = toSelect; }
private void DrawElementDescription(Shapes shapes) { ElementID id = gameState.currElement; if (Element.elements.ContainsKey(id) && id != ElementID.AIR && id != ElementID.VOID) { shapes.DrawText(Element.elements[id].Description, "smallButtonFont", new Vector2(graphicState.windowWidth - 8, graphicState.windowHeight - 8), Color.DimGray, anchorX: 2); } }
private void Button_convert_toStr_Click(object sender, RoutedEventArgs e) { string tmp = TextBox_ElementIDNo.Text; tmp = tmp.Replace("[", "").Replace("]", "").Trim(); string[] members = tmp.Split(','); UInt64 upperPart = UInt64.Parse(members[0]); UInt64 lowerPart = UInt64.Parse(members[1]); ElementID eid = new ElementID(new Tuple <UInt64, UInt64>(upperPart, lowerPart)); TextBox_ElementIDStr.Text = eid.ElementIDString; }
public ElementID[,] Save() { ElementID[,] save = new ElementID[width, height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { save[x, y] = Type(new Point(x, y)); } } return(save); }
/// <summary> /// Indicates if an object is the same, checking the id of the element. /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (obj == null) { return(false); } if (GetType() != obj.GetType()) { return(false); } // safe because of the GetType check CMElementUI ele = (CMElementUI)obj; // use this pattern to compare value members if (!ElementID.Equals(ele.ElementID)) { return(false); } return(true); }
private void CheckForClick() { if (Input.GetMouseButtonDown(0)) { GraphicRaycaster raycaster = transform.GetComponent <GraphicRaycaster>(); PointerEventData eventData = new PointerEventData(null); eventData.position = Input.mousePosition; List <RaycastResult> objectsHit = new List <RaycastResult>(); raycaster.Raycast(eventData, objectsHit); if (objectsHit.Count > 0) { if (objectsHit[0].gameObject.tag.Equals("Element") && objectsHit[0].gameObject.transform.parent.tag.Equals("InventoryView")) { elementSelected = objectsHit[0].gameObject.GetComponent <ElementID>(); } } } }
public void OnBeginDrag(PointerEventData eventData) { if (parent != transform.parent) { if (parent.GetComponentInParent <Canvas>().enabled) { element = gameObject.GetComponent <ElementID>(); elementBeingDragged = (GameObject)Instantiate(eleDB.GetElementByID(element.elementID).GetUIPrefab(), parent); elementBeingDragged.transform.SetAsLastSibling(); draggingFromInventory = true; } } else { elementBeingDragged = gameObject; elementBeingDragged.transform.SetAsLastSibling(); draggingFromInventory = false; } startPosition = transform.position; }
private GameState(ElementID selected, Vector2 position, Point cursorBoardPosition, int cursorSize) { this.graphicState = GraphicState.instance; this.currElement = selected; this.cursorPosition = position; this.cursorBoardPosition = cursorBoardPosition; this.cursorSize = cursorSize; this.boardBounds = new Point(graphicState.windowWidth / graphicState.particleSize, graphicState.windowHeight / graphicState.particleSize); maxCursorSize = 100; simDescriptors.Add("drawStyle", false); simDescriptors.Add("drawBoard", false); simDescriptors.Add("selectedId", false); simDescriptors.Add("cellPos", false); simDescriptors.Add("cellId", false); simDescriptors.Add("cellTemp", false); }
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; } } }
private void CheckForCombination(ElementID element2) { int id1 = elementBeingDragged.GetComponent <ElementID>().elementID; int id2 = element2.elementID; int[] comboID = comboDB.GetCombinations(id1, id2); if (comboID.Length > 0) { foreach (int i in comboID) { GameObject newObj = Instantiate(eleDB.GetElementByID(i).GetUIPrefab(), parent); newObj.transform.position = elementBeingDragged.transform.position; ElementID newElement = newObj.GetComponent <ElementID>(); AddElement(newElement); } RemoveElement(elementBeingDragged.GetComponent <ElementID>()); RemoveElement(element2); } }
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); }
private void CheckForAssignment() { //Check which slot the user wants to add to if (Input.GetKeyDown(keySlot1)) { slotSelected = 1; } else if (Input.GetKeyDown(keySlot2)) { slotSelected = 2; } else if (Input.GetKeyDown(keySlot3)) { slotSelected = 3; } else if (Input.GetKeyDown(keySlot4)) { slotSelected = 4; } else if (Input.GetKeyDown(keySlot5)) { slotSelected = 5; } else if (Input.GetKeyDown(keySlot6)) { slotSelected = 6; } else if (Input.GetKeyDown(keySlot7)) { slotSelected = 7; } else if (Input.GetKeyDown(keySlot8)) { slotSelected = 8; } else if (Input.GetKeyDown(keySlot9)) { slotSelected = 9; } //If they've selected an element and a slot if (elementSelected && slotSelected > 0) { bool creatable = db.GetElementByID(elementSelected.elementID).IsCreatable(); //Checks to see if the element is creatable in the world if (creatable) { string slotName = "Slot " + slotSelected; //Set the UI Image GameObject slot = GameObject.Find(slotName); Image slotImage = slot.GetComponent <Image>(); slotImage.sprite = db.GetElementByID(elementSelected.elementID).GetUIPrefab().GetComponent <Image>().sprite; //Set the element id slot.GetComponent <ElementID>().elementID = elementSelected.elementID; slotName = "UISlot " + slotSelected; //Set the UI Image slot = GameObject.Find(slotName); slotImage = slot.GetComponent <Image>(); slotImage.sprite = db.GetElementByID(elementSelected.elementID).GetUIPrefab().GetComponent <Image>().sprite; } else { Debug.Log("Cannot create this element"); //Notify the user that this element is not creatable in the world } elementSelected = null; //reset the selected item } slotSelected = 0; }
private void Awake() { elementId = GetComponent <ElementID>(); }
public bool Eval(Point pos, ParticleMap partMap, out List <ElementID> result, out Point destroy) // true if reaction occured and out is the result element { result = new List <ElementID>() { FROM }; destroy = new Point(-1, -1); if (NEED == ElementID.VOID) // time/prob based reactions { if (random.NextDouble() <= probability) { result = TO; return(true); } } else if (NEED != ElementID.MOLTEN) // element based reactions { int occurence = 0; Point testPos = new Point(); ElementID type; for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { testPos.X = pos.X + x; testPos.Y = pos.Y + y; type = partMap.Type(testPos); if (type == NEED) { occurence++; if (destroyOther) { destroy = testPos; } } } } if (occurence >= minNEEDAmount) { if (random.NextDouble() <= probability) { result = TO; return(true); } } } else // special reaction with molten elements { ElementID moltenElement = ElementID.VOID; int occurence = 0; Point testPos = new Point(); ElementID type; for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { testPos.X = pos.X + x; testPos.Y = pos.Y + y; type = partMap.Type(testPos); if (type == ElementID.COPPERMELT || type == ElementID.TINMELT || type == ElementID.BRONZEMELT) { occurence++; moltenElement = type; if (destroyOther) { destroy = testPos; } } } } if (occurence >= minNEEDAmount) { if (random.NextDouble() <= probability) { if (TO[0] == ElementID.MOLTEN) { result = new List <ElementID>() { moltenElement } } ; else { result = TO; } return(true); } } } return(false); }
public Reaction(ElementID FROM, List <ElementID> TO, float probability) : this(FROM, TO, ElementID.VOID, 0, probability) { }
public void collectSpatialIndexAndInsert(Octree octreeInstance, int federatedId) { string sqlStmt = "INSERT INTO " + DBOperation.formatTabName("BIMRL_SPATIALINDEX", federatedId) + " (ELEMENTID, CELLID, XMinBound, YMinBound, ZMinBound, XMaxBound, YMaxBound, ZMaxBound, Depth) " + "VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9)"; OracleCommand commandIns = new OracleCommand(" ", DBOperation.DBConn); commandIns.CommandText = sqlStmt; OracleParameter[] spatialIdx = new OracleParameter[9]; spatialIdx[0] = commandIns.Parameters.Add("1", OracleDbType.Varchar2); spatialIdx[0].Direction = ParameterDirection.Input; spatialIdx[1] = commandIns.Parameters.Add("2", OracleDbType.Varchar2); spatialIdx[1].Direction = ParameterDirection.Input; spatialIdx[2] = commandIns.Parameters.Add("3", OracleDbType.Int32); spatialIdx[2].Direction = ParameterDirection.Input; spatialIdx[3] = commandIns.Parameters.Add("4", OracleDbType.Int32); spatialIdx[3].Direction = ParameterDirection.Input; spatialIdx[4] = commandIns.Parameters.Add("5", OracleDbType.Int32); spatialIdx[4].Direction = ParameterDirection.Input; spatialIdx[5] = commandIns.Parameters.Add("6", OracleDbType.Int32); spatialIdx[5].Direction = ParameterDirection.Input; spatialIdx[6] = commandIns.Parameters.Add("7", OracleDbType.Int32); spatialIdx[6].Direction = ParameterDirection.Input; spatialIdx[7] = commandIns.Parameters.Add("8", OracleDbType.Int32); spatialIdx[7].Direction = ParameterDirection.Input; spatialIdx[8] = commandIns.Parameters.Add("9", OracleDbType.Int32); spatialIdx[8].Direction = ParameterDirection.Input; int initArraySize = 1000; List <string> elementIDList = new List <string>(initArraySize); List <string> cellIDStrList = new List <string>(initArraySize); List <int> XMinB = new List <int>(initArraySize); List <int> YMinB = new List <int>(initArraySize); List <int> ZMinB = new List <int>(initArraySize); List <int> XMaxB = new List <int>(initArraySize); List <int> YMaxB = new List <int>(initArraySize); List <int> ZMaxB = new List <int>(initArraySize); List <int> depthList = new List <int>(initArraySize); int XMin; int YMin; int ZMin; int XMax; int YMax; int ZMax; int recCount = 0; for (int i = 0; i < octreeInstance.MasterDictClass.DictEntryCount; ++i) { foreach (KeyValuePair <UInt64, CellData> dictEntry in octreeInstance.MasterDictClass.GetElementAt(i)) { CellID64 cellID = new CellID64(dictEntry.Key); string cellIDstr = cellID.ToString(); CellID64.getCellIDComponents(cellID, out XMin, out YMin, out ZMin, out XMax, out YMax, out ZMax); int cellLevel = CellID64.getLevel(cellID); if (dictEntry.Value.data != null && dictEntry.Value.nodeType != 0) { foreach (int tupEID in dictEntry.Value.data) { List <int> cBound = new List <int>(); ElementID eID = new ElementID(Octree.getElementIDByIndex(tupEID)); elementIDList.Add(eID.ElementIDString); //cellIDStrList.Add(cellID.ToString()); cellIDStrList.Add(cellIDstr); //CellID64.getCellIDComponents(cellID, out XMin, out YMin, out ZMin, out XMax, out YMax, out ZMax); XMinB.Add(XMin); YMinB.Add(YMin); ZMinB.Add(ZMin); XMaxB.Add(XMax); YMaxB.Add(YMax); ZMaxB.Add(ZMax); //depthList.Add(CellID64.getLevel(cellID)); depthList.Add(cellLevel); } } try { recCount = elementIDList.Count; if (recCount >= initArraySize) { spatialIdx[0].Value = elementIDList.ToArray(); spatialIdx[0].Size = recCount; spatialIdx[1].Value = cellIDStrList.ToArray(); spatialIdx[1].Size = recCount; spatialIdx[2].Value = XMinB.ToArray(); spatialIdx[2].Size = recCount; spatialIdx[3].Value = YMinB.ToArray(); spatialIdx[3].Size = recCount; spatialIdx[4].Value = ZMinB.ToArray(); spatialIdx[4].Size = recCount; spatialIdx[5].Value = XMaxB.ToArray(); spatialIdx[5].Size = recCount; spatialIdx[6].Value = YMaxB.ToArray(); spatialIdx[6].Size = recCount; spatialIdx[7].Value = ZMaxB.ToArray(); spatialIdx[7].Size = recCount; spatialIdx[8].Value = depthList.ToArray(); spatialIdx[8].Size = recCount; commandIns.ArrayBindCount = recCount; int commandStatus = commandIns.ExecuteNonQuery(); DBOperation.commitTransaction(); elementIDList.Clear(); cellIDStrList.Clear(); XMinB.Clear(); YMinB.Clear(); ZMinB.Clear(); XMaxB.Clear(); YMaxB.Clear(); ZMaxB.Clear(); depthList.Clear(); } } catch (OracleException e) { string excStr = "%%Insert Spatial Index Error - " + e.Message + "\n\t"; _refBIMRLCommon.StackPushError(excStr); } catch (SystemException e) { string excStr = "%%Insert Spatial Index Error - " + e.Message + "\n\t"; _refBIMRLCommon.StackPushError(excStr); throw; } } } // At last if there are entries in the list, insert them try { recCount = elementIDList.Count; if (recCount > 0) { spatialIdx[0].Value = elementIDList.ToArray(); spatialIdx[0].Size = recCount; spatialIdx[1].Value = cellIDStrList.ToArray(); spatialIdx[1].Size = recCount; spatialIdx[2].Value = XMinB.ToArray(); spatialIdx[2].Size = recCount; spatialIdx[3].Value = YMinB.ToArray(); spatialIdx[3].Size = recCount; spatialIdx[4].Value = ZMinB.ToArray(); spatialIdx[4].Size = recCount; spatialIdx[5].Value = XMaxB.ToArray(); spatialIdx[5].Size = recCount; spatialIdx[6].Value = YMaxB.ToArray(); spatialIdx[6].Size = recCount; spatialIdx[7].Value = ZMaxB.ToArray(); spatialIdx[7].Size = recCount; spatialIdx[8].Value = depthList.ToArray(); spatialIdx[8].Size = recCount; commandIns.ArrayBindCount = recCount; int commandStatus = commandIns.ExecuteNonQuery(); DBOperation.commitTransaction(); elementIDList.Clear(); cellIDStrList.Clear(); XMinB.Clear(); YMinB.Clear(); ZMinB.Clear(); XMaxB.Clear(); YMaxB.Clear(); ZMaxB.Clear(); depthList.Clear(); } } catch (OracleException e) { string excStr = "%%Insert Spatial Index Error - " + e.Message + "\n\t"; _refBIMRLCommon.StackPushError(excStr); } catch (SystemException e) { string excStr = "%%Insert Spatial Index Error - " + e.Message + "\n\t"; _refBIMRLCommon.StackPushError(excStr); throw; } commandIns.Dispose(); }
public void AddElement(ElementID e) { elements.Add(e); }
public void RemoveElement(ElementID e) { elements.Remove(e); }
public Point UpdatePosition(Point pos, ParticleMap partMap) { if (!this.move) { return(pos); } Point INVALID = new Point(-1, -1); List <Point> possiblePos = new List <Point>(); if (state == 0) // solids { Point DOWN = new Point(pos.X, pos.Y + 1); ElementID typeDOWN = partMap.Type(DOWN); if ((typeDOWN == ElementID.AIR) || (Element.elements[typeDOWN].weight < this.weight)) // heavier sinks { if (MainGame.random.NextDouble() <= 0.9f) // random sideways movement { return(DOWN); } else { Point DOWNLEFT = new Point(pos.X - 1, pos.Y + 1); DOWNLEFT = (partMap.Type(DOWNLEFT) == ElementID.AIR) ? DOWNLEFT : INVALID; Point DOWNRIGHT = new Point(pos.X + 1, pos.Y + 1); DOWNRIGHT = (partMap.Type(DOWNRIGHT) == ElementID.AIR) ? DOWNRIGHT : INVALID; if (DOWNLEFT == INVALID && DOWNRIGHT == INVALID) { return(DOWN); } else if (DOWNLEFT != INVALID && DOWNRIGHT != INVALID) { if (MainGame.random.NextDouble() <= 0.5f) { return(DOWNLEFT); } else { return(DOWNRIGHT); } } else if (DOWNLEFT != INVALID) { return(DOWNLEFT); } else { return(DOWNRIGHT); } } } Point testPos = new Point(); ElementID typeTestPos; for (int _y = 1; _y < 2; _y++) { for (int _x = -1; _x < 2; _x++) { testPos.X = pos.X + _x; testPos.Y = pos.Y + _y; typeTestPos = partMap.Type(testPos); if ((typeTestPos == ElementID.AIR) || (Element.elements[typeTestPos].weight < this.weight)) { possiblePos.Add(testPos); } } } } else if (state == 1) // LIQUID { Point DOWN = new Point(pos.X, pos.Y + 1); ElementID typeDOWN = partMap.Type(DOWN); if ((typeDOWN == ElementID.AIR) || (Element.elements[typeDOWN].weight < this.weight)) // heavier sinks { if (MainGame.random.NextDouble() <= 0.9f) // random sideways movement { return(DOWN); } else { Point DOWNLEFT = new Point(pos.X - 1, pos.Y + 1); DOWNLEFT = (partMap.Type(DOWNLEFT) == ElementID.AIR) ? DOWNLEFT : INVALID; Point DOWNRIGHT = new Point(pos.X + 1, pos.Y + 1); DOWNRIGHT = (partMap.Type(DOWNRIGHT) == ElementID.AIR) ? DOWNRIGHT : INVALID; if (DOWNLEFT == INVALID && DOWNRIGHT == INVALID) { return(DOWN); } else if (DOWNLEFT != INVALID && DOWNRIGHT != INVALID) { if (MainGame.random.NextDouble() <= 0.5f) { return(DOWNLEFT); } else { return(DOWNRIGHT); } } else if (DOWNLEFT != INVALID) { return(DOWNLEFT); } else { return(DOWNRIGHT); } } } Point testPos = new Point(); ElementID typeTestPos; for (int _y = 0; _y < 2; _y++) { for (int _x = -1; _x < 2; _x++) { testPos.X = pos.X + _x; testPos.Y = pos.Y + _y; typeTestPos = partMap.Type(testPos); if ((typeTestPos == ElementID.AIR) || (Element.elements[typeTestPos].weight < this.weight)) { possiblePos.Add(testPos); } } } } else if (state == 2) // GAS { Point UP = new Point(pos.X, pos.Y - 1); ElementID typeUP = partMap.Type(UP); if ((typeUP == ElementID.AIR) || (Element.elements[typeUP].weight < this.weight)) // lighter sinks { if (MainGame.random.NextDouble() <= 0.8f) // random sideways movement { return(UP); } else { Point UPLEFT = new Point(pos.X - 1, pos.Y - 1); UPLEFT = (partMap.Type(UPLEFT) == ElementID.AIR) ? UPLEFT : INVALID; Point UPRIGHT = new Point(pos.X + 1, pos.Y - 1); UPRIGHT = (partMap.Type(UPRIGHT) == ElementID.AIR) ? UPRIGHT : INVALID; if (UPLEFT == INVALID && UPRIGHT == INVALID) { return(UP); } else if (UPLEFT != INVALID && UPRIGHT != INVALID) { if (MainGame.random.NextDouble() <= 0.5f) { return(UPLEFT); } else { return(UPRIGHT); } } else if (UPLEFT != INVALID) { return(UPLEFT); } else { return(UPRIGHT); } } } Point testPos = new Point(); ElementID typeTestPos; for (int _y = 0; _y > -2; _y--) { for (int _x = -1; _x < 2; _x++) { testPos.X = pos.X + _x; testPos.Y = pos.Y + _y; typeTestPos = partMap.Type(testPos); if ((typeTestPos == ElementID.AIR) || (Element.elements[typeTestPos].weight < this.weight)) { possiblePos.Add(testPos); } } } } if (possiblePos.Count != 0) // choose random from possible positions { return(possiblePos[MainGame.random.Next(0, possiblePos.Count)]); } else { return(pos); } }
public void SelectElement(ElementID element) { this.currElement = element; }
public BuildingResource(ElementID elementID, float amount) { this.elementID = elementID; this.amount = amount; }
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); } } } } } }
public void SpawnLater(ElementID element, Point position, int size = 1) { toSpawn_elem.Add(element); toSpawn_pos.Add(position); toSpawn_size.Add(size); }
private void RemoveElement(ElementID e) { activeElements.RemoveElement(e); Destroy(e.gameObject); }