public int directionToAngle(Command.Direction dir) { if (dir == Command.Direction.North) { return(45 * 0); } else if (dir == Command.Direction.NorthWest) { return(45 * 1); } else if (dir == Command.Direction.West) { return(45 * 2); } else if (dir == Command.Direction.SouthWest) { return(45 * 3); } else if (dir == Command.Direction.South) { return(45 * 4); } else if (dir == Command.Direction.SouthEast) { return(45 * 5); } else if (dir == Command.Direction.East) { return(45 * 6); } else { return(45 * 7); } }
Vector2Int getCollisionLocationAndUpdateSteps(Command.Direction direction, GameObject unitToCommand, Command command) { Vector2Int cellPosition = getCellPosition(unitToCommand); for (int i = 0; i < 22; i++) { Vector2Int nextCellLocation = new Vector2Int(cellPosition.x + directionToMutatorVector[direction].x, cellPosition.y + directionToMutatorVector[direction].y); if (!(Mathf.Abs(nextCellLocation.x) <= 5 && Mathf.Abs(nextCellLocation.y) <= 5)) { if (i < command.nbOfSteps) { command.nbOfSteps = i; } return(nextCellLocation); } foreach (GameObject unit in units) { if (unit != null && (unit.GetComponent <unit_behaviour>().id != unitToCommand.GetComponent <unit_behaviour>().id && getCellPosition(unit) == nextCellLocation)) { if (i < command.nbOfSteps) { command.nbOfSteps = i; } Debug.Log("Hit a player"); return(nextCellLocation); } } foreach (GameObject box in boxes) { Debug.Log("Box is " + box); if (box != null && (getCellPosition(box) == nextCellLocation)) { if (i < command.nbOfSteps) { command.nbOfSteps = i; } Debug.Log("Hit a box"); return(nextCellLocation); } } cellPosition = nextCellLocation; } return(new Vector2Int(0, 0)); }
public void turn(Command.Direction dir) { SpriteRenderer spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); // Non-diagonals if (dir == Command.Direction.North) { spriteRenderer.sprite = spriteArray[3]; } else if (dir == Command.Direction.East) { spriteRenderer.sprite = spriteArray[4]; } else if (dir == Command.Direction.South) { spriteRenderer.sprite = spriteArray[1]; } else if (dir == Command.Direction.East) { spriteRenderer.sprite = spriteArray[0]; } // Diagonals else if (dir == Command.Direction.NorthEast) { spriteRenderer.sprite = spriteArray[3]; } else if (dir == Command.Direction.SouthEast) { spriteRenderer.sprite = spriteArray[1]; } else if (dir == Command.Direction.SouthWest) { spriteRenderer.sprite = spriteArray[2]; } else { spriteRenderer.sprite = spriteArray[4]; } }
public static byte requestType(Command.Direction d) { return((byte)(d == Command.Direction.DEVICE_TO_HOST ? 0xC0 : 0x40)); }