/// <summary> /// Calculates the estimated cost of moving to goal from this node, ignoring obstacles, as hScore /// </summary> /// <param name="goal">Goal</param> /// <param name="hex">If hex</param> public void calculateH(Point goal, bool hex) { if (hex) { hScore = HandyMethods.DistanceHex(pos, goal); } else { hScore = (int)Math.Sqrt(Math.Abs(goal.x - pos.x) + Math.Abs(goal.y - pos.y)); } }
void Start() { gm = GameObject.Find("GameManager").GetComponent <GameManager>(); width = gm.WIDTH; height = gm.HEIGHT / 2 / 2; cam = GetComponent <Camera>(); cameraHeight = (2f * cam.orthographicSize); cameraWidth = cameraHeight * cam.aspect; cameraHeight /= 2; cameraWidth /= 2; // At start, center camera at player1's first hero centerCamera(HandyMethods.getGraphicPosForIso(gm.activeHero.Position.ToVector2())); }
// ------------ Methods to create transitions between environment and environment ------------\\ /// <summary> /// Creates the transitions between water and grass. /// TODO: Make this work. /// </summary> private void CreateTransitions() { int[,] tempMap = HandyMethods.Copy2DArray(map); for (int y = 1; y < height - 1; y++) { for (int x = 1; x < width - 1; x++) { int direction = FindDirection(x, y); if (direction >= 0) { tempMap[x, y] = direction; } else { tempMap[x, y] = map[x, y]; } } } map = tempMap; }
/// <summary> /// Executes the movement logically. /// </summary> public override void execute() { // Preparing movement: MovementManager movement = new MovementManager(gm.Reactions, gm.CanWalk, gm.AStar, gm); movement.PrepareMovement(to, hero); Point step = null; // Actually moving: while (movement.HasNextStep()) { step = movement.NextStep(); } // Updating the graphics accordingly: GameObject graphics = gm.heroLayer[movement.StartPosition.x, movement.StartPosition.y]; gm.heroLayer[movement.StartPosition.x, movement.StartPosition.y] = null; gm.heroLayer[step.x, step.y] = graphics; graphics.transform.position = HandyMethods.getGraphicPosForIso(step.ToVector2()); }
/// <summary> /// Method for attacking without moving /// </summary> /// <param name="attackingUnitPos">Position of attacking unit</param> /// <param name="defendingUnitPos">Position of defending unit</param> public void attackWithoutMoving(Point attackingUnitPos, Point defendingUnitPos, bool ranged) { int distance = HandyMethods.DistanceHex(attackingUnitPos, defendingUnitPos); UnitAndAmount attackingUnits = unitsPos[attackingUnitPos.x, attackingUnitPos.y]; UnitAndAmount defendingUnits = unitsPos[defendingUnitPos.x, defendingUnitPos.y]; attackingUnits.dealDamage(defendingUnits, ranged, distance); if (defendingUnits.Unit.HaveNotRetaliated && defendingUnits.Amount > 0 && !ranged) { defendingUnits.dealDamage(attackingUnits, ranged, distance); defendingUnits.Unit.HaveNotRetaliated = false; } if (attackingUnits.Amount < 0) { attackingUnits.Amount = 0; } if (defendingUnits.Amount < 0) { defendingUnits.Amount = 0; } }
/// <summary> /// Method finds wich enemy unit to attack and then calls the checkPos method /// </summary> /// <param name="activeUnit">The unit whose turn it is</param> public void act(UnitGameObject activeUnit) { x = activeUnit.LogicalPos.x; y = activeUnit.LogicalPos.y; UnitGameObject[] possibleTargets = new UnitGameObject[UnitTree.TREESIZE + 1]; int next = 0; //Finds enemy units for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (field[i, j].GetComponent <GroundGameObject>().IsOccupied&& unitsOnField[i, j] != null && unitsOnField[i, j].GetComponent <UnitGameObject>().AttackingSide) { possibleTargets[next++] = unitsOnField[i, j].GetComponent <UnitGameObject>(); } } } //Finds closest enemy unit UnitGameObject target = possibleTargets[0]; int distance = HandyMethods.DistanceHex(activeUnit.LogicalPos, target.LogicalPos); for (int i = 1; i < possibleTargets.Length; i++) { if (possibleTargets[i] == null) { break; } int tmpDistance = HandyMethods.DistanceHex(activeUnit.LogicalPos, possibleTargets[i].LogicalPos); if (tmpDistance < distance) { target = possibleTargets[i]; distance = tmpDistance; } } checkPos(target.LogicalPos.x, target.LogicalPos.y); }
static void Main(string[] args) { List <int> numbers = new List <int>(); HandyMethods list = new HandyMethods(); }