public void move(HexPosition[] path) { if (path.Length < 2) { state = State.ATTACK; return; } HexPosition destination = path [path.Length - 1]; this.path = new Vector3[path.Length]; for (int i = 0; i < path.Length; ++i) { this.path [i] = path [i].getPosition(); } state = State.ATTACK; if (destination.containsKey("Unit")) { print("ERROR: Space occupied."); moveComplete(); return; } position.remove("Unit"); destination.add("Unit", this); //transform.position = desitination.getPosition(); t = 0; n = 0; moving = true; position = destination; }
private void move() { if (mouse.Equals(selection)) { unselect(); } else if (!mouse.containsKey("Unit")) { if (path.Length > 0) { waiting = true; HexPosition.clearSelection(); selection = mouse; selection.select("Selection"); CmdMoveUnit(HexPosition.pathToIntString(path)); } } else { object enemy = null; if (mouse.tryGetValue("Unit", out enemy)) { if (isAttackable(selection.getUnit(), (Unit)enemy)) { actuallyAttack(); } } } }
private void move() { if (mouse.Equals(selection)) { unselect(); } else if (!mouse.containsKey("Unit")) { if (path.Length > 0) { Unit myUnit = selection.getUnit(); myUnit.move(path); HexPosition.clearSelection(); selection = mouse; selection.select("Selection"); if (selectAttackable(myUnit)) { phase = Phase.ATTACK; } else { myUnit.skipAttack(); unselect(); } } } }
IEnumerator PerformManeuvers(float delayPerAction) { for (int i = 0; i < allUnits.Count; i++) { // do each plane's maneuver var unit = allUnits[i]; var m = allCommands[unit]; if (unit.hitPoints > 0) { Debug.Log("Executing: " + m.id.ToString() + " on " + unit.callsign); //m.Execute(ref unit); unit.PerformManeuver(m); unit.Move(); unit.StallCheck(); unit.CrashCheck(); //ManeuverManager.CrashCheck(ref unit); //m.aircraft.Move(); unit.TriggerAnimation(); // if plane is in range of another plane... attack! bool attacked = false; for (int range = 1; range <= 2; range++) { HexPosition attackPoint = unit.LookAhead(range); if (attackPoint.containsKey(GameBoard.KEY_UNIT_AIR)) { UnitAircraft target = (UnitAircraft)attackPoint.getValue(GameBoard.KEY_UNIT_AIR); Debug.Log(unit.callsign + " fires on " + target.callsign); attacked = true; unit.Attack(target); target.TriggerAnimation(); } } if (attacked) { unit.AttackAnimation(); } } yield return(new WaitForSeconds(delayPerAction)); } if (phase == GamePhase.MANEUVER) { AdvancePhase(); } }
/// <summary> /// return true if pos x is reachable /// </summary> /// <returns><c>true</c>, if movable was ised, <c>false</c> otherwise.</returns> /// <param name="unit">Unit.</param> /// <param name="coordinates">Coordinates.</param> private bool isMovable(Unit unit, HexPosition coordinates) { if (unit.Coordinates.dist(coordinates) <= unit.SPEED) { if (AStar.search(unit.Coordinates, coordinates, unit.SPEED).Length != 0) { if (!coordinates.containsKey("Obstacle")) { return(true); } } } return(false); }
/// <summary> /// move the plane ahead /// </summary> public void Move() { HexPosition newPos = ProjectAhead(); // crash? if (newPos.containsKey(GameBoard.KEY_UNIT_AIR)) { UnitAircraft other = (UnitAircraft)newPos.getValue(GameBoard.KEY_UNIT_AIR); if (other != this) { other.Die("Mid-air collision with " + callsign); UpdatePositionTo(newPos); Die("Mid-air collision with " + other.callsign); } } else { UpdatePositionTo(newPos); } }
private void move() { if (mouse.Equals(selection)) { unselect(); } else if (!mouse.containsKey("Unit")) { if (path.Length > 0) { Unit myUnit = ((Unit)selection.getValue("Unit")); myUnit.move(path); HexPosition.clearSelection(); selection = mouse; selection.select("Selection"); if (selectAttackable(myUnit)) { turn = Turn.ATTACK; } else { myUnit.Status = Unit.State.WAIT; unselect(); endTurn(); } } } else { object enemy = null; if (mouse.tryGetValue("Unit", out enemy)) { Unit myUnit = ((Unit)selection.getValue("Unit")); if (isAttackable(myUnit, (Unit)enemy)) { actuallyAttack(); } } } }
private void move() { if (mouse.Equals(selection)) { unselect(); } else if (!mouse.containsKey("Unit")) { if (path.Length > 0) { Unit myUnit = selection.getUnit(); myUnit.move(path); HexPosition.clearSelection(); selection = mouse; selection.select("Selection"); if (selectAttackable(myUnit)) { turn = Turn.ATTACK; } else { myUnit.skipAttack(); unselect(); } } } else { Unit enemy = mouse.getUnit(); if (enemy != null) { Unit myUnit = selection.getUnit(); if (isAttackable(myUnit, enemy)) { actuallyAttack(); } } } }
void Update() { if (!isLocalPlayer || !myTurn || waiting) { return; } if (!Input.mousePresent) { mouse = null; } else { HexPosition newMouse = getMouseHex(); if (newMouse == null) { HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = null; } else { if (newMouse != mouse) { if (mouse != null) { mouse.unselect("Cursor"); } if (newMouse.containsKey("Obstacle")) //The Obstacle tag is being used to make the tile unselectable. { if (mouse != null && turn == Turn.MOVE) { HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = null; } mouse = null; return; } mouse = newMouse; mouse.select("Cursor"); if (turn == Turn.MOVE) { Unit unit = selection.getUnit(); HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = AStar.search(selection, mouse, unit.SPEED); HexPosition.select("Path", path); selectAttackable(unit, mouse); } } if (Input.GetButtonDown("Fire1")) { switch (turn) { case Turn.SELECT: select(); break; case Turn.MOVE: move(); break; case Turn.ATTACK: attack(); break; default: print("Error: Turn " + turn + " not implemented."); break; } return; } } } }
void Update() { if (waiting || gameOver || !modeSelected) { return; } if (player == 1 && computerPlayer) { if (ai.go()) { endTurn(); } checkGameOver(); return; } /*if (timeout > 0) { * --timeout; * if(timeout == 0) { * print ("Warning: HexGrid.cs timed out."); * } * return; * }*/ if (!Input.mousePresent) { mouse = null; } else { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray); if (hits.Length == 0) { if (mouse != null && turn == Turn.MOVE) { HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = null; } // No hits == null mouse = null; } else // if hit(s) { // Find closest float minDist = float.PositiveInfinity; int min = 0; for (int i = 0; i < hits.Length; ++i) { if (hits[i].distance < minDist) { minDist = hits[i].distance; min = i; } } HexPosition newMouse = new HexPosition(hits[min].point); if (newMouse != mouse) { if (mouse != null) { mouse.unselect("Cursor"); } if (newMouse.containsKey("Obstacle")) { //The Obstacle tag is being used to make the tile unselectable. if (mouse != null && turn == Turn.MOVE) { HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = null; } mouse = null; return; } mouse = newMouse; mouse.select("Cursor"); if (turn == Turn.MOVE) { Unit unit = (Unit)selection.getValue("Unit"); HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = AStar.search(selection, mouse, unit.SPEED); HexPosition.select("Path", path); selectAttackable(unit, mouse); } } if (Input.GetButtonDown("Fire1")) { switch (turn) { case Turn.SELECT: select(); break; case Turn.MOVE: move(); break; case Turn.ATTACK: attack(); break; default: print("Error: Turn " + turn + " not implemented."); break; } return; } } } }
void Update() { if (waiting || gameOver || !modeSelected) { return; } if (player == 1 && computerPlayer) { if (ai.go()) { endTurn(); } checkGameOver(); return; } /*if (timeout > 0) { --timeout; if(timeout == 0) { print ("Warning: HexGrid.cs timed out."); } return; }*/ if (!Input.mousePresent) { mouse = null; } else { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray); if (hits.Length == 0) { if (mouse != null && turn == Turn.MOVE) { HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = null; } // No hits == null mouse = null; } else // if hit(s) { // Find closest float minDist = float.PositiveInfinity; int min = 0; for (int i = 0; i < hits.Length; ++i) { if (hits[i].distance < minDist) { minDist = hits[i].distance; min = i; } } HexPosition newMouse = new HexPosition(hits[min].point); if (newMouse != mouse) { if (mouse != null) { mouse.unselect("Cursor"); } if (newMouse.containsKey("Obstacle")) { //The Obstacle tag is being used to make the tile unselectable. if (mouse != null && turn == Turn.MOVE) { HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = null; } mouse = null; return; } mouse = newMouse; mouse.select("Cursor"); if (turn == Turn.MOVE) { Unit unit = (Unit)selection.getValue("Unit"); HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = AStar.search(selection, mouse, unit.SPEED); HexPosition.select("Path", path); selectAttackable(unit, mouse); } } if (Input.GetButtonDown("Fire1")) { switch (turn) { case Turn.SELECT: select(); break; case Turn.MOVE: move(); break; case Turn.ATTACK: attack(); break; default: print("Error: Turn " + turn + " not implemented."); break; } return; } } } }
public void move(HexPosition desitination, HexPosition[] path) { this.path = new Vector3[path.Length]; for (int i = 0; i < path.Length; ++i) { this.path[i] = path[i].getPosition(); } state = State.ATTACK; if (desitination.containsKey ("Unit")) { print ("Space occupied."); grid.actionComplete(); return; } position.remove ("Unit"); desitination.add ("Unit", this); //transform.position = desitination.getPosition(); t = 0; n = 0; moving = true; position = desitination; }
private void build() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray); float minDist = float.PositiveInfinity; int min = 0; for (int i=0; i<hits.Length; ++i) { if(hits[i].distance < minDist) { minDist = hits[i].distance; min = i; } } HexPosition newMouse = new HexPosition (hits[min].point); if (!newMouse.containsKey("Obstacle") && !newMouse.containsKey("Unit")) { gm.build_place_here(newMouse); } }
void Update() { if (waiting || gameOver || !modeSelected) { return; } if (player == 1 && computerPlayer) { if (ai.go()) { endPhase(); } checkGameOver(); return; } if (!Input.mousePresent) { mouse = null; } else { HexPosition newMouse = getMouseHex(); if (newMouse == null) { HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = null; } else { if (newMouse != mouse) { if (mouse != null) { mouse.unselect("Cursor"); } if (newMouse.containsKey("Obstacle")) //The Obstacle tag is being used to make the tile unselectable. { if (mouse != null && phase == Phase.MOVE) { HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = null; } mouse = null; return; } mouse = newMouse; //display where the cursor is pointing at mouse.select("Cursor"); //if is in move phase, also display the route toward where the cursor is current at if (phase == Phase.MOVE) { Unit unit = selection.getUnit(); HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); path = AStar.search(selection, mouse, unit.SPEED); HexPosition.select("Path", path); } } if (Input.GetMouseButtonDown(0)) { switch (phase) { case Phase.SELECT: select(); break; case Phase.MOVE: move(); break; case Phase.ATTACK: attack(); break; default: print("Error: Turn " + phase + " not implemented."); break; } return; } else if (Input.GetMouseButtonDown(1)) { HexPosition.clearSelection("Path"); HexPosition.clearSelection("Attack"); HexPosition.clearSelection("Movable"); HexPosition.clearSelection("Selection"); phase = Phase.SELECT; Unit unit = selection.getUnit(); unit.undoMovement(moveFromPos); unit.setState(Unit.State.MOVE); selectSelectable(); } } } }