public void UpdateArea() { AreaMultiplier = 1; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { foreach (var Entity in UpdateWorld.Chunks [(ChunkPos.X + i + UpdateWorld.ChunkAmount) % UpdateWorld.ChunkAmount] [(ChunkPos.Y + j + UpdateWorld.ChunkAmount) % UpdateWorld.ChunkAmount].Entities) { { if (Entity is Tree T && Entity != this) { float dist = UpdateWorld.GetRelativePosition(this, T).Mag(); if (dist < T.EnergyRadius + EnergyRadius && T.EnergyRadius > 0)//if their energy circles are touching { float A = GetCoveredArea(EnergyRadius, T.EnergyRadius, dist); float M1 = 1 - (A / ((float)Math.PI * (EnergyRadius * EnergyRadius))) / 2; AreaMultiplier *= M1; float M2 = 1 - (A / ((float)Math.PI * (T.EnergyRadius * T.EnergyRadius))) / 2; T.AreaMultiplier *= M2; NearbyTrees.Add(T, M1); T.NearbyTrees.Add(this, M2); } } } } } } }
void MouseRelease(MouseButtons B) { if (!(Draw.MousePress() || FileHandler.MousePress() || Draw.SelectedFamily)) { Draw.ScreenToWorld(MousePos.X, MousePos.Y, out Vector V, out VectorI Chunk); Draw.Selected = UpdateWorld.Entities.OfType <SelectableObject>().ToList().Find( x => { Vector RelPos = UpdateWorld.GetRelativePosition(x.ChunkPos, x.Pos, Chunk, V); if (x is Tree T) { if (T.PointOnTree(RelPos)) { return(true); } } return(RelPos.MagSq() < x.Radius * x.Radius * 4); }); ManualControl = false; //Draw.Selected = Creatures.Find(x => (x.Pos - WorldPos).MagSq() < (x.Radius * x.Radius) * 4); //if (Draw.Selected == null) //Draw.Selected = Trees.Find(x => x.PointOnTree(WorldPos)); //Draw.SelectedCreature = Draw.Selected as Creature; //Draw.SelectedTree = Draw.Selected as Tree; //ManualControl = false; } }
public PointF WorldToScreen(VectorI Chunk, Vector Pos) { Vector V = UpdateWorld.GetRelativePosition(CameraChunk, CameraPos2, Chunk, Pos) * Zoom; return(new PointF(V.X, V.Y)); }