/// <summary> /// /// </summary> /// <param name="node"></param> /// <returns></returns> static TileDrawing GetTileDrawing(XmlNode node) { if (node == null) { return(null); } // Tile id int id = int.Parse(node.Attributes["tile"].Value); // Location Point location = new Point(int.Parse(node.Attributes["x"].Value), int.Parse(node.Attributes["y"].Value)); // effect SpriteEffects effect = SpriteEffects.None; if (node.Attributes["effect"] != null) { effect = (SpriteEffects)Enum.Parse(typeof(SpriteEffects), node.Attributes["effect"].Value); } CardinalPoint side = CardinalPoint.North; if (node.Attributes["side"] != null) { side = (CardinalPoint)Enum.Parse(typeof(CardinalPoint), node.Attributes["side"].Value, true); } return(new TileDrawing(id, location, side, effect)); }
private void GetLeft(Dictionary <int, Cell> tree, int currentCellIdentifier, CardinalPoint direction) { tree[currentCellIdentifier].Visited = true; visited.Add(currentCellIdentifier); solution.Add(currentCellIdentifier); List <CardinalPoint> order = this.GetOrderFromDirection(direction); if (tree[currentCellIdentifier].Type == CellType.End) { endFound = true; return; } foreach (CardinalPoint newDirection in order) { Cell tmpCell = tree[currentCellIdentifier]; if (tmpCell.Neighbours.ContainsKey(newDirection) && !tree[tmpCell.Neighbours[newDirection].Identifier].Visited) { this.GetLeft(tree, tmpCell.Neighbours[newDirection].Identifier, newDirection); if (endFound) { return; } } } solution.RemoveAt(solution.Count - 1); }
void TurnOffSprite(CardinalPoint dir) { GameObject go = sprites[((int)dir) - 1]; go.GetComponent <SpriteRenderer>().enabled = false; go.GetComponent <Animator>().SetBool("Moving", false); }
/// <summary> /// Mouse click on the door /// </summary> /// <param name="location">Location of the click</param> /// <param name="side">Wall side</param> /// <param name="button">Mouse button state</param> /// <returns>True if the event is handled</returns> public override bool OnClick(Point location, CardinalPoint side, MouseButtons button) { // Button if (HasButton && Button.Contains(location)) { if (State == DoorState.Closed || State == DoorState.Closing) { Open(); } else if (State == DoorState.Opened || State == DoorState.Opening) { Close(); } return(true); } else { // Try to force the door if (State != DoorState.Opened) { GameMessage.AddMessage("No one is able to pry this door open."); return(true); } } return(false); }
/// <summary> /// Constructor /// </summary> /// <param name="monster">Monster handle</param> /// <param name="range">Range of the target</param> /// <param name="direction">Direction of the target</param> public MoveState(Monster monster, int range, CardinalPoint direction) : base(monster) { TargetRange = range; TargetDirection = direction; TargetLocation = new DungeonLocation(Monster.Location); TargetLocation.Offset(direction, range); }
public void RoverShouldNotMoveInBorders(int coordX, int coordY, CardinalPoint cardinalPoint) { var roverStatic = new Robot { Position = new CoordinatePoint { CoordX = coordX, CoordY = coordY }, FacingTo = cardinalPoint }; var roverMoving = new Robot { Position = new CoordinatePoint { CoordX = coordX, CoordY = coordY }, FacingTo = cardinalPoint }; var robotAction = new RobotAction(new RoverCreator(new RoverBuilder())); robotAction.MoveForward(roverMoving); Assert.AreEqual(roverStatic.FacingTo, roverMoving.FacingTo); Assert.AreEqual(roverStatic.Position.CoordX, roverMoving.Position.CoordX); Assert.AreEqual(roverStatic.Position.CoordY, roverMoving.Position.CoordY); }
/// <summary> /// Move team despite the direction the team is facing /// (useful for forcefield) /// </summary> /// <param name="offset">Direction of the move</param> /// <param name="count">Number of square</param> public void Offset(CardinalPoint direction, int count) { Point offset = Point.Empty; switch (direction) { case CardinalPoint.North: offset = new Point(0, -1); break; case CardinalPoint.South: offset = new Point(0, 1); break; case CardinalPoint.West: offset = new Point(-1, 0); break; case CardinalPoint.East: offset = new Point(1, 0); break; } Move(offset); }
/// <summary> /// Builds a road character /// Uses a passed in type, ctor + reflection /// to get this working on both XNA and Silver /// This BUILDS a character /// It creates a Road Character with a behavior and animation /// It does NOT create the navigation path /// </summary> /// <param name="character"></param> /// <param name="row"></param> /// <param name="column"></param> /// <param name="roadDirection"></param> /// <param name="squarePosition"></param> /// <param name="boardSize"></param> /// <param name="reachHalfSquare"></param> /// <returns></returns> private IRoadCharacter BuildCharacter(int row, int column, CardinalPoint roadDirection, float squarePosition, int boardSize, bool reachHalfSquare) { object[] args = (mCanvas == null) ? new object[6] : new object[7]; args[0] = row; args[1] = column; args[2] = roadDirection; // used for FRB layering args[3] = mGopherLayer; // not used args[4] = boardSize; // not used args[5] = reachHalfSquare; if (mCanvas != null) { args[6] = mCanvas; } ConstructorInfo[] info = mControllerType.GetConstructors(); object obj = info[0].Invoke(args); IRoadCharacter character = obj as IRoadCharacter; return(character); }
/// <summary> /// Devuelve el punto cardinal contrario (Entra sur, sale norte) /// </summary> /// <param name="direction"></param> /// <returns></returns> public static CardinalPoint ReverseDirection(CardinalPoint direction) { CardinalPoint result = CardinalPoint.None; switch (direction) { case CardinalPoint.N: result = CardinalPoint.S; break; case CardinalPoint.E: result = CardinalPoint.W; break; case CardinalPoint.W: result = CardinalPoint.E; break; case CardinalPoint.S: result = CardinalPoint.N; break; case CardinalPoint.None: result = CardinalPoint.None; break; default: result = CardinalPoint.None; break; } return(result); }
/// <summary> /// Constructor /// </summary> /// <param name="maze">Name of the maze</param> /// <param name="coordinate">Location</param> /// <param name="direction">Direction</param> /// <param name="position">Square position</param> public DungeonLocation(string maze, Point coordinate, CardinalPoint direction, SquarePosition position) { Maze = maze; Coordinate = coordinate; Direction = direction; Position = position; }
private void button11_MouseMove(object sender, MouseEventArgs e) { if (sender is Button) { ((Button)sender).Focus(); } CardinalPoint tmp = value; if (sender == button10) { tmp = CardinalPoint.Centroid; } else if (sender == button11) { tmp = CardinalPoint.ShearCenter; } else if (e.X < 78 && e.Y < 78) { tmp = Points[e.Y / 26][e.X / 26]; } if (tmp != value) { value = tmp; Console.WriteLine(value); Invalidate(); } }
private List <CardinalPoint> GetOrderFromDirection(CardinalPoint direction) { List <CardinalPoint> order = new List <CardinalPoint>(); switch (direction) { case CardinalPoint.West: order.Add(CardinalPoint.South); order.Add(CardinalPoint.West); order.Add(CardinalPoint.North); break; case CardinalPoint.North: order.Add(CardinalPoint.West); order.Add(CardinalPoint.North); order.Add(CardinalPoint.East); break; case CardinalPoint.East: order.Add(CardinalPoint.North); order.Add(CardinalPoint.East); order.Add(CardinalPoint.South); break; case CardinalPoint.South: order.Add(CardinalPoint.East); order.Add(CardinalPoint.South); order.Add(CardinalPoint.West); break; } return(order); }
/// <summary> /// Consulta si esta carretera tiene la salida indicada /// </summary> /// <param name="direction"></param> /// <returns></returns> public bool HasDirection(CardinalPoint direction) { bool r = false; switch (direction) { case CardinalPoint.N: r = HasN; break; case CardinalPoint.E: r = HasE; break; case CardinalPoint.W: r = HasW; break; case CardinalPoint.S: r = HasS; break; case CardinalPoint.None: r = true; break; default: r = false; break; } return(r); }
/// <summary> /// Instantiate CargoSprites /// </summary> /// <param name="cardinalPoint">MidBox to Spawn (it CAN be 0)</param> GameObject SpawnCargoSprite(CardinalPoint cardinalPoint) { GameObject GO = (GameObject)GameObject.Instantiate(cargoSpritePrefab, midBoxes[(int)cardinalPoint], false); GO.transform.localScale = Vector3.one; return(GO); }
/// <summary> /// Fires Event OnTruckUnloaded /// </summary> /// <param name="cp"></param> /// <param name="cargo"></param> public void TruckGotUnloaded(CardinalPoint cp, Cargo cargo) { if (OnTruckUnloaded != null) { OnTruckUnloaded(cp, cargo, this); } }
/// <summary> /// A hero used an empty hand on the wall /// </summary> /// <returns>True if the event is processed</returns> public bool OnBash(CardinalPoint side, Item item) { #region Decoration must change on hack Decoration deco = Maze.GetDecoration(Location, side); if (deco != null && deco.OnHackId != -1) { // If forced decoration, then erase all other decorations if (deco.ForceDisplay) { for (int id = 0; id < 4; id++) { if (Decorations[id] != -1) { Decorations[id] = deco.OnHackId; } } } // change only this decoration else { Decorations[(int)side] = deco.OnHackId; } return(true); } #endregion GameMessage.AddMessage("Square: OnBash()"); return(false); }
/// <summary> /// SpawnsArrows /// </summary> /// <param name="cardinalPoint">Cardinal Point where to Spawn. CANT BE 0!</param> /// <param name="inner">On the inner Circle or Outer</param> void SpawnArrow(CardinalPoint cardinalPoint, Color color, bool inner = true, bool flipped = false) { GameObject prefab = arrowPrefab; if (flipped) { prefab = flippedArrowPrefab; } List <Transform> list = centerPanelArrows; if (!inner) { list = outterPanelArrows; } GameObject GO = (GameObject)GameObject.Instantiate(prefab, list[(int)cardinalPoint], false); //GO.transform.SetParent(list[(int)cardinalPoint]); GO.transform.localScale = Vector3.one; //GO.transform.rotation = Quaternion. GO.GetComponent <ArrowCargo>().SetColor(color); if (!flipped) { // SpawnArrow(cardinalPoint, color, !inner, true); } }
public override void TruckOnPointListener(CardinalPoint cp, Cargo cargo, CargoBuilding building) { if (!direction.Contains(cp)) { return; //Si no ha pasado por nuestro lado no hacemos nada } if (cargo.cargo != CargoType) { return; //Si est� vacio no hacemos nada } if (myCargoSpriteReference == null) { return; //FAILSAFE, en caso de que no haya referencia escrita por ManagesCargo } if (myBuilding != building) { return; //We check the building } CargoDelivered CD = GameController.s.CargosDelivered.Find(x => x.type == cargo.cargo); if (CD == null) { Debug.LogError("UNLOAD: Cannot Find CargoType: " + cargo.ToString()); return; } GameController.s.CargosDelivered[0].delivered += 1; //Cargo of type "none" (all cargo delivered) CD.delivered += 1; building.TruckGotUnloaded(cp, cargo); GameController.s.FloatingTextSpawn(building.TriggersTransform[(int)cp], "+1", enumColor.Green, "CargoSpritev2_Load", GameConfig.s.cargoColors[(int)cargo.cargo], 0f); cargo.cargo = CargoType.None; //Cargamos el vehiculo GameController.s.money += moneyGained; GameController.s.FloatingTextSpawn(building.TriggersTransform[(int)cp], "+" + moneyGained.ToString(), enumColor.Green, "Money", Color.black, 1.5f); }
/// <summary> /// Compara dos "RoadDirection" Devuelve las similitudes en array de Truckdirection /// mediante el RETURN. /// Devuelve las diferencias en array de TruckDirection mediante out. /// Ambas arrays varian entre 0 y 2 elementos /// </summary> /// <param name="thisRoad">selfroad</param> /// <param name="otherRoad">La otra carretera a comparar</param> /// <param name="diferences">OUT de array de TruckDirection</param> /// <param name="focusDifferencesOnOtherRoad">Si es false, el out "differences" devuelve=> ¿Que tiene esta carretera que no tenga "otherRoad"?. Si es true => ¿Que tiene la otra carretera que no tenga esta?</param> /// <returns>array de TruckDirection</returns> public static CardinalPoint[] Compare(this RoadDirection thisRoad, RoadDirection otherRoad, out CardinalPoint[] diferences, bool focusDifferencesOnOtherRoad = false) { bool b = focusDifferencesOnOtherRoad; //alias //Arrays temporales a llenar CardinalPoint[] diff = new CardinalPoint[2]; CardinalPoint[] result = new CardinalPoint[2]; //contadores para las arrays int i = 0; //result int e = 0; //diff //MainLoop de 1 a 4. el ENUM TruckDirection puede ser casteado a INT (y viceversa) //Nota: Enum Truckdirection. None = 0, N = 1, E = 2, W = 3, S = 4. for (int index = 1; index <= 4; index++) { //Sacamos la dirección que vamos a comprobar en este loop: CardinalPoint dir = (CardinalPoint)index; //Cast de int a TruckDirection //La comprobamos! //Si ambos tienen la direción, guaramos la similitud y se acaba el loop if (thisRoad.HasDirection(dir) && otherRoad.HasDirection(dir)) { result[i] = dir; i++; } else //Si no comprobamos si alguno de los dos tiene esa dirección { //Nota: b es el focus. //Sobre Que carretera queremos devolver las diferencias // !b = esta carretera // b = la otra carretera if (thisRoad.HasDirection(dir) && !b) { diff[e] = dir; e++; } if (otherRoad.HasDirection(dir) && b) { diff[e] = dir; e++; } } } //End of Main Loop //reconstruimos ambas arrays y devolvemos. CardinalPoint[] resultd = new CardinalPoint[result.Length]; for (int x = 0; x < result.Length; x++) { resultd[x] = result[x]; } diferences = new CardinalPoint[diff.Length]; for (int y = 0; y < diff.Length; y++) { diferences[y] = diff[y]; } return(resultd); }
private IEnumerator OpenShutters(CardinalPoint point, GameObject front, GameObject back) { yield return(new WaitForSecondsRealtime(0.5f)); if ((front == null) || (back == null)) { yield return(0); } //--- Snd --- Audio_OpenShutters.transform.SetParent(front.transform); Audio_OpenShutters.transform.localPosition = Vector3.zero; Audio_OpenShutters.Play(); //--- Snd --- float startTime = Time.time; while (Time.time - startTime < 2.0f) { front.transform.position += Vector3.up * Time.fixedDeltaTime * 0.25f; back.transform.position += Vector3.up * Time.fixedDeltaTime * 0.25f; yield return(new WaitForFixedUpdate()); } Debug.Log($"[GameMgr][{Time.fixedTime - startingTime}s] {front.name} is open."); StartCoroutine(CloseShutters(point, front, back)); }
/// <summary> /// /// </summary> /// <param name="xml"></param> /// <returns></returns> public override bool Load(XmlNode xml) { if (xml == null || xml.Name != Tag) { return(false); } foreach (XmlNode node in xml) { switch (node.Name.ToLower()) { case "side": { CardinalPoint dir = (CardinalPoint)Enum.Parse(typeof(CardinalPoint), node.Attributes["name"].Value); Alcoves[(int)dir].Load(node); } break; default: { base.Load(node); } break; } } return(true); }
protected override bool ProcessDialogKey(Keys keyData) { if (keyData == Keys.Right || keyData == Keys.Tab) { value = (CardinalPoint)nextRight[(int)value]; Invalidate(); return(true); } else if (keyData == Keys.Left) { value = (CardinalPoint)nextLeft[(int)value]; Invalidate(); return(true); } else if (keyData == Keys.Up) { value = (CardinalPoint)nextUp[(int)value]; Invalidate(); return(true); } else if (keyData == Keys.Down) { value = (CardinalPoint)nextDown[(int)value]; Invalidate(); return(true); } else if (keyData == Keys.Enter) { EndEdit(); editingControl.DropDown.Close(ToolStripDropDownCloseReason.ItemClicked); return(true); } return(base.ProcessDialogKey(keyData)); }
private void CardinalPointControl_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { EndEdit(); editingControl.DropDown.Close(ToolStripDropDownCloseReason.ItemClicked); e.Handled = true; } if (e.KeyCode == Keys.Right || e.KeyCode == Keys.Tab) { value = (CardinalPoint)nextRight[(int)value]; Invalidate(); e.Handled = true; } else if (e.KeyCode == Keys.Left) { value = (CardinalPoint)nextLeft[(int)value]; Invalidate(); e.Handled = true; } else if (e.KeyCode == Keys.Up) { value = (CardinalPoint)nextUp[(int)value]; Invalidate(); e.Handled = true; } else if (e.KeyCode == Keys.Down) { value = (CardinalPoint)nextDown[(int)value]; Invalidate(); e.Handled = true; } }
public void RefreshData() { if (Singleton <BuildingManager> .exists && transform.parent.gameObject.GetComponent <UIComponent>().isVisible) { GetComponent <UIComponent>().isVisible = true; Building b = Singleton <BuildingManager> .instance.m_buildings.m_buffer[this.m_buildingID]; this.m_buildingName.text = Singleton <BuildingManager> .instance.GetBuildingName(this.m_buildingID, default(InstanceID)); byte districtID = Singleton <DistrictManager> .instance.GetDistrict(b.m_position); string districtName = districtID == 0 ? Locale.Get("SVM_DISTRICT_NONE") : Singleton <DistrictManager> .instance.GetDistrictName(districtID); this.m_districtName.text = districtName; int count = 0; int cargo = 0; int capacity = 0; int inbound = 0; int outbound = 0; var extstr = SVMBuildingAIOverrideUtils.getBuildingOverrideExtensionStrict(b.Info); var defLevel = b.Info.m_class.m_level; SVMBuildingUtils.CalculateOwnVehicles(buildingId, ref b, extstr.GetManagedReasons(b.Info).Where(x => (x.Value.vehicleLevel ?? defLevel) == sysDef.level).Select(x => x.Key), ref count, ref cargo, ref capacity, ref inbound, ref outbound); int maxCount = SVMBuildingUtils.GetMaxVehiclesBuilding(buildingId, sysDef.vehicleType, sysDef.level); m_totalVehicles.prefix = count.ToString(); m_totalVehicles.suffix = maxCount > 0x3FFF ? "∞" : maxCount.ToString(); if (Singleton <T> .instance.GetSSD().outsideConnection) { float angle = Vector2.zero.GetAngleToPoint(VectorUtils.XZ(b.m_position)); m_directionLabel.prefix = $"{angle:n1}°"; m_directionLabel.text = " - "; m_directionLabel.suffix = CardinalPoint.getCardinalPoint(angle).ToString(); } } }
static double Sexa2DecimalDegrees(uint grados, uint minutos, double segundos, CardinalPoint CardinalPoint) { if (CardinalPoint == CardinalPoint.E || CardinalPoint == CardinalPoint.N) return grados + minutos / 60.0 + segundos / 3600.0; return -grados - minutos / 60.0 - segundos / 3600.0; }
/// <summary> /// Consulta si esta carretera tiene la salida indicada /// </summary> /// <param name="direction"></param> /// <returns></returns> public static bool HasDirection(this RoadDirection roadDirection, CardinalPoint direction) { bool r = false; switch (direction) { case CardinalPoint.N: r = roadDirection.HasN(); break; case CardinalPoint.E: r = roadDirection.HasE(); break; case CardinalPoint.W: r = roadDirection.HasW(); break; case CardinalPoint.S: r = roadDirection.HasS(); break; case CardinalPoint.None: r = true; break; default: r = false; break; } return(r); }
public void ChangeRoom(Room newRoom, CardinalPoint comingFrom) { var offset = 10; switch (comingFrom) { case CardinalPoint.NORTH: player.position = new Vector2(Constants.GameWidth / 2, offset); break; case CardinalPoint.SOUTH: player.position = new Vector2(Constants.GameWidth / 2, Constants.GameHeight - offset); break; case CardinalPoint.EAST: player.position = new Vector2(Constants.GameWidth - offset, Constants.GameHeight / 2); break; case CardinalPoint.WEST: player.position = new Vector2(offset, Constants.GameHeight / 2); break; } currentRoom = newRoom; }
/// <summary> /// Constructor /// </summary> /// <param name="id">ID of the tile</param> /// <param name="location">Display location on the screen</param> /// <param name="side">Wall side</param> /// <param name="effect">Display effect</param> public TileDrawing(int id, Point location, CardinalPoint side, SpriteEffects effect) { ID = id; Location = location; Effect = effect; Side = side; }
/// <summary> /// /// </summary> /// <param name="location"></param> /// <param name="side"></param> /// <param name="button"></param> /// <returns></returns> public override bool OnClick(Point location, CardinalPoint side, MouseButtons button) { // No decoration set if (Square.Maze.Decoration == null) { return(false); } // No decoration for the alcove Alcove alcove = GetAlcove(side); if (alcove.Decoration == -1) { return(false); } // Point not in decoration if (!Square.Maze.Decoration.IsPointInside(alcove.Decoration, location)) { return(false); } Team team = GameScreen.Team; // No item in hand if (team.ItemInHand != null) { if (!alcove.AcceptBigItems && team.ItemInHand.IsBig) { return(false); } // Run scripts alcove.AddItem(); Square.DropItemFromSide(side, team.ItemInHand); team.SetItemInHand(null); } else { // Run scripts alcove.RemoveItem(); // Set item in hand if ((button | MouseButtons.Left) == MouseButtons.Left) { team.SetItemInHand(Square.CollectItemFromSide(side)); } // Add to inventory else if ((button | MouseButtons.Right) == MouseButtons.Right && team.SelectedHero != null) { team.SelectedHero.AddToInventory(Square.CollectItemFromSide(side)); } } return(true); }
private Corridor generateCorridor(CardinalPoint mapDirection, Room lastRoom, IntInRangePicker corrLengthPicker, IntInRangePicker corrWidthPicker, CellInRangePicker cellRangePicker) { int corridorLenght = corrLengthPicker.draw(); int corridorSection = corrWidthPicker.draw(); Corridor.Orientation corrOrient = 0; Grid grid = null; Cell topLeftCell = lastRoom.topLeftVertex(); if (mapDirection == CardinalPoint.NORD) { grid = new Grid(corridorLenght, corridorSection); corrOrient = Corridor.Orientation.vertical; Cell topLeftVertexMin = lastRoom.topLeftVertex().minusSize(corridorLenght, 0); Cell topLeftVertexMax = topLeftVertexMin.plusCell(0, lastRoom.width() - corridorSection); //Excluding cells to avoid Inward and Outward Corner Walls Overlapping Cell excludeOne = topLeftVertexMin.plusCell(0, 1); Cell excludeTwo = topLeftVertexMax.minusCell(0, 1); topLeftCell = cellRangePicker.drawBetweenWithExclusion(topLeftVertexMin, topLeftVertexMax, excludeOne, excludeTwo); _logger.info("Min: " + topLeftVertexMin + " Max: " + topLeftVertexMax + " Selected: " + topLeftCell + " Exclusions: " + excludeOne + " - " + excludeTwo); } else if (mapDirection == CardinalPoint.EST) { grid = new Grid(corridorSection, corridorLenght); corrOrient = Corridor.Orientation.horizontal; Cell topLeftVertexMin = lastRoom.topRightVertex(); Cell topLeftVertexMax = topLeftVertexMin.plusCell(lastRoom.height() - corridorSection, 0); //Excluding cells to avoid Inward and Outward Corner Walls Overlapping Cell excludeOne = topLeftVertexMin.plusCell(1, 0); Cell excludeTwo = topLeftVertexMax.minusCell(1, 0); topLeftCell = cellRangePicker.drawBetweenWithExclusion(topLeftVertexMin, topLeftVertexMax, excludeOne, excludeTwo); _logger.info("Min: " + topLeftVertexMin + " Max: " + topLeftVertexMax + " Selected: " + topLeftCell + " Exclusions: " + excludeOne + " - " + excludeTwo); } else if (mapDirection == CardinalPoint.SUD) { grid = new Grid(corridorLenght, corridorSection); corrOrient = Corridor.Orientation.vertical; Cell topLeftVertexMin = lastRoom.bottomLeftVertex(); Cell topLeftVertexMax = topLeftVertexMin.plusCell(0, lastRoom.width() - corridorSection); //Excluding cells to avoid Inward and Outward Corner Walls Overlapping Cell excludeOne = topLeftVertexMin.plusCell(0, 1); Cell excludeTwo = topLeftVertexMax.minusCell(0, 1); topLeftCell = cellRangePicker.drawBetweenWithExclusion(topLeftVertexMin, topLeftVertexMax, excludeOne, excludeTwo); _logger.info("Min: " + topLeftVertexMin + " Max: " + topLeftVertexMax + " Selected: " + topLeftCell + " Exclusions: " + excludeOne + " - " + excludeTwo); } else if (mapDirection == CardinalPoint.WEST) { grid = new Grid(corridorSection, corridorLenght); corrOrient = Corridor.Orientation.horizontal; Cell topLeftVertexMin = lastRoom.topLeftVertex().minusSize(0, corridorLenght); Cell topLeftVertexMax = topLeftVertexMin.plusCell(lastRoom.height() - corridorSection, 0); //Excluding cells to avoid Inward and Outward Corner Walls Overlapping Cell excludeOne = topLeftVertexMin.plusCell(1, 0); Cell excludeTwo = topLeftVertexMax.minusCell(1, 0); topLeftCell = cellRangePicker.drawBetweenWithExclusion(topLeftVertexMin, topLeftVertexMax, excludeOne, excludeTwo); _logger.info("Min: " + topLeftVertexMin + " Max: " + topLeftVertexMax + " Selected: " + topLeftCell + " Exclusions: " + excludeOne + " - " + excludeTwo); } return(new Corridor(topLeftCell, grid, corrOrient)); }
public void Turn(CardinalPoint direction) { compass = direction; /*CardinalPoint[] values = (CardinalPoint[]) Enum.GetValues(typeof(CardinalPoint)); int change = (int)direction; int nextPosition = Array.IndexOf(values, compass) + change; compass = (values.Length == nextPosition) ? values[0] : values[nextPosition];*/ }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (Decoration == null || IsHidden) return; TileDrawing td = DisplayCoordinates.GetFloorPlate(position); if (td == null) return; Decoration.Draw(batch, DecorationPrimary, position); }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (TileSet == null) return; // Upstair or downstair ? int delta = Type == StairType.Up ? 0 : 13; foreach (TileDrawing tmp in DisplayCoordinates.GetStairs(position)) batch.DrawTile(TileSet, tmp.ID + delta, tmp.Location, Color.White, 0.0f, tmp.Effect, 0.0f); }
/// <summary> /// /// </summary> /// <param name="location"></param> /// <param name="side"></param> /// <param name="button"></param> /// <returns></returns> public override bool OnClick(Point location, CardinalPoint side, MouseButtons button) { // No wall side or no decoration if (side != Side || Square.Maze.Decoration == null) return false; // Not in the decoration zone if (!Square.Maze.Decoration.IsPointInside(IsActivated ? ActivatedDecoration : DeactivatedDecoration, location)) return false; // Switch already used and not reusable if ((WasUsed && !Reusable) || !IsEnabled) { GameMessage.AddMessage("It's already unlocked.", GameColors.Red); return true; } // Does an item is required ? if (!string.IsNullOrEmpty(NeededItem)) { // No item in hand or not the good item if (GameScreen.Team.ItemInHand == null || GameScreen.Team.ItemInHand.Name != NeededItem) { GameMessage.AddMessage("You need a key to open this lock"); return true; } // Picklock if (GameScreen.Team.ItemInHand.Name == "PickLock") { // TODO: already unlocked => "It's already unlocked" if (PickLock()) { GameMessage.AddMessage("You pick the lock.", GameColors.Green); } else { GameMessage.AddMessage("You failed to pick the lock", GameColors.Yellow); } return true; } // Consume item if (ConsumeItem) GameScreen.Team.SetItemInHand(null); } Toggle(); return true; }
/// <summary> /// /// </summary> /// <param name="batch"></param> /// <param name="field"></param> /// <param name="position"></param> /// <param name="direction"></param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (Decoration == null || IsHidden) return; TileDrawing td = DisplayCoordinates.GetPit(position); if (td == null) return; if (IsActivated) //batch.FillRectangle(new Rectangle(td.Location, new Size(50, 50)), Color.Red); Decoration.Draw(batch, field.Maze.FloorPitDeco, position); //TODO //if (td != null && !IsHidden) // batch.DrawTile(TileSet, td.ID, td.Location, Color.White, 0.0f, td.Effect, 0.0f); }
/// <summary> /// Rotate the team /// </summary> /// <param name="direction">Initial direction</param> /// <param name="rot">Rotation needed</param> /// <returns>Final direction</returns> static public CardinalPoint Rotate(CardinalPoint direction, CompassRotation rot) { CardinalPoint[][] points = new CardinalPoint[][] { // North new CardinalPoint[] { CardinalPoint.East, CardinalPoint.South, CardinalPoint.West, CardinalPoint.North, }, // South new CardinalPoint[] { CardinalPoint.West, CardinalPoint.North, CardinalPoint.East, CardinalPoint.South, }, // West new CardinalPoint[] { CardinalPoint.North, CardinalPoint.East, CardinalPoint.South, CardinalPoint.West, }, // East new CardinalPoint[] { CardinalPoint.South, CardinalPoint.West, CardinalPoint.North, CardinalPoint.East, }, }; return points[(int)direction][(int)rot]; }
/// <summary> /// Draws all alcoves according to the view point /// </summary> /// <param name="batch">Spritebatch handle</param> /// <param name="field">Field of view handle</param> /// <param name="position">Position in the field of view</param> /// <param name="direction">Looking direction</param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (field.Maze.Decoration == null) return; // For each wall side, draws the decoration foreach (CardinalPoint side in DisplayCoordinates.DrawingWallSides[(int) position]) { Alcove alcove = GetAlcove(Compass.GetDirectionFromView(direction, side)); // Get the decoration Decoration deco = field.Maze.Decoration.GetDecoration(alcove.Decoration); if (deco == null) continue; // Draw the decoration deco.DrawDecoration(batch, field.Maze.Decoration, position, side == CardinalPoint.South); // Hide items if (alcove.HideItems || side != CardinalPoint.South) continue; // Offset the item locations according to the distance Vector2 vect = DisplayCoordinates.GetMonsterScaleFactor(position); Point loc = deco.PrepareLocation(position); loc.Offset((int) (deco.ItemLocation.X * vect.X), (int) (deco.ItemLocation.Y * vect.Y)); // Draw items in the alcove in front of the team foreach (Item item in Square.GetItemsFromSide(direction, side)) { batch.DrawTile(Square.Maze.Dungeon.ItemTileSet, item.GroundTileID, loc, DisplayCoordinates.GetDistantColor(position), 0.0f, DisplayCoordinates.GetItemScaleFactor(position), SpriteEffects.None, 0.0f); } } }
/// <summary> /// A hero used an empty hand on the wall /// </summary> /// <returns>True if the event is processed</returns> public bool OnBash(CardinalPoint side, Item item) { #region Decoration must change on hack Decoration deco = Maze.GetDecoration(Location, side); if (deco != null && deco.OnHackId != -1) { // If forced decoration, then erase all other decorations if (deco.ForceDisplay) { for (int id = 0; id < 4; id++) { if (Decorations[id] != -1) Decorations[id] = deco.OnHackId; } } // change only this decoration else Decorations[(int)side] = deco.OnHackId; return true; } #endregion GameMessage.AddMessage("Square: OnBash()"); return false; }
/// <summary> /// Gets if the wall have decoration /// </summary> /// <param name="from">Facing direction</param> /// <param name="side">Wall side</param> /// <returns>True if a decoration is present<returns> public bool HasDecoration(CardinalPoint from, CardinalPoint side) { return GetDecorationId(from, side) != -1; }
/// <summary> /// Gets the decoration id of a wall side /// </summary> /// <param name="side">Wall side</param> /// <returns>Decoration id or -1 if no decoration</returns> public int GetDecorationId(CardinalPoint side) { // Is there a forced decoration //foreach (CardinalPoint cp in Enum.GetValues(typeof(CardinalPoint))) //{ // Decoration deco = Maze.GetDecoration(Location, cp); // if (deco != null && deco.ForceDisplay) // return 0; //} // The decoration of the desired side return Decorations[(int)side]; }
/// <summary> /// Returns items on the ground at a specific corner /// </summary> /// <param name="from">Facing position</param> /// <param name="position">Ground position</param> /// <returns>List of items</returns> public List<Item> GetItems(CardinalPoint from, SquarePosition position) { CardinalPoint[,] tab = new CardinalPoint[,] { {CardinalPoint.North, CardinalPoint.South, CardinalPoint.West, CardinalPoint.East}, {CardinalPoint.South, CardinalPoint.North, CardinalPoint.East, CardinalPoint.West}, {CardinalPoint.West, CardinalPoint.East, CardinalPoint.South, CardinalPoint.North}, {CardinalPoint.East, CardinalPoint.West, CardinalPoint.North, CardinalPoint.South}, }; return GetItems((SquarePosition)tab[(int)from, (int)position]); }
/// <summary> /// Constructor /// </summary> /// <param name="id">ID of the tile</param> /// <param name="location">Display location on the screen</param> /// <param name="side">Wall side</param> public TileDrawing(int id, Point location, CardinalPoint side) : this(id, location, side, SpriteEffects.None) { }
/// <summary> /// Offset the location /// </summary> /// <param name="direction">Direction of the move</param> /// <param name="count">Number of block to move</param> public void Offset(CardinalPoint direction, int count) { switch (direction) { case CardinalPoint.North: Coordinate.Offset(0, -count); break; case CardinalPoint.South: Coordinate.Offset(0, count); break; case CardinalPoint.West: Coordinate.Offset(-count, 0); break; case CardinalPoint.East: Coordinate.Offset(count, 0); break; } }
/// <summary> /// /// </summary> /// <param name="character"></param> private void HandleMiddleSquareCourse( BoardController boardController) { int row = mRow; int column = mColumn; bool[] squareExitStatus = new bool[4]; bool noExit = true; int randomCardinalPoint = mRandom.Next(0, 4) - 1; CardinalPoint targetDirection = mOriginRoadDirection; CardinalPoint currentDirection = mRoadDirection; // Cardinal Point{ N, W, S, E } for (int cardinalPoint = 0; cardinalPoint < 4; cardinalPoint++) { squareExitStatus[cardinalPoint] = boardController.HasSquareExit(row, column, (CardinalPoint)Enum.ToObject(typeof(CardinalPoint), cardinalPoint)); } if (squareExitStatus[(int)targetDirection] && ((int)currentDirection != ((int)targetDirection + 2) % 4)) { mRoadDirection = targetDirection; noExit = false; } else if (squareExitStatus[(int)mRoadDirection] && ((int)currentDirection != ((int)targetDirection + 2) % 4)) { noExit = false; } else { for (int cardinalPoint = 0; cardinalPoint < 4; cardinalPoint++) { randomCardinalPoint += 1; if (randomCardinalPoint == 4) { randomCardinalPoint = 0; } if (randomCardinalPoint != (((int)(currentDirection) + 2) % 4) && (randomCardinalPoint != ((int)targetDirection + 2) % 4)) { if (squareExitStatus[randomCardinalPoint]) { mRoadDirection = (CardinalPoint)Enum.ToObject(typeof(CardinalPoint), randomCardinalPoint); noExit = false; cardinalPoint = 3; } } } } if (noExit) { if (squareExitStatus[(((int)targetDirection + 2) % 4)]) { mRoadDirection = (CardinalPoint)Enum.ToObject(typeof(CardinalPoint), (((int)(targetDirection) + 2) % 4)); } else { mRoadDirection = (CardinalPoint)Enum.ToObject(typeof(CardinalPoint), (((int)(currentDirection) + 2) % 4)); } } }
/// <summary> /// Gets a list of items from a side /// </summary> /// <param name="side">Wall side</param> /// <returns>List of items</returns> public List<Item> GetItemsFromSide(CardinalPoint side) { return Items[(int)side]; }
/// <summary> /// Gets a list of items /// </summary> /// <param name="from">View point</param> /// <param name="side">Wall side</param> /// <returns>List of items</returns> public List<Item> GetItemsFromSide(CardinalPoint from, CardinalPoint side) { return GetItemsFromSide(Compass.GetDirectionFromView(from, side)); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="direction"></param> private void DirectionBox_DirectionChanged(object sender, CardinalPoint direction) { ChangeSide(direction); }
/// <summary> /// /// </summary> /// <param name="side"></param> void ChangeSide(CardinalPoint side) { Face = side; Alcove = Actor.GetAlcove(side); if (Alcove.Decoration == -1) { ItemAddedBox.Enabled = false; ItemRemovedBox.Enabled = false; } else { ItemAddedBox.Enabled = true; ItemRemovedBox.Enabled = true; ItemAddedBox.Scripts = Alcove.OnAddedItem; ItemRemovedBox.Scripts = Alcove.OnRemovedItem; ItemAddedBox.Dungeon = Maze.Dungeon; ItemRemovedBox.Dungeon = Maze.Dungeon; } UpdateUI(); RenderScene(); }
/// <summary> /// Collects and removes an item from a side /// </summary> /// <param name="side">Wall side</param> /// <returns>Item handle or null</returns> public Item CollectItemFromSide(CardinalPoint side) { return CollectItem((SquarePosition)side); }
/// <summary> /// Returns all items depending the view point /// </summary> /// <param name="location">Facing direction</param> /// <returns>Returns an array of items /// Position 0 : Up left /// Position 1 : Up Right /// Position 2 : Bottom left /// Position 3 : Bottom right</returns> public List<Item>[] GetItems(CardinalPoint location) { // List of items List<Item>[] items = new List<Item>[4]; switch (location) { case CardinalPoint.North: { items[0] = Items[0]; items[1] = Items[1]; items[2] = Items[2]; items[3] = Items[3]; } break; case CardinalPoint.East: { items[0] = Items[1]; items[1] = Items[3]; items[2] = Items[0]; items[3] = Items[2]; } break; case CardinalPoint.South: { items[0] = Items[3]; items[1] = Items[2]; items[2] = Items[1]; items[3] = Items[0]; } break; case CardinalPoint.West: { items[0] = Items[2]; items[1] = Items[0]; items[2] = Items[3]; items[3] = Items[1]; } break; } return items; }
/// <summary> /// Draw the door /// </summary> /// <param name="batch">Spritebatch to use</param> /// <param name="field">View field</param> /// <param name="position">Position in the view filed</param> /// <param name="view">Looking direction of the team</param> public override void Draw(SpriteBatch batch, ViewField field, ViewFieldPosition position, CardinalPoint direction) { if (!IsVisible) return; TileDrawing td = DisplayCoordinates.GetTeleporter(position); if (td == null) return; Anim.Draw(batch, td.Location, 0.0f, SpriteEffects.None, DisplayCoordinates.GetDistantColor(position), DisplayCoordinates.GetMonsterScaleFactor(position)); }
public FirstCharacterController(int row, int column, CardinalPoint roadDirection, float squarePosition, int boardSize, bool reachHalfSquare) { mRow = row; mBoardSize = boardSize; mOriginRow = row; mOriginColumn = column; mOriginPosition = squarePosition; mOriginRoadDirection = roadDirection; mReachHalfSquare = reachHalfSquare; mRow = mOriginRow; mColumn = mOriginColumn; mSquareLocation = mOriginPosition; mRoadDirection = mOriginRoadDirection; }
/// <summary> /// /// </summary> /// <param name="roadCharacter"></param> private void HandleEndSquareCourse( BoardController boardController) { int nextRow = mRow; int nextColumn = mColumn; CardinalPoint roadDirection = mRoadDirection; CardinalPoint oppositeCardinalPoint = (CardinalPoint)Enum.ToObject(typeof(CardinalPoint), (((int)(mRoadDirection) + 2) % 4)); CardinalPoint targetDirection = mOriginRoadDirection; switch (roadDirection) { case CardinalPoint.N: nextRow += 1; break; case CardinalPoint.S: nextRow -= 1; break; case CardinalPoint.E: nextColumn += 1; break; case CardinalPoint.W: nextColumn -= 1; break; } if ((nextRow < 0) || (nextRow > (boardController.Size - 1)) || (nextColumn > (boardController.Size - 1)) || nextColumn < 0) { if ((nextRow < 0 && targetDirection == CardinalPoint.S) || (nextRow > (boardController.Size - 1) && targetDirection == CardinalPoint.N) || (nextColumn > (boardController.Size - 1) && targetDirection == CardinalPoint.E) || nextColumn < 0 && targetDirection == CardinalPoint.W) { mSpeed = 0f; mArrivedAtDestination = true; } else { mRoadDirection = oppositeCardinalPoint; } } else { mReachHalfSquare = false; mSquareLocation = 0; if (!boardController.HasSquareExit(nextRow, nextColumn, oppositeCardinalPoint)) { mRoadDirection = oppositeCardinalPoint; } else { mRow = nextRow; mColumn = nextColumn; } } }
private string getCardinalPoint(CardinalPoint point) { switch (point) { case CardinalPoint.BottomLeft: return "1 (bottom left)"; case CardinalPoint.BottomCenter: return "2 (bottom center)"; case CardinalPoint.BottomRight: return "3 (bottom right)"; case CardinalPoint.MiddleLeft: return "4 (middle left)"; case CardinalPoint.MiddleCenter: return "5 (middle center)"; case CardinalPoint.MiddleRight: return "6 (middle right)"; case CardinalPoint.TopLeft: return "7 (top left)"; case CardinalPoint.TopCenter: return "8 (top center)"; case CardinalPoint.TopRight: return "9 (top right)"; case CardinalPoint.Centroid: return "10 (centroid)"; case CardinalPoint.ShearCenter: return "11 (shear center)"; default: return "10 (centroid)"; } }
/// <summary> /// Drops an item from a side /// </summary> /// <param name="side">Wall side</param> /// <returns>True if the item can go in the alcove, or false</returns> public bool DropItemFromSide(CardinalPoint side, Item item) { if (item == null) // || !HasAlcove(side)) return false; Items[(int)side].Add(item); return true; }
/// <summary> /// Returns if a side has a decoration /// </summary> /// <param name="side">Wall side</param> /// <returns>True if a decoration is present<returns> public bool HasDecoration(CardinalPoint side) { return Decorations[(int)side] != -1; }
/// <summary> /// Gets the decoration id of a wall side /// </summary> /// <param name="from">Facing direction</param> /// <param name="side">Wall side</param> /// <returns>Decoration id or -1 if no decoration</returns> public int GetDecorationId(CardinalPoint from, CardinalPoint side) { // Get desired side return Decorations[(int)Compass.GetDirectionFromView(from, side)]; }