public void DisplayPart(Position Pos, int Width, int Height) { RebuildDisplayGrid(Pos, Width, Height); for (int y = Height - 1; y >= 0; y--) { for (int x = 0; x < Width; x++) { Console.ForegroundColor = display[x, y].color; Console.Write(display[x, y].sign); } Console.Write("\n"); } }
public IUsable GetUsableOnPos(Position Pos) { foreach(GameObject go in activeObjects) { if (go.Position == Pos) { IUsable ius = go as IUsable; if (ius != null) { return ius; } } } return null; }
//Supply a list of grids and it will create BeamObjects that stay in the same position in the world across all selected grids public MultiDimensionalBeam(List<Grid> Grids, Position WorldPosition, int Count, int Radius) { int offset = Radius; pos = WorldPosition; grids = Grids; Random rnd = new Random(); for (int i = 0; i < Count; i++) { int dis = rnd.Next(offset); double rnddeg = rnd.Next(3600) / 10d; double tx = (dis * Math.Cos(rnddeg)) - (dis * Math.Sin(rnddeg)); double ty = (dis * Math.Sin(rnddeg)) + (dis * Math.Cos(rnddeg)); foreach (Grid g in grids) { Position temppos = new Position((int) Math.Round(tx), (int) Math.Round(ty)); BeamObject b = GameObject.Instantiate<BeamObject>(pos, g); b.worldPos = g.worldPosition; b.Offset = temppos; beams.Add(b); } } }
private void RebuildObjects(Position Pos, int Width, int Height) { //Ceiling all the ranges for the sake of consistency Width = (int)Math.Ceiling(Width / 2.0); Height = (int)Math.Ceiling(Height / 2.0); lastCheckPosition = Pos; visibleObjects.Clear(); //This rebuilds the entire active objects list in one pass. //If there is only 1 active object and this is being called (this happens when you move the player to a grid, as all active objects //get deactivated when you move off a grid) then rebuild the entire thing immediately. //Alternatively if the player has moved too far from their previous position AND the batch updating hasn't finished yet, do it all //in one go instead. Lags a bit more but avoids a pop-in effect of gameobjects being reactivated on screen. if (activeObjects.Count <= 1 || Position.Distance(Pos, lastObjectCheckPos) > fullRecheckActiveObjectsdistance) { foreach (GameObject go in activeObjects) go.Active = false; activeObjects.Clear(); lastObjectCheckPos = Pos; BatchObjects.Clear(); CurrentBatchRebuild = 0; BatchComplete = false; foreach (GameObject go in gameObjects) { if (IsInActiveRange(go.Position, Pos)) { activeObjects.Add(go); go.Active = true; if (IsInVisibleRange(go.Position, Pos, Width, Height)) { visibleObjects.Add(go); } } } } else if (Position.Distance(Pos, lastObjectCheckPos) > recheckActiveObjectsDistance) { for (int i = 0; i <= BatchSize; i++) { if (i+CurrentBatchRebuild >= gameObjects.Count) { BatchComplete = true; break; } if (gameObjects[i+CurrentBatchRebuild] != null) { if (IsInActiveRange(gameObjects[i+CurrentBatchRebuild].Position, Pos)) { BatchObjects.Add(gameObjects[i+CurrentBatchRebuild]); } } if (i >= BatchSize) { CurrentBatchRebuild = i + CurrentBatchRebuild; } } if (BatchComplete) { activeObjects.Clear(); foreach (GameObject go in BatchObjects) activeObjects.Add(go); lastObjectCheckPos = Pos; BatchObjects.Clear(); CurrentBatchRebuild = 0; BatchComplete = false; } foreach (GameObject go in activeObjects) if (IsInVisibleRange(go.Position, Pos, Width, Height)) visibleObjects.Add(go); } else { foreach (GameObject go in activeObjects) { if (IsInVisibleRange(go.Position, Pos, Width, Height)) { visibleObjects.Add(go); } } } }
private bool IsInVisibleRange(Position ObjectPos, Position Pos, int Width, int Height) { if (ObjectPos.x < Pos.x + Width && ObjectPos.x > Pos.x - Width && ObjectPos.y < Pos.y + Height && ObjectPos.y > Pos.y - Height) return true; else return false; }
private bool IsInActiveRange(Position ObjectPos, Position Pos) { if (Position.Distance(ObjectPos, Pos) < maxActiveDistance) return true; else return false; }
private Sign GetCharAtVisiblePoint(Position Pos) { Sign ret; IEnumerable<GameObject> objectlist = from o in visibleObjects where o.Position == Pos select o; if (objectlist.Any()) { IEnumerable<GameObject> sortvisible = from o in objectlist where o.enterable == false select o; if (sortvisible.Any()) { ret = sortvisible.First().sign; } else { ret = objectlist.First().sign; } } else if (IsPointOnGrid(Pos)) { ret = ground[Pos.x, Pos.y].sign; } else { ret.sign = outofboundschar; ret.color = ConsoleColor.DarkGreen; } return ret; }
public void RebuildDisplayGrid(Position Pos, int Width, int Height) { RebuildObjects(Pos, Width, Height); display = new Sign[Width, Height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { display[x,y] = GetCharAtVisiblePoint(new Position( (Pos.x - (int) Math.Floor(Width / 2.0)) + x, (Pos.y - (int) Math.Floor(Height / 2.0)) + y)); } } }
public bool PosIsAvailable(Position Pos, bool AllObjects) { if (IsPointOnGrid(Pos)) { if (ground[Pos.x, Pos.y].enterable) { foreach(GameObject go in (AllObjects ? gameObjects : activeObjects)) { if (go.Position == Pos && go.enterable == false) return false; } return true; } else return false; } else return false; }
public bool IsPointOnGrid(Position Pos) { if (Pos.x < width && Pos.x >= 0 && Pos.y < height && Pos.y >= 0) return true; else return false; }
public static int Distance(Position Pos1, Position Pos2) { return Math.Abs(Pos1.x - Pos2.x) + Math.Abs(Pos1.y - Pos2.y); }
private void RebuildObjects(Position Pos, int Width, int Height) { Width = (int)Math.Ceiling(Width / 2.0); Height = (int)Math.Ceiling(Height / 2.0); visibleObjects.Clear(); if (activeObjects.Count <= 1 || Position.Distance(Pos, lastObjectCheckPos) > fullRecheckActiveObjectsdistance) { foreach (GameObject go in activeObjects) go.active = false; activeObjects.Clear(); lastObjectCheckPos = Pos; BatchObjects.Clear(); CurrentBatchRebuild = 0; BatchComplete = false; foreach (GameObject go in gameObjects) { if (IsInActiveRange(go.position, Pos)) { activeObjects.Add(go); go.active = true; if (IsInVisibleRange(go.position, Pos, Width, Height)) { visibleObjects.Add(go); } } } } else if (Position.Distance(Pos, lastObjectCheckPos) > recheckActiveObjectsDistance) { for (int i = 0; i <= BatchSize; i++) { if (i+CurrentBatchRebuild >= gameObjects.Count) { BatchComplete = true; break; } if (gameObjects[i+CurrentBatchRebuild] != null) { if (IsInActiveRange(gameObjects[i+CurrentBatchRebuild].position, Pos)) { BatchObjects.Add(gameObjects[i+CurrentBatchRebuild]); } } if (i >= BatchSize) { CurrentBatchRebuild = i + CurrentBatchRebuild; } } if (BatchComplete) { activeObjects.Clear(); foreach (GameObject go in BatchObjects) activeObjects.Add(go); lastObjectCheckPos = Pos; BatchObjects.Clear(); CurrentBatchRebuild = 0; BatchComplete = false; } foreach (GameObject go in activeObjects) if (IsInVisibleRange(go.position, Pos, Width, Height)) visibleObjects.Add(go); } else { foreach (GameObject go in activeObjects) { if (IsInVisibleRange(go.position, Pos, Width, Height)) { visibleObjects.Add(go); } } } }