public RectInt(VectorInt2 size) { X = 0; Y = 0; W = size.X; H = size.Y; }
private static void FillCell(BitmapSpan contraints, VectorInt2 p, IBitmap output) { if (p.X < 0 || p.Y < 0) { return; } if (p.X > contraints.Size.X || p.Y > contraints.Size.Y) { return; } if (contraints[p]) { return; } if (output[p]) { return; } output[p] = true; FillCell(contraints, p + VectorInt2.Up, output); FillCell(contraints, p + VectorInt2.Down, output); FillCell(contraints, p + VectorInt2.Left, output); FillCell(contraints, p + VectorInt2.Right, output); }
private bool UpdateRoomPosition(Vector2 newRoomPos, Room roomReference, bool moveRooms) { VectorInt2 newRoomPosInt = VectorInt2.FromRounded(newRoomPos); VectorInt2 roomMovement = newRoomPosInt - roomReference.SectorPos; if (roomMovement != new VectorInt2()) { if (EditorActions.CheckForLockedRooms(this, _roomsToMove)) { _roomMouseClicked = null; } else { var delta = new VectorInt3(roomMovement.X, 0, roomMovement.Y); if (roomMovement.X != 0 || roomMovement.Y != 0) { _overallDelta += delta; if (moveRooms) { EditorActions.MoveRooms(delta, _roomsToMove, true); return(true); } } } } return(false); }
public void InitialiseInstance(SolverNode parent, VectorInt2 playerBefore, VectorInt2 push, IBitmap crateMap, IBitmap moveMap) { base.Parent = parent; base.Clear(); // Check init/use should have a NEW id to avoid same-ref bugs; it is effectively a new instance solverNodeId = Interlocked.Increment(ref nextId); this.playerBefore = new VectorByte2(playerBefore); this.push = push switch { (0, 0) => (byte)0, (0, -1) => (byte)1, (0, 1) => (byte)2, (-1, 0) => (byte)3, (1, 0) => (byte)4, _ => throw new ArgumentOutOfRangeException(push.ToString()) }; this.crateMap = crateMap; this.moveMap = moveMap; this.status = (byte)SolverNodeStatus.UnEval; unchecked { var hashCrate = CrateMap.GetHashCode(); var hashMove = MoveMap.GetHashCode(); #if NET47 hash = hashCrate ^ (hashMove << (MoveMap.Width / 2)); #else hash = HashCode.Combine(hashCrate, hashMove); #endif } }
public RenderingTexture(ImageC image, VectorInt2 from, VectorInt2 to) { Image = image; From = from; To = to; Tag = null; }
public static Bitmap Fill(IBitmap contraints, VectorInt2 p) { var result = new Bitmap(contraints.Size); FillCell(contraints, result, p); return result; }
public RenderingTexture(ImageC image) { Image = image; From = new VectorInt2(); To = image.Size; Tag = null; }
public static Bitmap Fill(IBitmap contraints, VectorInt2 p) { var result = new Bitmap(contraints.Size); FillCell(contraints, result, p); return(result); }
} // in 1/10ths public void Step(IRenderer <ConsolePixel> render, float time) { var p = new VectorInt2(Position); var next = Position + Speed * time; var i = new VectorInt2(next); if (i == p) { Position = next; return; } if (i.X != p.X) { if (i.X < 0 || i.X > render.Width || render[i].Char != ' ') { Speed = Speed * new Vector2(-1f, 1f); } } if (i.Y != p.Y) { if (i.Y < 0 || i.Y > render.Height || render[i].Char != ' ') { Speed = Speed * new Vector2(1f, -1f); } } Position = Position + Speed * time; }
private VectorInt3?AllocateTexture(RenderingTexture texture) { if (texture.To.X < texture.From.X || texture.To.Y < texture.From.Y) { throw new ArgumentOutOfRangeException(); // Avoid totally currupted texture allocator state. } for (int i = 0; i < Pages.Length; ++i) { VectorInt2?allocatedPos = Pages[i].Packer.TryAdd(VectorInt2.Max((texture.To - texture.From) + new VectorInt2(2), VectorInt2.One)); if (allocatedPos != null) { VectorInt3 pos = new VectorInt3(allocatedPos.Value.X, allocatedPos.Value.Y, i); if (texture.To.X == texture.From.X || texture.To.Y == texture.From.Y) { UploadTexture(ImageC.CreateNew(1, 1), pos); // Attempt to handle this situation } else { UploadTexture(texture, pos); } AvailableTextures.Add(texture, pos + new VectorInt3(1, 1, 0)); return(pos + new VectorInt3(1, 1, 0)); } } return(null); }
protected RenderTexture GetTemporaryRT(Material material, int ID_t, VectorInt2 rtSize, int rtDepth, RenderTextureFormat rtFormat, FilterMode rtFilterMode = FilterMode.Point, RenderTextureReadWrite rtReadWrite = RenderTextureReadWrite.Default) { var rt = GetTemporaryRT(material, ID_t, rtSize, rtDepth, rtFormat, rtFilterMode, rtReadWrite); material.SetTexture(ID_t, rt); return(rt); }
protected PointF ToVisualCoord(VectorInt2 sectorCoord) { RectangleF roomArea = GetVisualAreaRoom(); float gridStep = GetGridStep(); return(new PointF(sectorCoord.X * gridStep + roomArea.X, roomArea.Bottom - (sectorCoord.Y + 1) * gridStep)); }
virtual internal void PreRender(Camera camera, VectorInt2 cameraSize) { if (isRenderTextureDirty > 0) { if (isRenderTextureDirty == 1 || (isRenderTextureDirty == 2 && isFresh)) { // circumvents a bug in unity with the _CameraMotionVectorsTexture. complicated explanation: // When the viewport size changes, the _CameraMotionVectorsTexture gets messed up; unless two frames after a new RenderTexture (wtf, unity???) gets created. // +-------------------------------+-------------------------------+-------------------------------+ // | frame 0 ; OnPostRender | frame 1 ; OnPostRender | frame 2 ; OnPostRender | // | ; detect Size change | ; | create new RT ; | This DOES fix it. // +-------------------------------+-------------------------------+-------------------------------+ RenewAllRenderTextures(camera, cameraSize); } isRenderTextureDirty = Math.Max(0, isRenderTextureDirty - 1); } UpdateMaterialPerFrame(material, camera, cameraSize); if (isMaterialDirty) { isMaterialDirty = false; UpdateMaterial(material, camera, cameraSize); } isFresh = false; }
protected RenderTexture GetTemporaryRT(int ID_t, VectorInt2 rtSize, int rtDepth, RenderTextureFormat rtFormat, FilterMode rtFilterMode = FilterMode.Point, RenderTextureReadWrite rtReadWrite = RenderTextureReadWrite.Default) { var rt = RenderTexture.GetTemporary(rtSize.x, rtSize.y, rtDepth, rtFormat, rtReadWrite); rt.filterMode = rtFilterMode; return(rt); }
protected void CreateRT(RenderTextureContainer rtc, VectorInt2 rtSize, int rtDepth, bool rtUseMipMap, RenderTextureFormat rtFormat, FilterMode rtFilterMode = FilterMode.Point, RenderTextureReadWrite rtReadWrite = RenderTextureReadWrite.Default, TextureWrapMode rtWrapMode = TextureWrapMode.Clamp, string rtName = "RenderTexture") { RenderTexture rt = rtc; if (rt == null || // if at least one difference, release old texture and create a new one: rtSize != new VectorInt2(rt.width, rt.height) || rtDepth != rt.depth || rtUseMipMap != rt.useMipMap || rtFormat != rt.format || rtFilterMode != rt.filterMode // || rtReadWrite != (rt.sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear) || rtWrapMode != rt.wrapMode || rtName != rt.name || false ) { // if at least one difference, release old texture and create a new one: // if (rt != null && rt.IsCreated()) { // rt.Release(); // } rtc.setRT(new RenderTexture(Math.Max(1, rtSize.x), Math.Max(1, rtSize.y), rtDepth, rtFormat, rtReadWrite) { filterMode = rtFilterMode, wrapMode = rtWrapMode, useMipMap = rtUseMipMap, autoGenerateMips = false, antiAliasing = 1, name = rtName }); } m_OldRenderTextures.Remove(rtc); m_RenderTextures.Add(rtc); }
protected void CreateCopyRT(RenderTextureContainer rtc, VectorInt2 rtSize, int rtDepth, bool rtUseMipMap, RenderTextureFormat rtFormat, FilterMode rtFilterMode = FilterMode.Point, RenderTextureReadWrite rtReadWrite = RenderTextureReadWrite.Default, TextureWrapMode rtWrapMode = TextureWrapMode.Clamp, string rtName = "RenderTexture") { RenderTexture tempRT = null; try { RenderTexture rt = rtc; var hasPreviousRT = rt != null && rt.IsCreated(); if (hasPreviousRT) { var tempRTReadWrite = rt.sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear; tempRT = RenderTexture.GetTemporary(rt.width, rt.height, rt.depth, rt.format, tempRTReadWrite, rt.antiAliasing); tempRT.filterMode = rt.filterMode; Graphics.Blit(rtc, tempRT); } CreateRT(rtc, rtSize, rtDepth, rtUseMipMap, rtFormat, rtFilterMode, rtReadWrite, rtWrapMode, rtName); if (hasPreviousRT) { Graphics.Blit(tempRT, rtc); } } finally { if (tempRT != null) { RenderTexture.ReleaseTemporary(tempRT); } } }
override protected void UpdateMaterial(Material material, Camera camera, VectorInt2 cameraSize) { var settings = this.settings; var isSceneView = postProcessingManager.isSceneView; // Shader.EnableKeyword("CAT_SSR_ON"); if (settings.useTemporalSampling) { material.EnableKeyword("CAT_TEMPORAL_SSR_ON"); } else { material.DisableKeyword("CAT_TEMPORAL_SSR_ON"); } material.SetTexture(PropertyIDs.Refl_t, history); material.SetFloat(PropertyIDs.MaxReflectionDistance_f, settings.maxReflectionDistance); material.SetInt(PropertyIDs.StepCount_i, settings.stepCount); // isExactPixelStride var maxStride = Settings.isExactPixelStride ? settings.minPixelStride : settings.maxPixelStride; var minPixelStride = Math.Min(settings.minPixelStride, maxStride); var maxPixelStride = Math.Max(settings.minPixelStride, maxStride); material.SetFloat(PropertyIDs.MinPixelStride_i, minPixelStride); material.SetFloat(PropertyIDs.MaxPixelStride_i, maxPixelStride); material.SetFloat(PropertyIDs.NoiseStrength_f, Settings.noiseStrength); material.SetFloat(PropertyIDs.CullBackFaces_b, settings.cullBackFaces ? 1 : 0); // rayTraceResol // upSampleHitTexture material.SetInt(PropertyIDs.UseRetroReflections_b, settings.useRetroReflections ? 1 : 0); material.SetFloat(PropertyIDs.Intensity_f, settings.intensity); material.SetFloat(PropertyIDs.ReflectionDistanceFade_f, settings.reflectionDistanceFade); material.SetFloat(PropertyIDs.RayLengthFade_f, settings.rayLengthFade); material.SetFloat(PropertyIDs.EdgeFade_f, settings.edgeFade); material.SetFloat(PropertyIDs.UseReflectionMipMap_b, settings.useReflectionMipMap ? 1 : 0); // reflectionResolution // useImportanceSampling material.SetInt(PropertyIDs.ResolveSampleCount_i, settings.resolveSampleCount); material.SetFloat(PropertyIDs.ImportanceSampleBias_f, settings.importanceSampleBias); material.SetFloat(PropertyIDs.UseCameraMipMap_b, settings.useCameraMipMap ? 1 : 0); // suppressFlickering // useTemporalSampling material.SetFloat(PropertyIDs.Response_f, settings.response); material.SetFloat(PropertyIDs.ToleranceMargin_f, settings.toleranceMargin); // debugOn material.SetInt(PropertyIDs.DebugMode_i, (int)settings.debugMode); material.SetInt(PropertyIDs.MipLevelForDebug_i, settings.mipLevelForDebug); material.SetTexture(PropertyIDs.blueNoise_t, PostProcessingManager.blueNoiseTexture); var allowVelocityPrediction = true && !isSceneView; material.SetInt(PropertyIDs.IsVelocityPredictionEnabled_b, allowVelocityPrediction ? 1 : 0); }
public override VectorInt2?TryAdd(VectorInt2 size) { if (_currentY + size.Y > Size.Y) { return(null); } if (_currentX + size.X > Size.X) { // Does not fit in that row, but maybe in a new row if (size.X > Size.X) { return(null); } if (_currentY + _stackHeight + size.Y > Size.Y) { return(null); } _currentX = 0; _currentY = _currentY + _stackHeight; _stackHeight = 0; } // Pack and adjust coordinates VectorInt2 result = new VectorInt2(_currentX, _currentY); _stackHeight = Math.Max(_stackHeight, size.Y); _currentX += size.X; return(result); }
public void TwoRooms() { var bountry = Bitmap.Create(new[] { "#########", "# ######", "# ### #", "###### #", "#########" }, x => x == ' '); var expected = Bitmap.Create(new[] { "#########", "#oo######", "#oo### #", "###### #", "#########" }, x => x == 'O'); var start = new VectorInt2(1, 1); var result = FloodFill.Fill(bountry, start); Assert.Equal(expected, result); }
protected virtual void MoveCrate(Map newState, VectorInt2 pp, VectorInt2 ppp) { Statistics.Pushes++; newState.UnSetFlag(Block.Crate, pp); newState.SetFlag(Block.Crate, ppp); }
public Entry Lookup(VectorInt3 pos) { int mapX = pos.X / _mapGranularity; int mapY = pos.Y / _mapGranularity; if (mapX < 0 || mapY < 0 || mapX >= _map.GetLength(2) || mapY >= _map.GetLength(1)) { return(null); } List <Entry> candidates = _map[pos.Z, mapY, mapX]; foreach (Entry candidate in candidates) { if ((pos.X >= candidate.Pos.X) && (pos.Y >= candidate.Pos.Y)) { VectorInt2 size = candidate.Texture.To - candidate.Texture.From; if ((pos.X < (candidate.Pos.X + size.X)) && (pos.Y < (candidate.Pos.Y + size.Y))) { return(candidate); } } } return(null); }
protected virtual void MovePlayer(Map newState, VectorInt2 p, VectorInt2 pp) { Statistics.Steps++; newState.UnSetFlag(Block.Player, p); newState.SetFlag(Block.Player, pp); }
private bool Collision(IRenderer <ConsolePixel> render, Vector2 next) { if (next.X < 0 || next.X > render.Width) { return(true); } if (next.Y < 0 || next.Y > render.Height) { return(true); } var p = new VectorInt2(Position); var i = new VectorInt2(next); if (p == i) { return(false); } if (render[i].Char != ' ') { return(true); } return(false); }
public CartesianMap(int width, int height) { Width = width; Height = height; Size = new VectorInt2(width, height); inner = new T[width, height]; }
public SolverNode CreateFromPull( SolverNode parent, IBitmap nodeCrateMap, IBitmap walls, VectorInt2 pc, VectorInt2 p, VectorInt2 pp) { if (TryGetPooledInstance(out var fromPool)) { var eCrate = fromPool.CrateMap; var eMove = fromPool.MoveMap; eMove.Fill(false); // Reuse the nodes, resetting the values eCrate.Set(nodeCrateMap); eCrate[pc] = false; eCrate[p] = true; SolverHelper.FloodFillUsingWallAndCratesInline(walls, eCrate, pp, eMove); fromPool.InitialiseInstance(parent, p, pp - p, eCrate, eMove, true); return(fromPool); } var newCrate = CreateBitmap(nodeCrateMap); newCrate[pc] = false; newCrate[p] = true; var newMove = CreateBitmap(nodeCrateMap.Size); SolverHelper.FloodFillUsingWallAndCratesInline(walls, newCrate, pp, newMove); return(CreateInstance(parent, p, pp - p, newCrate, newMove)); }
public int Compare(Map.Entry first, Map.Entry second) { VectorInt2 firstSize = first.Texture.To - first.Texture.From; VectorInt2 secondSize = second.Texture.To - second.Texture.From; // Return 0 if sizes are completely equal if (firstSize == secondSize) { return(0); } // Compare height if (firstSize.Y != secondSize.Y) { return(firstSize.Y > secondSize.Y ? -1 : 1); // Higher textures first! } // Compare area int firstArea = firstSize.X * firstSize.Y; int secondArea = secondSize.X * secondSize.Y; if (firstArea != secondArea) { return(firstArea > secondArea ? -1 : 1); // Bigger textures first! } return(0); }
public Path?FindPlayerWalkRoute(VectorInt2 pos) { if (!CrateMap[pos]) { return(null); } var match = Root.FirstOrDefault(x => x.CrateTarget == pos); if (match == null) { throw new InvalidDataException(); } var res = new Path(); foreach (var pair in GeneralHelper.OffsetWalk(match.PathToRoot())) { // Path from old to new positions var walk = PathFinder.Find(pair.Item1.Maps.MoveMap.Invert(), pair.Item1.PlayerAfter, pair.Item2.PlayerBefore); res.AddRange(walk); res.Add(pair.Item2.PlayerAfter - pair.Item2.PlayerBefore); } return(res); }
public Map(RenderingTextureAllocator Allocator) { // Create map _map = new List <Entry> [Allocator.Size.Z, Allocator.Size.Y / _mapGranularity, Allocator.Size.X / _mapGranularity]; for (int z = 0; z < _map.GetLength(0); ++z) { for (int y = 0; y < _map.GetLength(1); ++y) { for (int x = 0; x < _map.GetLength(2); ++x) { _map[z, y, x] = new List <Entry>(); } } } // Fill map foreach (KeyValuePair <RenderingTexture, VectorInt3> availableTexture in Allocator.AvailableTextures) { Entry @ref = new Entry(availableTexture); VectorInt2 startPixel = new VectorInt2(availableTexture.Value.X, availableTexture.Value.Y); VectorInt2 endPixel = startPixel + (availableTexture.Key.To - availableTexture.Key.From); VectorInt2 startBlock = startPixel / _mapGranularity; VectorInt2 endBlock = (endPixel + new VectorInt2(_mapGranularity - 1, _mapGranularity - 1)) / _mapGranularity; for (int x = startBlock.X; x < endBlock.X; ++x) { for (int y = startBlock.Y; y < endBlock.Y; ++y) { _map[availableTexture.Value.Z, y, x].Add(@ref); } } } }
private VectorInt2 GetDragDropOffset(DragEventArgs drgevent) { var newPos = FromVisualCoord(PointToClient(new Point(drgevent.X, drgevent.Y))); var result = newPos - _insertionDropPosition; return(VectorInt2.FromRounded(result)); }
public static Bitmap Fill(BitmapSpan contraints, VectorInt2 p) { var result = new Bitmap(contraints.Size); Fill(contraints, p, result); return(result); }
private static void FillCell(IBitmap contraints, IBitmap result, VectorInt2 p) { if (p.X < 0 || p.Y < 0) { return; } if (p.X > contraints.Size.X || p.Y > contraints.Size.Y) { return; } if (contraints[p]) { return; } if (result[p]) { return; } result[p] = true; FillCell(contraints, result, p + VectorInt2.Up); FillCell(contraints, result, p + VectorInt2.Down); FillCell(contraints, result, p + VectorInt2.Left); FillCell(contraints, result, p + VectorInt2.Right); }
public void LookAtPos (VectorInt2 pos, EventDelegate.Callback callback) { tween.from = mapRoot.localPosition; tween.to = new Vector3 (-pos.X * tileSize + Screen.width / 2 - tileSize / 2, -pos.Y * tileSize + Screen.height / 2 - tileSize / 2); EventDelegate.Add (tween.onFinished, callback, true); tween.ResetToBeginning (); tween.PlayForward (); }
public void Drop(VectorInt2 cell) { var action = Peek(cell); try { if (action == Action.Push) { var dir = cell - Game.Current.Player.Position; if (dir.IsUnit) // Next to each other { Game.Move(dir); } } else if (action == Action.Move) { start = Game.Current.Player.Position; var end = cell; var boundry = Game.Current.ToMap(Game.Current.Definition.Wall, Game.Current.Definition.Crate, Game.Current.Definition.CrateGoal); var path = PathFinder.Find(boundry, start, end); if (path != null) { foreach (var step in path) { Game.Move(step); } } } else if (action == Action.Drag) { var end = cell; var state = Game.Analysis.Evalute(Game.Current); var pushMap = PushMap.Find(state.Static, state.Current, start, Game.Current.Player.Position); if (pushMap.CrateMap[end]) { // Do Moves var path = pushMap.FindPlayerWalkRoute(end); if (path != null) { foreach (var c in path) { Game.Move(c); } } } } } finally { // Finally isDragInProgress = false; start = VectorInt2.MinValue; } }
public virtual MoveResult Move(VectorInt2 direction) { if (direction != VectorInt2.Up && direction != VectorInt2.Down && direction != VectorInt2.Left && direction != VectorInt2.Right) { throw new Exception("Must be U,D,L,R"); } var p = Current.Player.Position; var pp = p + direction; var ppp = pp + direction; // Valid? if (!Current.Area.Contains(pp)) return MoveResult.Invalid; if (!Current.Area.Contains(ppp)) return MoveResult.Invalid; // Move/Step if (Current.Definition.IsEmpty(Current[pp])) { var newState = new Puzzle(Current); // Move away MovePlayer(newState, p, pp); UpdateState(newState); return MoveResult.Ok; } // Push if (Current.Definition.IsCrate(Current[pp])) { if (!Current.Definition.IsEmpty(Current[ppp])) { return MoveResult.Invalid; } var newState = new Puzzle(Current); MoveCrate(newState, pp, ppp); MovePlayer(newState, p, pp); UpdateState(newState); if (newState.IsSolved) { return MoveResult.Win; } return MoveResult.Ok; } return MoveResult.Invalid; }
private static void FillCell(IBitmap contraints, IBitmap result, VectorInt2 p) { if (p.X < 0 || p.Y < 0) return; if (p.X > contraints.Size.X || p.Y > contraints.Size.Y) return; if (contraints[p]) return; if (result[p]) return; result[p] = true; FillCell(contraints, result, p + VectorInt2.Up); FillCell(contraints, result, p + VectorInt2.Down); FillCell(contraints, result, p + VectorInt2.Left); FillCell(contraints, result, p + VectorInt2.Right); }
public void Sample() { var bountry = Bitmap.Create(new string[] { "~~~###~~~~~", "~~## #~####", "~## ### #", "## X #", "# X # #", "### X### #", "~~# # #", "~## ## # ##", "~# ##~", "~# ##~~", "~#######~~~", }); var expected = Bitmap.Create(new string[] { "~~~###~~~~~", "~~## #~####", "~## ### #", "## X #", "# X # #", "### X### #", "~~# # #", "~## ## # ##", "~# ##~", "~# ##~~", "~#######~~~", }, x=>x == ' '); var start = new VectorInt2(4 ,4); var result = FloodFill.Fill(bountry, start); Assert.That(result, Is.EqualTo(expected)); }
public List<GameElement> ElementsAt(VectorInt2 p) { return RootElements.FindAll(x => x.Position.Equals(p)); }
public GameElement ElementAt(VectorInt2 p, char type) { var all = ElementsAt(p); return all.FirstOrDefault(x => x.Type == type); }
protected virtual void MoveCrate(Puzzle newState, VectorInt2 pp, VectorInt2 ppp) { Statistics.Pushes++; if (newState[pp] == newState.Definition.Crate) { newState[pp] = newState.Definition.Floor; } else if (newState[pp] == newState.Definition.CrateGoal) { newState[pp] = newState.Definition.Goal; } // Move to if (newState[ppp] == newState.Definition.Floor) { newState[ppp] = newState.Definition.Crate; } else if (newState[ppp] == newState.Definition.Goal) { newState[ppp] = newState.Definition.CrateGoal; } }
protected virtual void MovePlayer(Puzzle newState, VectorInt2 p, VectorInt2 pp) { Statistics.Steps++; MoveStack.Push(pp); if (newState[p] == newState.Definition.Player) { newState[p] = newState.Definition.Floor; } else if (newState[p] == newState.Definition.PlayerGoal) { newState[p] = newState.Definition.Goal; } // Move to if (newState[pp] == newState.Definition.Floor) { newState[pp] = newState.Definition.Player; } else if (newState[pp] == newState.Definition.Goal) { newState[pp] = newState.Definition.PlayerGoal; } }
protected override void MoveCrate(Puzzle newState, VectorInt2 pp, VectorInt2 ppp) { base.MoveCrate(newState, pp, ppp); // Move 'linked' RootElements var eCrate = ElementAt(pp, Current.Definition.Crate); eCrate.Move(ppp - pp); }
private void BackStep () { VectorInt2 prePos; do { leftSpeed++; movePath.RemoveAt (movePath.Count - 1); if (leftSpeed == allSpeed) { prePos = new VectorInt2 (x, y); break; } else { prePos = movePath [movePath.Count - 1]; } } while (GameWorld.Instance.Encounter.IsEmpty (prePos.X, prePos.Y)==false); GameWorld.Instance.gameMap.ShowStep (movePath); GameWorld.Instance.gameMap.LookAtPos (prePos, ShowMenuAndArea); }
public Action Peek(VectorInt2 currentMouseCell) { bool isDrag = start != VectorInt2.MinValue && start != currentMouseCell; bool singleClick = start == currentMouseCell; if (Game.Current.Contains(start)) { if (singleClick) { // Simple Push: Am I next to a crate if (Game.Current.Definition.IsCrate(Game.Current[currentMouseCell])) { var dir = currentMouseCell - Game.Current.Player.Position; if (dir.IsUnit) // Next { return Action.Push; } } // Just click on a floor cell if (Game.Current[currentMouseCell] == Game.Current.Definition.Floor || Game.Current[currentMouseCell] == Game.Current.Definition.Goal) { return Action.Move; } } if (isDrag) { // Crate drag: start dragging a crate, to a cell that is empty if (Game.Current.Definition.IsCrate(Game.Current[start])) { if (Game.Current.Definition.IsEmpty(Game.Current[currentMouseCell]) || currentMouseCell == Game.Current.Player.Position) { return Action.Drag; } } } // No clicks: Assume move if (currentMouseCell != Game.Current.Player.Position && (Game.Current[currentMouseCell] == Game.Current.Definition.Floor || Game.Current[currentMouseCell] == Game.Current.Definition.Goal)) { return Action.Move; } } return Action.None; }
public void Drag(VectorInt2 cell) { start = cell; isDragInProgress = true; }
public void UpdateMouseWithLogicalCell(VectorInt2 cell, bool isLeftDown, bool isRightDown) { if (!Game.Current.Contains(cell)) return; peekMovePath = null; peekCratePath = null; try { if (Game.HasPendingMoves) { // No hints while there are outstanding actions return; } if (isLeftDown && !prevLeftDown) { Drag(cell); return; } if (!isLeftDown && prevLeftDown) { Drop(cell); return; } var peek = Peek(cell); if (peek != Action.None) { if (peek == Action.Move) { start = Game.Current.Player.Position; var end = cell; var boundry = Game.Current.ToMap(Game.Current.Definition.Wall, Game.Current.Definition.Crate, Game.Current.Definition.CrateGoal); peekMovePath = PathFinder.Find(boundry, start, end); } else if (peek == Action.Drag) { var end = cell; var state = Game.Analysis.Evalute(Game.Current); var pushMap = PushMap.Find(state.Static, state.Current, start, Game.Current.Player.Position); if (pushMap.CrateMap[end]) { //var walk = pushMap.FindPlayerWalkRoute(end); peekCratePath = pushMap.FindCrateRoute(end); // PLayer move to begin crate stuff var pstart = Game.Current.Player.Position; var pend = start - peekCratePath.First(); var boundry = Game.Current.ToMap(Game.Current.Definition.Wall, Game.Current.Definition.Crate, Game.Current.Definition.CrateGoal); peekMovePath = PathFinder.Find(boundry, pstart, pend); if (peekMovePath != null) { peekMovePath.Add(peekCratePath.First()); } } } } } finally { prev = cell; prevLeftDown = isLeftDown; prevRightDown = isRightDown; } }
public void TwoRooms() { var bountry = Bitmap.Create(new string[] { "#########", "# ######", "# ### #", "###### #", "#########" }, x=> x == ' ' ); var expected = Bitmap.Create(new string[] { "#########", "#oo######", "#oo### #", "###### #", "#########" }, x => x == 'O'); var start = new VectorInt2(1, 1); var result = FloodFill.Fill(bountry, start); Assert.That(result, Is.EqualTo(expected)); }
private bool CheckDeadReverse(SolverCommandResult state, VectorInt2 ppp) { return false; return state.StaticMaps.DeadMap[ppp]; }
protected override void MovePlayer(Puzzle newState, VectorInt2 p, VectorInt2 pp) { base.MovePlayer(newState, p, pp); // Move 'linked' RootElements var ePlayer = ElementAt(p, Current.Definition.Player); ePlayer.Move(pp - p); }
public void MoveTileOnClick (GameObject mapTile) { MoveTile tile = mapTile.GetComponent<MoveTile> (); int speedCost = Mathf.Max (Mathf.Abs (tile.deltaX), Mathf.Abs (tile.deltaY)); leftSpeed -= speedCost; // make path int speedX = 0; if (tile.deltaX != 0) { speedX = tile.deltaX / Mathf.Abs (tile.deltaX); } int speedY = 0; if (tile.deltaY != 0) { speedY = tile.deltaY / Mathf.Abs (tile.deltaY); } for (int i = 1; i <= speedCost; i++) { int posX = speedX * i; if (Mathf.Abs (posX) > Mathf.Abs (tile.deltaX)) { posX = tile.deltaX; } int posY = speedY * i; if (Mathf.Abs (posY) > Mathf.Abs (tile.deltaY)) { posY = tile.deltaY; } VectorInt2 newPos = new VectorInt2 (tile.x + posX, tile.y + posY); movePath.Add (newPos); } GameWorld.Instance.gameMap.ShowStep (movePath); GameWorld.Instance.gameMap.LookAtPos (movePath [movePath.Count - 1], delegate { ShowMenuAndArea (); }); }
public LineBitmap(VectorInt2 aSize) : base(aSize) { }
public void Move(VectorInt2 dir) { PositionOld = Position; Position = Position + dir; }