public void OnTileExit(MovingUnit unit) { if (onTileExit != null) { onTileExit(unit); } }
void Update() { foreach (Player p in players) { p.ownedCells = hexGrid.GetAllCellsOfColor(p.color); } //Animate moving units if (unitsToMove.Count > 0) { for (int i = 0; i < unitsToMove.Count; i++) { MovingUnit m = unitsToMove [i]; if (m.rect == null) { unitsToMove.Remove(m); continue; } m.rect.anchoredPosition3D = Vector3.MoveTowards(m.rect.anchoredPosition3D, m.toPos, Vector3.Distance(m.fromPos, m.toPos) * 1 / unitMoveSpeed * Time.deltaTime); } } goldText.text = "Gold: " + ourPlayer.gold.ToString(); }
public void OnTileEnter(MovingUnit unit) { if (onTileEnter != null) { onTileEnter(unit); } }
public void HurtUnit(MovingUnit unit) { if (unit.GetComponent <Player> ()) { CardsManager.Instance.AddCurse(); } unit.GetHurt(); print(unit.gameObject.name + " was hurt!"); }
void CatchPickup(MovingUnit unit) { if (unit.GetComponent <Player> () != null) { if (gameObject) { currentTile.onTileEnter -= CatchPickup; MapManager.Instance.ArrowToEscape(); Destroy(gameObject); } } }
public void NotifyDeath(MovingUnit go) { if (go.faction == Faction.PLAYER) { alivePlayerUnitsLock.AcquireWriterLock(500); alivePlayerUnits.Remove(go.GetComponent <Unit>()); alivePlayerUnitsLock.ReleaseWriterLock(); } else { aliveEnemyUnitsLock.AcquireWriterLock(500); aliveEnemyUnits.Remove(go.GetComponent <Unit>()); aliveEnemyUnitsLock.ReleaseWriterLock(); } battleUIController.RefreshArmyBarsUI(alivePlayerUnits.Count, allPlayerUnitsCount, aliveEnemyUnits.Count, allEnemyUnitsCount); CheckWinLoseConditions(); }
private void ScanUnits() { GameObject[] units = GameObject.FindGameObjectsWithTag("Unit"); foreach (var goUnit in units) { MovingUnit u = goUnit.GetComponent <MovingUnit>(); if (u.faction == Faction.PLAYER) { alivePlayerUnits.Add(u); } else { aliveEnemyUnits.Add(u); } } allEnemyUnitsCount = aliveEnemyUnits.Count; allPlayerUnitsCount = alivePlayerUnits.Count; }
public override void InitLevel() { _mouseCapture = new MouseCapture(_playGrid); _xMaxBounds = (int)_playGrid.ActualWidth - 60; _xMinBounds = 10; _yMaxBounds = (int)_playGrid.ActualHeight - 60; _yMinBounds = 10; _unitsHit = 0; _nonMovingUnits = new List <Unit>(); _movingUnits = new List <MovingUnit>(); // set trees for (int t = 0; t < this.NonMovingUnitAmount; t++) { Application.Current.Dispatcher.Invoke(() => { // set location // random based on x and y bounds var xPos = (double)_random.Next(_xMinBounds, _xMaxBounds); var yPos = (double)_random.Next(_yMinBounds, _yMaxBounds); // Set tree on screen Unit unit = UnitFactory.CreateUnit(UnitEnum.Tree, xPos, yPos); _nonMovingUnits.Add(unit); }); } // random amount MovingUnits int startAmountUnits = _random.Next(5); for (int x = 0; x < startAmountUnits; x++) { Application.Current.Dispatcher.Invoke(() => { MovingUnit unit = null; bool collides = true; while (collides) { // set location var xPos = _random.Next(_xMinBounds, _xMaxBounds); var yPos = _random.Next(_yMinBounds, _yMaxBounds); var unitType = (UnitEnum)_random.Next(2, 4); unit = (MovingUnit)UnitFactory.CreateUnit(unitType, xPos, yPos); if ( !_nonMovingUnits.Any( unit1 => xPos >= unit1.LeftPosition && xPos <= (unit1.LeftPosition + 50) && yPos >= unit1.TopPosition && yPos <= (unit1.TopPosition + 50))) { collides = false; } } unit.SetSteps(this.MinSpeed, this.MaxSpeed); _movingUnits.Add(unit); }); } }
public void UpdateUnits() { Dictionary <double, double> clickedLocations = MouseCapture.getClicks(); foreach (MovingUnit unit in _movingUnits) { foreach (KeyValuePair <double, double> coords in clickedLocations) { unit.SetIsShot(coords); } unit.IsOutOfBounds(_yMaxBounds, _xMaxBounds); bool wasCollide = false; unit.MoveX(); foreach (Unit nonMovingUnit in _nonMovingUnits) { wasCollide = unit.CheckCollisionX(nonMovingUnit); } unit.MoveY(); if (!wasCollide) { foreach (Unit nonMovingUnit in _nonMovingUnits) { unit.CheckCollisionY(nonMovingUnit); } } } MovingUnit newMovingUnit = null; // Add MovingUnit int randomNum = _random.Next(35); if (randomNum % 2 == 0 && _movingUnits.Count < this.MovingUnitAmount) { bool collides = true; while (collides) { // set location var xPos = _random.Next(_xMinBounds, _xMaxBounds); var yPos = _random.Next(_yMinBounds, _yMaxBounds); var unitType = (UnitEnum)_random.Next(2, 4); newMovingUnit = (MovingUnit)UnitFactory.CreateUnit(unitType, xPos, yPos); if ( !_nonMovingUnits.Any( unit1 => xPos >= unit1.LeftPosition && xPos <= (unit1.LeftPosition + 50) && yPos >= unit1.TopPosition && yPos <= (unit1.TopPosition + 50))) { collides = false; } } newMovingUnit.SetSteps(this.MinSpeed, this.MaxSpeed); _movingUnits.Add(newMovingUnit); } }
public void PushBack(MovingUnit unit) { unit.PushBack(1); }
protected override void OnBeforeForeignAttack(MovingUnit attacker) { }
protected override void OnForeignMove(MovingUnit unit) { }