/// <summary> /// Get the next player position, and send an event for each feedback. /// </summary> /// <param name="coordPos"></param> public void PlayerMoveFeedback(Vector2Int coordPos) { Vector2Int coordPosInt = new Vector2Int(coordPos.x, coordPos.y); Vector2Int matrixPos = CoordinatesConverter.CoordinateToMatrixIndex(coordPosInt, SharedVariables.matrixDimensions.x); if (IsPositionOutOfBounds(matrixPos)) { OnCollided.Invoke(false); return; } else if (Matrix[matrixPos.x, matrixPos.y] == GridTags.Inaccessible.GetHashCode()) //snake has collided { OnCollided.Invoke(false); } else if (Matrix[matrixPos.x, matrixPos.y] == GridTags.Item.GetHashCode()) //snake collected an item { OnItemCollected.Invoke(coordPos); } else//the path is free , you can walk { OnFreePathOcurred.Invoke(coordPos); } OnChangeMatrixValue.Invoke(matrixPos, GridTags.Inaccessible); Matrix[matrixPos.x, matrixPos.y] = GridTags.Inaccessible.GetHashCode(); }
public virtual void OnPosition(GameEntity entity, Vector2Int value) { transform.DOLocalMove(CoordinatesConverter.Convert(value, size), 0.3f); bubblePosition = value; collider.enabled = true; }
public void CreateExampleMap() { LoadedNormalTiles = new Dictionary <Vector2i, NormalTerrainTile>(); double lon = 139.819038; double lat = 35.666048; int xCoor = CoordinatesConverter.LonToX(lon, 14); int yCoor = CoordinatesConverter.LatToY(lat, 14); xCoor = 14555; yCoor = 6452; int xNum = 1; int yNum = 1; isUseToggle = usePNGtoggle.isOn; Vector3 startPos = new Vector3(0, 0, 0); //draw map for (int i = xCoor; i < xCoor + xNum; i++) { for (int j = yCoor; j < yCoor + yNum; j++) { create(new Vector2i(i, j), startPos); startPos.z += TerrainSize; } startPos.x += TerrainSize; startPos.z = 0; } }
protected override void Execute(List <TimerEntity> entities) { foreach (var e in entities) { var mergeProgressMergeNumber = e.mergeProgress.mergeNumber; var mergeBubblePosition = e.mergeProgress.mergeBubblePosition; e.RemoveTimer(); contexts.timer.RemoveMergeProgress(); var newBubble = contexts.game.GetBubbleWithPosition(mergeBubblePosition); contexts.game.SpawnEffect( CoordinatesConverter.Convert(mergeBubblePosition, contexts.config.gameConfig.value.BubbleSize), mergeProgressMergeNumber); contexts.game.SpawnTextEffect( CoordinatesConverter.Convert(mergeBubblePosition, contexts.config.gameConfig.value.BubbleSize), mergeProgressMergeNumber); contexts.gameState.ReplaceScore(contexts.gameState.score.value + mergeProgressMergeNumber); if (newBubble != null) { newBubble.isNewBubble = true; } else { contexts.game.isMoveComplete = true; } } }
/// <summary> /// Set an matrix position to 'Empty' /// </summary> /// <param name="pos"></param> public void RemoveValueFromMatrix(Vector2 pos) { Vector2Int posInt = new Vector2Int((int)pos.x, (int)pos.y); posInt = CoordinatesConverter.CoordinateToMatrixIndex(posInt, SharedVariables.matrixDimensions.x); Matrix[(int)posInt.x, (int)posInt.y] = GridTags.Empty.GetHashCode(); OnChangeMatrixValue.Invoke(posInt, GridTags.Empty); }
public void ConvertItmToWgs84() { var converter = new CoordinatesConverter(); var latlon = converter.ItmToWgs84(new NorthEast { North = 656000, East = 200000 }); Assert.AreEqual(31.99702701, latlon.Latitude, 1e-7); Assert.AreEqual(34.9986170, latlon.Longitude, 1e-7); }
public void ConvertWgs84ToItm() { var converter = new CoordinatesConverter(); var northEast = converter.Wgs84ToItm(new LatLon { Latitude = 31.99702701, Longitude = 34.9986170 }); Assert.AreEqual(200000, northEast.East); Assert.AreEqual(656000, northEast.North); }
// Use this for initialization void Start() { double lon = 139.820550; double lat = 35.665557; int zoomLevel = 14; Debug.Log(CoordinatesConverter.LonToX(lon, zoomLevel)); Debug.Log(CoordinatesConverter.LatToY(lat, zoomLevel)); }
public void OnMergeTarget(GameEntity entity, Vector2Int value) { shadow.SetActive(false); gameObject.transform.DOLocalMove(CoordinatesConverter.Convert(value, size), destroyDuration).OnComplete( () => { entity.isDestroyed = true; base.destroy(); entity.Destroy(); }); }
public virtual void OnPosition(GameEntity entity, Vector2Int value) { transform.DOKill(); transform.localScale = new Vector3(0.01f, 0.01f, 1); var newPos = CoordinatesConverter.Convert(value, 1.2f); newPos.z = -1; transform.localPosition = newPos; transform.DOScale(new Vector3(0.45f, 0.45f, 1), 0.5f); }
void SpawnItem() { int randomItem = Random.Range(0, items.Length); currentItem = items[randomItem]; //get random item int randomSpawnPoint = Random.Range(0, possibleSpawnPoints.Count); Vector2Int spawnPoint = possibleSpawnPoints[randomSpawnPoint]; OnItemSpawned.Invoke(spawnPoint); SetPossibleSpawnPoints(CoordinatesConverter.CoordinateToMatrixIndex(spawnPoint, SharedVariables.matrixDimensions.x), GridTags.Item); }
public void IsConverterReturnNotNull() { //Arrange var lati = 54.719823; var longi = 25.320651; //Act var Data = CoordinatesConverter.GetConvertedCoordinates(lati, longi); //Assert Assert.IsNotNull(Data); }
public void Link(IEntity entity) { var e = (GameEntity)entity; e.AddPositionListener(this); e.AddVisibleListener(this); if (e.hasPosition) { transform.localPosition = CoordinatesConverter.Convert(e.position.value, 1.2f); } SpriteRenderer.enabled = false; }
public void FirstSpawn() { currentItem = items[0]; if (possibleSpawnPoints.Contains(Vector2Int.one)) { possibleSpawnPoints.Remove(Vector2Int.one); } Vector2Int spawnPoint = possibleSpawnPoints[Random.Range(0, possibleSpawnPoints.Count)]; OnItemSpawned.Invoke(spawnPoint); SetPossibleSpawnPoints(CoordinatesConverter.CoordinateToMatrixIndex(spawnPoint, SharedVariables.matrixDimensions.x), GridTags.Item); }
private static State <FilterChainState, IEnumerable <XElement> > BuildDiffuseLightingGenerator( DiffuseLightingGenerator diffuseLightingGenerator, CoordinatesConverter converter) { XElement lightComponent = diffuseLightingGenerator.Light.Pipe(x => BuildLightComponent(x, converter)); var elementCore = XElementBuilder.WithName("feDiffuseLighting") .Add( new XAttribute("lighting-color", SvgColorFactory.SvgColor(diffuseLightingGenerator.LightColor)), new XAttribute("surfaceScale", diffuseLightingGenerator.SurfaceScale), new XAttribute("diffuseConstant", diffuseLightingGenerator.DiffuseConstant)) .Add(lightComponent); return(BuildIOFilter(elementCore).Select(x => x.Build()).Select(x => new[] { x }.AsEnumerable())); }
public void SetPossibleSpawnPoints(Vector2 pos, GridTags tag) { Vector2Int posInt = new Vector2Int((int)pos.x, (int)pos.y); posInt = CoordinatesConverter.MatrixIndexToCoordinate(posInt, SharedVariables.matrixDimensions.x); if (tag == GridTags.Empty) { if (!possibleSpawnPoints.Contains(posInt)) { possibleSpawnPoints.Add(posInt); } } else { if (possibleSpawnPoints.Contains(posInt)) { possibleSpawnPoints.Remove(posInt); } } }
private static XElement BuildLightComponent(IFilterLight filterLight, CoordinatesConverter coordinatesConverter) { if (filterLight is Spotlight spotlight) { SvgCoordinate3d startPosition = spotlight.LightSource.Pipe(coordinatesConverter.ToSvgCoord); SvgCoordinate3d endPosition = spotlight.LightDestination.Pipe(coordinatesConverter.ToSvgCoord); return (XElementBuilder.WithName("feSpotLight") .Add( new XAttribute("x", startPosition.X), new XAttribute("y", startPosition.Y), new XAttribute("z", startPosition.Z), new XAttribute("pointsAtX", endPosition.X), new XAttribute("pointsAtY", endPosition.Y), new XAttribute("pointsAtZ", endPosition.Z), new XAttribute("specularExponent", spotlight.SpecularExponent), new XAttribute("limitingConeAngle", spotlight.ConeAngle.Degrees) ) .Build()); } if (filterLight is DistantLight distantLight) { return(XElementBuilder.WithName("feDistantLight") .Add( new XAttribute("azimuth", distantLight.Azimuth.Degrees), new XAttribute("elevation", distantLight.Elevation.Degrees)) .Build()); } if (filterLight is PointLight pointLight) { var coordinate = coordinatesConverter.ToSvgCoord(pointLight.Coordinate); return(XElementBuilder.WithName("fePointLight").Add( new XAttribute("x", coordinate.X), new XAttribute("y", coordinate.Y), new XAttribute("z", coordinate.Z)) .Build()); } throw new Exception($"unable to generate a light source from type '{filterLight}'"); }
void Spawn(Transform prefab, Color color, ChessCoord position, FigureType type) { Transform instance = Instantiate(prefab, CoordinatesConverter.ChessToVector(position), Quaternion.identity, this.transform); instance.localScale = scaleVector; instance.gameObject.GetComponent <MeshRenderer>().material.color = color; Figure addedF = instance.gameObject.AddComponent <Figure>(); addedF.AssignTypeBehaviour(type); //Add to BoardManager BoardManager.board[(int)CoordinatesConverter.ChessToVector(position).x, (int)CoordinatesConverter.ChessToVector(position).z].figure = addedF; if (color == Color.black) { instance.localRotation = Quaternion.Euler(0f, 180f, 0f); BoardManager.blackFigures.Add(addedF); } else { BoardManager.whiteFigures.Add(addedF); } }
private void CreateApplicationEntities() { IAssetProvider assetProvider = new AssetProvider(new JsonParser()); IEntitiesCreator creator = new EntitiesCreator(gameObject, assetProvider); ICoordinatesConverter coordsConverter = new CoordinatesConverter(); IGeoJsonParser geoParser = new GeoJsonParser(); IMeshGenerator meshGenerator = new MeshGenerator(); IOutlineDrawer outlineDrawer = new OutlineDrawer(); var mapModel = creator.CreateMapModel(mapNormal, mapForwardDirection, coordsConverter, geoParser); creator.CreateMapView(mapModel, meshGenerator, outlineDrawer); IMapScanner mapScanner = new MapScanner(mapModel.MapInfo); var container = creator.CreateProjectModelContainer(mapModel, coordsConverter); var controllerFactory = creator.CreateProjectControllerFactory(mapScanner, container); _manager = controllerFactory.ProjectsManager; _uiController = creator.CreateUiController(); }
internal static XElementBuilder BuildFilter(IFilterComponent component, CoordinatesConverter converter) { var firstAttempt = BuildFilterComponent(component, converter) .Run(FilterChainState.Initial()); var firstAttemptItems = firstAttempt.Value.ToList(); List <XElement> filterChainList; if (firstAttemptItems.Any() == true) { filterChainList = firstAttemptItems; } else { var filterComponent = Filters.Noop; filterChainList = BuildFilterComponent(filterComponent, converter) .Run(firstAttempt.State).Value.ToList(); } return (XElementBuilder.WithName("filter") .Add(filterChainList)); }
public override void Link(IEntity entity) { base.Link(entity); var e = (GameEntity)entity; e.AddPositionListener(this); e.AddMergeTargetListener(this); e.AddFallingListener(this); collider.enabled = false; if (e.hasPosition) { if (e.hasStartPosition) { transform.localPosition = CoordinatesConverter.Convert(e.startPosition.Position, size); } else { transform.localPosition = CoordinatesConverter.Convert(e.position.value, size); } bubblePosition = e.position.value; collider.enabled = true; } }
private static State <FilterChainState, IEnumerable <XElement> > BuildMergeFilter(MergeFilter mergeFilter, CoordinatesConverter converter) { var states = mergeFilter.FilterComponents.Select(component => BuildInputAndMergeNode(component, converter)); var concatenated = State.Concat(states); State <FilterChainState, (ImmutableList <XElement> FilterElements, ImmutableList <XElement> MergeNodes)> aggregatedState = from items in concatenated select items .Aggregate( (FilterElements : ImmutableList <XElement> .Empty, MergeNodes : ImmutableList <XElement> .Empty), (acc, next) => (acc.FilterElements.AddRange(next.FilterInputs), acc.MergeNodes.Add(next.MergeNode))); State <FilterChainState, IEnumerable <XElement> > finishedElements = from items in aggregatedState from mergeElement in BuildMergeElement(items.MergeNodes) select items.FilterElements.Concat(new[] { mergeElement }); return(finishedElements); }
private static State <FilterChainState, (IEnumerable <XElement> FilterInputs, XElement MergeNode)> BuildInputAndMergeNode(IFilterComponent component, CoordinatesConverter converter) =>
public bool IsGroundConstructible(Vector3 pos) { //return _mapInfos.GetInfosAtPos(pos).mapType != MapInfosManager.MapType.Water; return(_mapInfos.GetInfosAtPos(CoordinatesConverter.RealToMapCoordinates(pos)).mapType != MapInfosManager.MapType.Water); }
private static State <FilterChainState, IEnumerable <XElement> > BuildBlendFilter(BlendFilter blendFilter, CoordinatesConverter converter) { var builder = XElementBuilder.WithName("feBlend") .Add( new XAttribute("mode", blendFilter.BlendModeSvgName)); return(BuildTwoInputFilter(builder, blendFilter.Source2, converter)); }
private static State <FilterChainState, IEnumerable <XElement> > BuildDisplacementFilter(DisplacementFilter displacementFilter, CoordinatesConverter converter) { var elementCore = XElementBuilder.WithName("feDisplacementMap") .Add( new XAttribute("scale", converter.ScaleDistance(displacementFilter.Scale)), new XAttribute("xChannelSelector", "R"), new XAttribute("yChannelSelector", "B") ); return(BuildTwoInputFilter(elementCore, displacementFilter.DisplacementProvider, converter)); }
private static State <FilterChainState, IEnumerable <XElement> > BuildFilterChain(FilterChain chain, CoordinatesConverter converter) { IEnumerable <State <FilterChainState, IEnumerable <XElement> > > states = chain.Components.Select(x => BuildFilterComponent(x, converter)); State <FilterChainState, ICollection <IEnumerable <XElement> > > concatenatedStates = State.Concat <FilterChainState, IEnumerable <XElement> >(states); return(concatenatedStates.Select(x => x.SelectMany(y => y))); }
private static State <FilterChainState, XElement> BuildGaussianBlur(GaussianBlurFilter filter, CoordinatesConverter converter) { var basicElement = XElementBuilder .WithName("feGaussianBlur") .Add( new XAttribute( "stdDeviation", $"{ converter.ScaleDistance( filter.StandardDeviationX )} { converter.ScaleDistance( filter.StandardDeviationY )}")); return(basicElement.Pipe(BuildIOFilter).Select(x => x.Build())); }
private static State <FilterChainState, XElement> BuildDropShadowFilter(DropShadowFilter filter, CoordinatesConverter converter) { var svgVector = filter.ShadowVector.Pipe(converter.ToSvgVector); var element = XElementBuilder.WithName("feDropShadow").Add( new XAttribute("dx", svgVector.Dx), new XAttribute("dy", svgVector.Dy), new XAttribute("stdDeviation", converter.ScaleDistance(filter.StdDeviation))); return(element.Pipe(BuildIOFilter).Select(x => x.Build())); }
private static State <FilterChainState, IEnumerable <XElement> > BuildTwoInputFilter(XElementBuilder elementCore, IFilterComponent input2, CoordinatesConverter converter) => from startingState in State.Get <FilterChainState>() from input2ProviderElements in BuildFilterComponent(input2, converter) from input2Attribute in Input2AttributeBuilder from postDisplacementState in State.Get <FilterChainState>() from resetStartingState in FilterChainState.SetInputId(startingState.NextInputId) let displacementBuilder = elementCore .Add(input2Attribute) from finalElement in BuildIOFilter(displacementBuilder) select input2ProviderElements.Concat(new[] { finalElement.Build() });
private void PredictReflectionPattern(Vector2 position, Vector2 direction, GameEntity launcherEntity, GameEntity previewEntity) { bool isReflected = false; bool isHitBubble = false; Vector2 hitPoint = new Vector2(); Vector2Int hitBubblePosition = new Vector2Int(); Vector2 hitBubbleTransformPosition = new Vector2(); var startingPosition = position; var reflectionCount = 0; var collisionPoints = new List <Vector2>(); collisionPoints.Add(startingPosition); while (reflectionCount <= contexts.config.gameConfig.value.MaxAmountOfReflections) { var hit = Physics2D.Raycast(position, direction, maxStepDistance); if (hit.collider == null) { break; } if (hit.collider.tag == "Bubble") { hitPoint = hit.point; hitBubblePosition = hit.collider.gameObject.GetComponent <BoardBubbleView>().bubblePosition; hitBubbleTransformPosition = hit.collider.transform.position; isHitBubble = true; collisionPoints.Add(hitPoint); break; } if (hit.collider.tag == "Wall") { direction = Vector2.Reflect(direction, hit.normal); position = hit.point; //small adjustment so we not stuck in the wall if (position.x < startingPosition.x) { position.x += 0.01f; } if (position.x > startingPosition.x) { position.x -= 0.01f; } collisionPoints.Add(position); reflectionCount++; } } if (isHitBubble == false) { launcherEntity.ReplaceVisible(false); previewEntity.ReplaceVisible(false); } else { var newBubblePosition = CalculateNewBubblePosition(hitBubblePosition, hitBubbleTransformPosition, hitPoint); var shownTrajectory = collisionPoints.ToArray(); var flyingTrajectory = collisionPoints.ToArray(); flyingTrajectory[flyingTrajectory.Length - 1] = GameObject.FindWithTag("Board").transform.TransformPoint(CoordinatesConverter.Convert(newBubblePosition, contexts.config.gameConfig.value.BubbleSize)); launcherEntity.ReplaceLauncherTrajectory(hitPoint, shownTrajectory, flyingTrajectory); if (!previewEntity.hasPosition) { previewEntity.AddPosition(newBubblePosition); } if (previewEntity.hasPosition && previewEntity.position.value != newBubblePosition) { previewEntity.ReplacePosition(newBubblePosition); } launcherEntity.ReplaceVisible(true); previewEntity.ReplaceVisible(true); } }
/// <summary> /// Add an Item (food) element to the matrix. /// </summary> /// <param name="pos"></param> public void AddItemToMatrix(Vector2Int pos) { Vector2Int posInt = CoordinatesConverter.CoordinateToMatrixIndex(new Vector2Int((int)pos.x, (int)pos.y), SharedVariables.matrixDimensions.x); Matrix[posInt.x, posInt.y] = GridTags.Item.GetHashCode(); }