public void setPathGoal(PathGoal pathGoal) { this.pathGoal = pathGoal; pathGoal.updatePath(); List<Entity> entities = pathGoal.getEntities(); foreach (Entity entity in entities) { entity.GetComponent<component.Unit>().pathGoal = pathGoal; } }
public void update() { MouseState mouseState; if (entitiesInSelection.Count > 0) { if (inputState.IsNewRightMouseClick(out mouseState)) { if (Global.Viewport.Contains(mouseState.Position)) { Vector2 pos = Global.Camera.ScreenToWorld(mouseState.Position.ToVector2()); //Bag<Entity> entities = entityWorld.EntityManager.GetEntities(Aspect.All(typeof(component.Goal), typeof(component.Physics), typeof(component.Formation))); int2 goalPos = new int2((int)pos.X / Global.tileSize, (int)pos.Y / Global.tileSize); Bag<Entity> bag = new Bag<Entity>(); PathGoal pathGoal = new PathGoal(entitiesInSelection, disFieldMixer, new int2(Global.mapWidth, Global.mapHeight), goalPos); setPathGoal(pathGoal); pathGoal.updatePath(); EntityFormation formation = new EntityFormation(entitiesInSelection, disFieldMixer, goalPos); foreach (Entity e in entitiesInSelection) { e.GetComponent<component.Formation>().EntityFormation = formation; } formation.update(); } } } if (Mouse.GetState().LeftButton == ButtonState.Pressed && !isSelecting) { isSelecting = true; firstCorner = Global.Camera.ScreenToWorld(Mouse.GetState().Position.ToVector2()); foreach (Entity old in entitiesInSelection) { old.GetComponent<component.HealthComponent>().Visible = false; } entitiesInSelection.Clear(); } else if (Mouse.GetState().LeftButton == ButtonState.Released && isSelecting) { isSelecting = false; Vector2 secondCorner = Global.Camera.ScreenToWorld(Mouse.GetState().Position.ToVector2()); Vector2 topLeft = new Vector2(Math.Min(firstCorner.X, secondCorner.X), Math.Min(firstCorner.Y, secondCorner.Y)); Vector2 bottomRight = new Vector2(Math.Max(firstCorner.X, secondCorner.X), Math.Max(firstCorner.Y, secondCorner.Y)); RectangleF rect = new RectangleF(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); Console.WriteLine(rect.X / 32 + " - " + rect.Y / 32); if (rect.Width > 0 && rect.Height > 0) { Bag<Entity> entities = entityWorld.EntityManager.GetEntities(Aspect.All(typeof(component.Physics), typeof(component.Formation), typeof(component.HealthComponent), typeof(component.Unit))); foreach (Entity e in entities) { if (e.GetComponent<component.Unit>().Lord != lord) continue; component.Physics phys = e.GetComponent<component.Physics>(); Vector2 newPos = new Vector2(phys.Position.X * Global.tileSize, phys.Position.Y * Global.tileSize); RectangleF entityRect = new RectangleF(newPos.X - 0.5f * 32f, newPos.Y - 0.5f * 32f, 1f * 32f, 1f * 32f); if (rect.IntersectsWith(entityRect)) { e.GetComponent<component.HealthComponent>().Visible = true; entitiesInSelection.Add(e); } } if (onSelectUnit != null) onSelectUnit(); } } if (isSelecting) { Vector2 secondCorner = Global.Camera.ScreenToWorld(Mouse.GetState().Position.ToVector2()); Vector2 topLeft = new Vector2(Math.Min(firstCorner.X, secondCorner.X), Math.Min(firstCorner.Y, secondCorner.Y)); Vector2 bottomRight = new Vector2(Math.Max(firstCorner.X, secondCorner.X), Math.Max(firstCorner.Y, secondCorner.Y)); RectangleF rect = new RectangleF(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); foreach (Entity e in tempEntitiesInSelection) { e.GetComponent<component.HealthComponent>().Visible = false; } tempEntitiesInSelection.Clear(); if (rect.Width > 0 && rect.Height > 0) { Bag<Entity> entities = entityWorld.EntityManager.GetEntities(Aspect.All(typeof(component.Physics), typeof(component.Formation), typeof(component.HealthComponent))); foreach (Entity e in entities) { component.Physics phys = e.GetComponent<component.Physics>(); Vector2 newPos = new Vector2(phys.Position.X * Global.tileSize, phys.Position.Y * Global.tileSize); RectangleF entityRect = new RectangleF(newPos.X - 0.5f * 32f, newPos.Y - 0.5f * 32f, 1f * 32f, 1f * 32f); if (rect.IntersectsWith(entityRect)) { e.GetComponent<component.HealthComponent>().Visible = true; tempEntitiesInSelection.Add(e); } } } } }