/// <summary> /// Resets this generator's output state. /// </summary> /// <param name="newSize">If not null, the output will be resized to the given size.</param> public void Reset(Vector2i?newSize, int?seed) { if (seed.HasValue) { Rng = new Random(seed.Value); } //If necessary, re-allocate output data. if (newSize.HasValue) { Output = new OutputPixel[newSize.Value.x, newSize.Value.y]; foreach (Vector2i pos in Output.AllIndices()) { Output.Set(pos, new OutputPixel()); } } //Reset output data. foreach (var pixel in Output) { pixel.FinalValue = null; pixel.VisualizedValue = Input.AverageColor; pixel.ApplicableColorFrequencies.Clear(); foreach (KeyValuePair <Color, uint> kvp in Input.ColorFrequencies) { pixel.ApplicableColorFrequencies.Add(kvp.Key, kvp.Value); } } }
public void UpdateInventory() { Update_ItemDisplayData(); float x = Input.NDCMouseX, y = Input.NDCMouseY; y -= 24f / Program.Height; int cx = (int)(10 * (x - Pos.x)); int cy = (int)(10 / Program.AspectRatio * (y - Pos.y)); if (cx < 0 || cx >= Items.GetLength(0) || cy < 0 || cy >= Items.GetLength(1) - 1 || !InventoryOpen) { Selected = null; return; } Selected = new Vector2i(cx, cy); if (Input.Mouse[Input.MouseLeft]) { if (!MouseFlag) { SwapItems(new Vector2i(cx, cy + 1), new Vector2i(CurSelectedSlot, 0)); } MouseFlag = true; } else { MouseFlag = false; } }
private static void DrawMousePosition() { mousePosition = Event.current.mousePosition; mousePosition.y = SceneView.currentDrawingSceneView.camera.pixelHeight - mousePosition.y; mousePosition = SceneView.currentDrawingSceneView.camera.ScreenToWorldPoint(mousePosition); mousePosition.y = -mousePosition.y; mousePosition.y *= -1; mouseCoord = _instance.mapEditor.Data.Grid.GetCoordAt(mousePosition); //Debug.Log("Drawn : " + mousePosition); Handles.BeginGUI(); string coordText; string mousePositionText = "Mouse Position : " + mousePosition + " (World coordinate)"; if (mouseCoord.HasValue) { coordText = "Coord : " + mouseCoord.Value.x + ", " + mouseCoord.Value.y; } else { coordText = "Coord : " + "None"; } GUILayout.Label(mousePositionText); GUILayout.Label(coordText); Handles.EndGUI(); }
public void Raise_OnFinished(Vector2i?selectedTile) { if (OnFinished != null) { OnFinished(selectedTile); } }
void Update() { if (ActiveSnap) { float snapValue = MapEditorModel.instance.caseSize; if (snapValue == 0) { return; } Vector2i?coord = MapEditorModel.instance.grid.GetCoordAt(transform.position); if (coord.HasValue) { if (_oldPosition.x != transform.position.x) { _coord.x = coord.Value.x; } if (_oldPosition.y != transform.position.y) { _coord.y = coord.Value.y; } Vector2 casePosition = MapEditorModel.instance.grid.GetCasePosition(_coord); transform.position = casePosition + _offset; _oldPosition = transform.position; } } }
static public IEnumerator CollapseField(Directions dir, Vector2i?lastPos) { float posTime = GameManager.Instance.Definitions.CollapseFieldTime; bool[,] matched; while (true) { matched = GameManager.Instance.Grid.CheckMatches(); if (matched != null) { yield return(StartCoroutine(Collect(matched, dir, lastPos))); lastPos = null; int maxCtr = GameManager.Instance.Grid.Collapse(matched, posTime, dir); //yield return new WaitForSeconds(GameManager.Instance.Definitions.CollectStatsTime); float waitTime = posTime * (maxCtr - 1); // - GameManager.Instance.Definitions.CollectStatsTime; if (waitTime > 0) { yield return(new WaitForSeconds(waitTime)); } yield return(StartCoroutine(GameManager.Instance.HeroManager.Spawn())); GameManager.Instance.Grid.Log(); } else { yield break; } } }
public override void Step(float dt, Field <Cell> field) { var dist = Distance(waypoint, Position); if (dist < 0.1f || dist > 2 * SEARCHING_RADIUS) { var target = FindFarSmell(field, SEARCHING_RADIUS, Map.Smells.SmellType.FromFood); if (!target.found) { float sgnX = (randomizer.Next(0, 9) < 5) ? 1 : -1; float sgnY = (randomizer.Next(0, 9) < 5) ? 1 : -1; waypoint.X = randomizer.Next(NEW_WP_MIN_DIST, SEARCHING_RADIUS) * sgnX; waypoint.Y = randomizer.Next(NEW_WP_MIN_DIST, SEARCHING_RADIUS) * sgnY; foodPosition = null; } else { waypoint.X = target.position.X; waypoint.Y = target.position.Y; foodPosition = target.position; } waypoint += Position; Direction = Normalize(waypoint - Position); } else { if (IsRotating) { Direction = Normalize(waypoint - Position); } } Position += Direction * dt * speed; }
private void Move(GameTime gameTime) { if (tileDestination == null) { return; } if (Directions.IsVectorsEqual(Position, pointDestination)) { if (shortestPathToPoint == null || !shortestPathToPoint.MoveNext()) { state = EnemyState.Patrol; return; } tileDestination = shortestPathToPoint.Current; pointDestination = level.Map.ConvertToWindowCoordinates((Vector2i)tileDestination); } var direction = Directions.Normalize(level.Map.ConvertToWindowCoordinates((Vector2i)tileDestination) - Position); var moveVector = speed * direction * gameTime.DeltaTime; if (level.Map.GetTileGidInLayer((Vector2i)tileDestination, level.Map.collisionTiles) != Map.Wall && !CheckCollisions(moveVector)) { Position += moveVector; var oldRotation = Rotation; Rotation = GetRotationDependingOnDirection(moveVector); viewZone.Position = Position; viewZone.Rotate((Rotation - oldRotation) * (float)Math.PI / 180); } }
public override bool Equals(object obj) { Vector2i?other = obj as Vector2i?; return (other.HasValue && (other.Value.x == this.x) && (other.Value.y == this.y)); }
// Hit to unclaim public override InteractResult OnActLeft(InteractionContext context) { Vector2i?position = ClaimingUtils.GetClaimingPosition(context); Player player = context.Player; if (!position.HasValue) { return(InteractResult.NoOp); } var plot = PropertyManager.GetPlot(position.Value); var deed = plot?.Deed; if (deed == null) { return(ErrorAlreadyPublic); } // shift + click if (context.Modifier == InteractionModifier.Shift) { var nearbyDeeds = PropertyManager.ConnectedDeeds(player.User, position.Value)?.Distinct(); if (nearbyDeeds != null && nearbyDeeds.Count() > 0) { ClaimingUtils.ChangeWithDialog(player, nearbyDeeds, position.Value); } else { return(ErrorNoNearby); } return(InteractResult.NoOp); } // ctrl + click else if (context.Modifier == InteractionModifier.Ctrl) { DeleteWithDialog(player, deed); return(InteractResult.NoOp); // } // regular click else { var deedsAfterUnclaim = deed.GetContiguousPartsWithAlterations(null, new List <Vector2i> { position.Value }); if (deedsAfterUnclaim.Count > 1) { this.ConfirmUnclaim(player, Localizer.Do($"Unclaiming this plot will split {deed.Name} into {deedsAfterUnclaim.Count()} because property must be contiguous on a deed. Do you want to continue?"), position.Value); return(InteractResult.NoOp); } var result = (InteractResult)PropertyManager.TryUnclaim(new GameActionPack(), player.User, player.User.Inventory, position.Value, autoPerform: true); return(result); } }
/// <summary> /// Checks for equality between this instance and a specified object. /// </summary> /// <param name="obj">An object.</param> /// <returns>A value indicating whether this instance and the object are equal.</returns> public override bool Equals(object obj) { Vector2i?objV = obj as Vector2i?; if (objV != null) { return(this.Equals(objV)); } return(false); }
public override bool Equals(object other) { Vector2i?vOther = other as Vector2i?; if (vOther == null) { return(false); } return(Equals((Vector2i)vOther)); }
protected List <Vector2i> GetValidShootingPositions(Vector2i?targetCoords = null, uint?shootingDistance = null) { Vector2i TargetCoords = targetCoords != null ? (Vector2i)targetCoords : GamestateManager.Instance.Player.Coords; return(GetAllShootingPositions(TargetCoords, shootingDistance) .OrderBy(position => position.ManhattanDistance(Owner.Coords)) .ThenBy(postion => GamestateManager.Instance.Map.GetFieldFromRegion(postion).TraversabilityMultiplier) .ToList() .FindAll(position => GamestateManager.Instance.Map.IsFieldTraversible(position) && IsLineUnobstructed(TargetCoords.GetAllVectorsBeetween(position)))); }
// Hit to unclaim public override InteractResult OnActLeft(InteractionContext context) { Vector2i?position = this.GetPosition(context); Player player = context.Player; if (!position.HasValue) { return(InteractResult.NoOp); } return((InteractResult)PropertyManager.Unclaim(player.User, position.Value)); }
public bool Resolve() { var enemiesInAttackRange = new Queue <KeyValuePair <double, List <IEnt> > >(Instance._gridCom .EntsInRange(Instance._cellInfoCom.Cords, Instance._unitInfoCom.VisionRange) .Where(i => Instance.IsEnemy(i.Value.First())) .OrderBy(i => i.Key) ); if (enemiesInAttackRange.Count <= 0) { return(false); } Vector2i?closestEnemyCords = null; while (enemiesInAttackRange.Count > 0 && closestEnemyCords == null) { var enemiesInDistance = new Queue <IEnt>(enemiesInAttackRange.Dequeue().Value); while (enemiesInDistance.Count() > 0) { var cords = enemiesInDistance.Dequeue().Parent.GetCom <CellInfoCom>().Cords; var astarResult = Instance._gridCom .AStar(Instance._cellInfoCom.Cords, cords, false); if (astarResult != null) { closestEnemyCords = cords; Debug.Assert(astarResult.Count() > 0); Instance._path = astarResult.ToList(); break; } } } if (closestEnemyCords == null) { return(false); } Instance._closestEnemyCords = closestEnemyCords; var dist = Instance._gridCom.DistanceBetween((Vector2i)closestEnemyCords, Instance._cellInfoCom.Cords); if (dist > Instance._unitInfoCom.AttackRange + 1) { return(false); } return(true); }
public bool MoveNext([NotNullWhen(true)] out Vector2i?indices) { if (_yIndex > _chunkRT.Y) { _yIndex = _chunkLB.Y; _xIndex += 1; } indices = new Vector2i(_xIndex, _yIndex); _yIndex += 1; return(_xIndex <= _chunkRT.X); }
void Start() { if (HexTerrain.Instance != null) { _gridPosition = HexTerrain.Instance.RegisterPawn(this); if (_gridPosition.HasValue) { Vector3 newPosition = HexagonUtils.ConvertHexaSpaceToOrthonormal(_gridPosition.Value); newPosition.y = HexTerrain.Instance.HexData[_gridPosition.Value].Height; transform.position = newPosition; } } }
static IEnumerator Collect(bool[,] matched, Directions dir, Vector2i?lastPos) { GameManager.Instance.HUD.SetUpdateVisual(false); GameManager.Instance.EnemyManager.SetUpdateVisual(false); GameManager.Instance.HeroManager.SetUpdateVisual(false); Vector2i pos; _ignoreSpecialGems = false; yield return(StartCoroutine(CollectCross(matched))); int multiplier = 1; List <Vector2i> multiplyList = GameManager.Instance.Grid.DetectMatchedGems(matched, LevelData.GemEffectType.ET_GEM_MULTIPLY); if (multiplyList != null) { for (int i = 0; i < multiplyList.Count; i++) { multiplier *= 2; } yield return(StartCoroutine(GameManager.Instance.HUD.Overlay.ShowMultiplier(multiplier))); } yield return(StartCoroutine(CollectBoost(matched, multiplier))); if (!_ignoreSpecialGems) { CreateSpecialGems(ref matched, dir, lastPos); } for (pos.x = 0; pos.x < Constants.FIELD_SIZE_X; pos.x++) { for (pos.y = 0; pos.y < Constants.FIELD_SIZE_Y; pos.y++) { if (matched[pos.x, pos.y]) { Collect(pos, multiplier); } } } yield return(new WaitForSeconds(GameManager.Instance.Definitions.CollectStatsTime)); GameManager.Instance.HUD.SetUpdateVisual(true); GameManager.Instance.EnemyManager.SetUpdateVisual(true); GameManager.Instance.HeroManager.SetUpdateVisual(true); float fadeOutTime = GameManager.Instance.Definitions.MatchFadeTime - GameManager.Instance.Definitions.CollectStatsTime; yield return(new WaitForSeconds(fadeOutTime)); }
private bool CanReachTargetDirectly() { NavGrid navGrid = Map.instance.navGrid; Vector2i?characterCoord = navGrid.GetCoordAt(_character.position); Vector2i?targetCoord = navGrid.GetCoordAt(_target.position); if (characterCoord == null || targetCoord == null) { return(false); } return(navGrid.IsClearLine(characterCoord.Value, targetCoord.Value)); }
//Public interface public RayResult RayCast(Vector2f O, float A) { RayResult result; Vector2f start = O; Vector2i? toIgnore = null; int fs = 0; do { result = RayCastInternal(O, start, A, toIgnore); result = Map[result.Tile.X, result.Tile.Y, toIgnore].OnIntersection(result, O, A, this); start = result.Position; toIgnore = result.Tile; }while (!result.Valid & fs++ < MaxRayRecast); return(result); }
public void SaveOffset() { Vector2i?coord = MapEditorModel.instance.grid.GetCoordAt(transform.position); if (coord.HasValue) { Vector2 casePosition = MapEditorModel.instance.grid.GetCasePosition(coord.Value); _offset = new Vector2(transform.position.x, transform.position.y) - casePosition; } else { _offset = Vector2.zero; } _oldPosition = transform.position; }
public void NotifyAboutShooting(Vector2f position) { var tiledPosition = level.Map.ConvertToTileCoordinates(Position); var shootingPositionInTiles = level.Map.ConvertToTileCoordinates(position); var path = level.Map.FindPathInTiles(tiledPosition, shootingPositionInTiles); if (path != null) { shortestPathToPoint = path.Reverse().GetEnumerator(); } else { shortestPathToPoint = null; } tileDestination = level.Map.ConvertToTileCoordinates(Position); pointDestination = level.Map.ConvertToWindowCoordinates(tiledPosition); speed = 400; state = EnemyState.MovingToPoint; }
public void OnNotify(IEnt ent, GameEvent evt) { switch (evt) { case GameEvent.AI_TAKE_TURN: { _cellInfoCom = Owner.Parent.GetCom <CellInfoCom>(); _gridCom = ent.GetCom <GridCom>(); var action = _decisionTrees[_currentState].GetAction(); action.TakeAction(); _gridCom = null; _closestEnemyCords = null; _cellInfoCom = null; break; } } }
// Interact to examine public override InteractResult OnActInteract(InteractionContext context) { Vector2i?position = ClaimingUtils.GetClaimingPosition(context); if (!position.HasValue) { return(InteractResult.NoOp); } Deed deed = PropertyManager.GetDeed(position.Value); if (deed != null) { deed.OpenAuthorizationMenuOn(context.Player); return(InteractResult.Success); } return(base.OnActLeft(context)); }
public bool MoveNext([NotNullWhen(true)] out Vector2i? chunkIndices) { if (_y > _topLeft.Y) { _x++; _y = _bottomRight.Y; } if (_x > _bottomRight.X) { chunkIndices = null; return false; } chunkIndices = new Vector2i(_x, _y); _y++; return true; }
// Place to claim public override InteractResult OnActRight(InteractionContext context) { Vector2i?position = this.GetPosition(context); Player player = context.Player; if (!position.HasValue) { return(InteractResult.NoOp); } Deed deed = PropertyManager.FindNearbyDeedOrCreate(player.User, position.Value); Result claimResult = PropertyManager.Claim(deed.Id, player.User, position.Value); if (!claimResult.Success && !deed.OwnedObjects.Any()) { PropertyManager.TryRemoveDeed(deed); } return((InteractResult)claimResult); }
public override void RightClick(Vector2 position) { base.RightClick(position); if (SelectionManager.Instance.SelectedControlledAgents.Any()) { Vector2i?pos = GetActualPosition(position); if (!pos.HasValue) { // Insantiate bad selection! return; } // Instantiate good selection! LocationTarget locationTarget = (LocationTarget)Object.Instantiate(AgentController.Instance.locationTargetPrefab, Vector2.one * -100, Quaternion.identity); locationTarget.transform.SetParent(SelectionManager.Instance.targetsParent); locationTarget.SetLocations(new[] { pos.Value }); SelectionManager.Instance.SelectedControlledAgents.ForEach(a => a.Target = locationTarget); } }
public IWindow CreateWindow(Guid resourceId, string title, string windowGroup, IWindowBackend listener, WindowOptions options, Vector2i position, Vector2i size, Vector2i?minSize, Vector2i?maxSize, WindowState state, IWindow parentWindow, bool blockParentInput) { lock (syncRoot) { AssertNotDisposed(); DefaultWindow window = new DefaultWindow(this, resourceId, title, windowGroup, listener, options, position, size, minSize.GetValueOrDefault(new Vector2i(0, 0)), maxSize.GetValueOrDefault(new Vector2i(int.MaxValue, int.MaxValue)), state, parentWindow, blockParentInput); windows.Add(window); return(window); } }
// Interact to examine public override InteractResult OnActInteract(InteractionContext context) { Vector2i?position = this.GetPosition(context); if (!position.HasValue) { return(InteractResult.NoOp); } Deed deed = PropertyManager.GetDeed(position.Value); if (deed == null) { return(InteractResult.NoOp); } else { deed.OpenAuthorizationMenuOn(context.Player); return(InteractResult.Success); } }
static IEnumerator ProcessMove(Directions dir, Vector2i?lastPos) { GameManager.Instance.HUD.Waves.AddMove(); yield return(StartCoroutine(CollapseField(dir, lastPos))); yield return(StartCoroutine(GameManager.Instance.EnemyManager.Move())); if (GameManager.Instance.HUD.Health.Get() > 0) { yield return(StartCoroutine(GameManager.Instance.EnemyManager.FetchWave())); GameManager.Instance.EnemyManager.Charge(); GameManager.Instance.HeroManager.Charge(); GameManager.Instance.Grid.Log(); if (GameManager.Instance.EnemyManager.AllDead()) { SetInputState(false); GameManager.Instance.HUD.Overlay.Show(true); // increase LevelsFinished if player won last opened level if (PlayerPrefs.HasKey(Constants.LevelsFinished)) { int levelCount = PlayerPrefs.GetInt(Constants.LevelsFinished); if (GameManager.Instance.InitStruct.levelIndex == (levelCount - 1)) { PlayerPrefs.SetInt(Constants.LevelsFinished, levelCount + 1); PlayerPrefs.Save(); } } } } else { SetInputState(false); GameManager.Instance.HUD.Overlay.Show(false); } }
//Assumes CanMoveToOrigin has already passed public void AddToFloor(Vector2i newOrigin) { origin = newOrigin; Simulation.OnMachineMoved(this); }
public void OnDragStart(Vector2 inPos) { oldOrigin = machine.Origin; GameMode.Current = GameMode.Mode.MoveMachine; machine.RemoveFromFloor(); CollisionEnabled = false; transform.position = inPos; Display(machine); }
public void RemoveFromFloor() { origin = null; Simulation.OnMachineMoved(this); //TODO: Destroy crane links }