public void PlayerWinAnimation() { if (SelectedTile != null) { Preview.Show(false); SelectedTile.Select(false); SelectedTile = null; } grabPoint = new Vector2(1000, 1000); winType.Run(timeInfo, collectedStars, RespawnManager.Stars.Length, ActionSelected); cts = new CancellationTokenSource(); int current_bi = SceneHelpers.GetCurrentLevelBuildIndex(); int current_bi_world = SceneHelpers.GetWorldFromBuildIndex(current_bi); int next_bi = SceneHelpers.GetNextLevelBuildIndex(); int next_bi_world = SceneHelpers.GetWorldFromBuildIndex(next_bi); if (current_bi_world > 0 && current_bi_world < next_bi_world) { next_bi = SceneHelpers.WorldCompleteBuildIndex; } // TODO: this if/else can be removed once we've guaranteed that every world has 10 levels // and replaced with just the statement inside the IF if (next_bi < SceneHelpers.SceneCount) { GameManager.Instance.AsyncLoadScene(next_bi, StartCoroutine(WaitActionSelected()), cts, null, false); } else { GameManager.Instance.SaveData.LastPlayedWorld = 0; } }
private void ManageClick() { // The second part of the condition prevents from interacting with the tilemap if we click on UI if (Input.GetMouseButtonDown(0) && EventSystem.current.currentSelectedGameObject == null && !BlockingUI.IsBlocked) { BaseTileData tileClicked = GetTileAtMousePos(); if (tileClicked != null) { if (BuildingManager.Instance.IsInBuildMode) { BuildingManager.Instance.BuildCurrentStructure(HoveredTile); } else { tileClicked.terrainTile.DebugOnClick(); } if (SelectedTile != null) { SelectedTile.SetIsSelected(false); } SelectedTile = tileClicked; SelectedTile.SetIsSelected(true); } else { if (SelectedTile != null) { SelectedTile.SetIsSelected(false); } SelectedTile = null; } OnPlayerClick?.Invoke(); } }
private void ShowEditInfo() { EditInfoViews.Clear(); var editInfos = SelectedTile.GetEditInfo(); foreach (var editInfo in editInfos) { var label = new Label() { Content = editInfo.Label, FontSize = 20, VerticalAlignment = VerticalAlignment.Center }; label.SetResourceReference(Label.StyleProperty, "LabelStyle"); editInfo.Control.Margin = new Thickness(5); var grid = new Grid(); var width = new GridLength(1, GridUnitType.Star); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = width }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = width }); Grid.SetColumn(editInfo.Control, 1); grid.Children.Add(label); grid.Children.Add(editInfo.Control); EditInfoViews.Add(grid); } }
private void OnTileClicked(TileController tile) { if (tile.PieceNr == turn && tile.EmptyMoveableTiles.Any()) { SelectedTile = tile; } else if (SelectedTile != null && !tile.HasPiece && (tile.CanJump(SelectedTile) || tile.IsNeighbour(SelectedTile))) { tile.PieceNr = SelectedTile.PieceNr; foreach (var t in tiles) { if (t.PieceNr != tile.PieceNr && t.HasPiece && t.IsNeighbour(tile)) { t.PieceNr = SelectedTile.PieceNr; } } if (!tile.IsNeighbour(SelectedTile)) { SelectedTile.ClearPiece(); } SelectedTile = null; turn = (turn + 1) % players; DisplayScores(); } }
private void SelectTile(TileViewModel tile) { if (tile == SelectedTile) { tile = null; } SelectedTile?.Deselect(); SelectedTile = tile; SelectedTile?.Select(); MoveDownCommand.OnCanExecuteChanged(); MoveLeftCommand.OnCanExecuteChanged(); MoveUpCommand.OnCanExecuteChanged(); MoveRightCommand.OnCanExecuteChanged(); DeleteTileCommand.OnCanExecuteChanged(); OnPropertyChanged("HintVisibility"); if (SelectedTile != null) { ShowEditInfo(); } else { HideEditInfo(); } }
public override void Undo() { if (executed) { TargetTile.DetachPiece(); SelectedTile.AttachPiece(Piece, PieceHasMoved); executed = false; } }
public override void Execute() { if (!executed) { SelectedTile.DetachPiece(); TargetTile.AttachPiece(Piece, true); executed = true; } }
// Templates are done as (x1,y1), (x2,y2) style with the bounding box being defined by diagonal corners. private static bool CheckTemplateValid(SelectedTile selected, NativeArray <Tile> tileMap, float2x2 template, int tilesPerWidth) { int x1 = (int)template.c0.x; int y1 = (int)template.c0.y; int x2 = (int)template.c1.x; int y2 = (int)template.c1.y; bool evenX = (x2 - x1 + 1) % 2 == 0 ? true : false; bool evenY = (y2 - y1 + 1) % 2 == 0 ? true : false; int tileAnchorX; int tileAnchorY; if (evenX) { tileAnchorX = ((x2 - x1 + 1) / 2) - 1; } else { tileAnchorX = ((x2 - x1 + 1) / 2); } if (evenY) { tileAnchorY = ((y2 - y1 + 1) / 2) - 1; } else { tileAnchorY = ((y2 - y1 + 1) / 2); } // get the start index (0,0) position removing the offset of the tile anchor int startIndex = selected.tileID - (tileAnchorY * tilesPerWidth) - tileAnchorX; for (int x = 0; x < (x2 - x1 + 1); x++) { for (int y = 0; y < (y2 - y1 + 1); y++) { int currentIndex = startIndex + (y * tilesPerWidth) + x; if (currentIndex > 0) { Tile testTile = tileMap[currentIndex]; if (testTile.isValid == 0) { return(false); } } else { return(false); } } } return(true); }
private static void SetTemplate(SelectedTile selected, NativeArray <Tile> tileMap, float2x2 template, int tilesPerWidth, GameState state) { int x1 = (int)template.c0.x; int y1 = (int)template.c0.y; int x2 = (int)template.c1.x; int y2 = (int)template.c1.y; bool evenX = (x2 - x1 + 1) % 2 == 0 ? true : false; bool evenY = (y2 - y1 + 1) % 2 == 0 ? true : false; int tileAnchorX; int tileAnchorY; if (evenX) { tileAnchorX = ((x2 - x1 + 1) / 2) - 1; } else { tileAnchorX = ((x2 - x1 + 1) / 2); } if (evenY) { tileAnchorY = ((y2 - y1 + 1) / 2) - 1; } else { tileAnchorY = ((y2 - y1 + 1) / 2); } // get the start index (0,0) position removing the offset of the tile anchor int startIndex = selected.tileID - (tileAnchorY * tilesPerWidth) - tileAnchorX; int buildingID = state.buildingID_Incrementer; for (int x = 0; x < (x2 - x1 + 1); x++) { for (int y = 0; y < (y2 - y1 + 1); y++) { int currentIndex = startIndex + (y * tilesPerWidth) + x; if (currentIndex > 0) { Tile tile = tileMap[currentIndex]; tile.isValid = 0; tile.hasRoad = false; tile.hasBuilding = true; tile.buildingID = buildingID; tileMap[currentIndex] = tile; } } } }
public override void Execute() { if (!executed) { SelectedTile.DetachPiece(); TargetTile.AttachPiece(Piece, true); if (Piece is IEnPassantable) { IEnPassantable enPassantablePiece = Piece as IEnPassantable; enPassantablePiece.CurrentlyEnPassantable = true; } executed = true; } }
public override void Undo() { if (executed) { TargetTile.DetachPiece(); SelectedTile.AttachPiece(Piece, PieceHasMoved); if (Piece is IEnPassantable) { IEnPassantable enPassantablePiece = Piece as IEnPassantable; enPassantablePiece.CurrentlyEnPassantable = false; } executed = false; } }
private static float3 CalculateBuildingOffset(SelectedTile selected, float2x2 template, int tileWidth) { int x1 = (int)template.c0.x; int y1 = (int)template.c0.y; int x2 = (int)template.c1.x; int y2 = (int)template.c1.y; float3 offset; offset.x = (x2 - x1 + 1) % 2 == 0 ? (float)tileWidth / 2.0f : 0; offset.z = (y2 - y1 + 1) % 2 == 0 ? (float)tileWidth / 2.0f : 0; offset.y = 0; return(offset); }
public MapView() { var road = new Random(Guid.NewGuid().GetHashCode()).Next(0, 13); var map = new Map(Enumerable.Range(0, 14).SelectMany(x => Enumerable.Range(0, 26) .Select(y => x == road ? new Grass(new TileLocation(x, y), new Road()) : new Grass(new TileLocation(x, y))))); new CurrentMap().SetMap(map); var moneyAccount = new MoneyAccount(); objs.Add(map); var selectedTile = new SelectedTile(); objs.Add(selectedTile); var buildingSelection = new BuildingSelectionOverlay(new Vector2(10, 10)); objs.Add(buildingSelection); objs.Add(new BuildingConstruction(moneyAccount, selectedTile, buildingSelection)); objs.Add(new MoneyAccountOverlay(moneyAccount, new Vector2(100, 10))); }
private void doActionAction() { if (MemUnit != null && (MemUnit.getUnit().getPlayer() == game.turn.currentPlayer)) { UnitAPI currunit = memUnit.getUnit(); if (SelectedTile.getEnemy() != null) { if (currunit.canAttack(SelectedTile.getEnemy())) { UnitAPI loser = currunit.attack(SelectedTile.getEnemy()); MessageBox.Show(loser.getPlayer().name + " loses the battle!"); if (loser.lifePoints <= 0) { MessageBox.Show(loser.getPlayer().name + " is dead!"); } } else { MessageBox.Show("Attack action not possible"); } } else { if (currunit.canMove(SelectedTile.X, SelectedTile.Y)) { currunit.move(SelectedTile.X, SelectedTile.Y); } else { MessageBox.Show("Move action not possible"); } } //Global Refresh memUnit.Refresh(); updateTiles(); this.Refresh(); } else { MessageBox.Show("No unit selected"); } this.isFinished(); }
private void DoDowngradeCommand() { if (SelectedTile != null && SelectedTile.CanBeDowngraded()) { SelectedTile.Downgrade(); } else if (SelectedTile == null) { MessageBox.Show("Select a street you want to downgrade please"); } else if (SelectedTile.OnMortage) { MessageBox.Show("This building cannot be downgraded any further!"); } else if (!SelectedTile.CanBeDowngraded()) { MessageBox.Show("You must first have all the streets at the same number of houses before you can downgrade this one further!"); } }
private void DoUpgradeCommand() { if (SelectedTile != null && (SelectedTile != null && SelectedTile.City.OwnsAllProperties(Game.CurrentPlayer) && SelectedTile.CanBeUpgraded() || SelectedTile.OnMortage)) { SelectedTile.Upgrade(); } else if (SelectedTile == null) { MessageBox.Show("Select an upgradable item in the list."); } else if (SelectedTile != null && !SelectedTile.City.OwnsAllProperties(Game.CurrentPlayer)) { MessageBox.Show("You must first have all the streets before you can start building houses"); } else if (!SelectedTile.CanBeUpgraded()) { MessageBox.Show("You must first have all the streets at the same number of houses before you can upgrade this one further!"); } }
// called every frame from context manager public override void HandleInput(InputPackage p) { if (!Won) { if (p.Touchdown) { if (p.TouchdownChange) { // clicked Tile t = Physics2D.OverlapCircleAll(p.MousePositionWorldSpace, 3f, tileMask) // roughly 1/3 of a tile of tap tolerance .Select(g => g.GetComponent <Tile>()) .Where(g => g != null && g.Movable) .OrderBy(g => Vector2.Distance(p.MousePositionWorldSpace, g.transform.position)) .FirstOrDefault(); if (t != null) { SelectedTile = t; grabPoint = p.MousePositionWorldSpace; SelectedTile.Select(true); MMVibrationManager.Haptic(HapticTypes.Selection); grabMovingVelocityAverage = Vector2.zero; } #if UNITY_EDITOR if (ShowFingerprint) { Fingerprint = GetComponentInChildren <Fingerprint>(true); Fingerprint.gameObject.SetActive(true); Fingerprint.transform.position = p.MousePositionWorldSpace; } #endif } else if (SelectedTile != null) { grabMovingVelocityAverage = p.MousePositionWorldSpaceDelta * 0.1f + grabMovingVelocityAverage * 0.9f; float scale = SelectedTile.transform.lossyScale.x; Vector2 moveAmount = (p.MousePositionWorldSpace - grabPoint) / scale; Tilespace tileBeforeMove = SelectedTile.Space; bool changedTilespaces = SelectedTile.TryMoveToPosition(SelectedTile.GetPositionFromInput(moveAmount), p.MousePositionWorldSpaceDelta); if (changedTilespaces) { if (SelectedTile.Space.Sticky) { SelectedTile = null; } else { Vector3 move = ((Vector2)SelectedTile.transform.position - SelectedTile.PositionWhenSelected); grabPoint += move; if (Mathf.Abs(move.y) > Mathf.Abs(move.x) && Mathf.Abs(moveAmount.x) < 2 * Tile.BaseThreshold) { grabPoint.x = p.MousePositionWorldSpace.x; } else if (Mathf.Abs(moveAmount.y) < 2 * Tile.BaseThreshold) { grabPoint.y = p.MousePositionWorldSpace.y; } SelectedTile.Select(true); } } if (!TimerRunning && !Won && !SelectedTile.Centered) { StartTimer(); } } Vector3 position = p.MousePositionWorldSpace + Player.Direction * -8.5f; if (Vector2.Distance(Player.transform.position, p.MousePositionWorldSpace) < 5) { Preview.Show(true, position); Preview.WatchedPosition = Player.transform.position; } else { Preview.Show(false, position); } #if UNITY_EDITOR if (Fingerprint != null) { Fingerprint.transform.position = p.MousePositionWorldSpace; } #endif } else if (!p.Touchdown && p.TouchdownChange) { Preview.Show(false); if (SelectedTile != null) { Vector2 avgOnRelease = grabMovingVelocityAverage; if (!SelectedTile.Centered) { avgOnRelease *= SelectedTile.NormalizedPosition; } //Debug.Log(avgOnRelease); SelectedTile.SetResidualVelocity(avgOnRelease); SelectedTile.Select(false); SelectedTile = null; } #if UNITY_EDITOR if (Fingerprint != null) { Fingerprint.gameObject.SetActive(false); } #endif } } }
public void AttackUnit() { CurrentGameState = GameState.SELECTED_UNIT_IS_ATTACKING; SelectedUnit.unitCombat.FinishedAttacking += SelectedUnitFinishedAttacking; SelectedUnit.Attack(SelectedTile.unitOnTile, !SelectedTile.IsAdjacentTile(SelectedUnit.currentTile)); }
public BuildingConstruction(MoneyAccount moneyAccount, SelectedTile selectedTile, BuildingSelectionOverlay buildingSelection) { this.moneyAccount = moneyAccount; this.selectedTile = selectedTile; this.buildingSelection = buildingSelection; }