public static Entity GetEntityAt(List<Entity> entities, Vector2f point) { Entity found = null; float depth = 0.0f; foreach (Entity entity in entities) { if (IsEntityAt(entity, point)) { if (entity.GetComponent<Position>() != null) { float newDepth = entity.GetComponent<Position>().depth; if (found == null) { depth = newDepth; found = entity; } else if (newDepth > depth) { depth = newDepth; found = entity; } } } } return found; }
public void SendMouseRelease(int button, Vector2f position) { foreach (IMouseListener listener in mouseListeners) { listener.Release(button, position); } }
public void SendMousePosition(Vector2f position) { foreach (IMouseListener listener in mouseListeners) { listener.Move(position); } }
public void SendMousePress(int button, Vector2f position) { foreach (IMouseListener listener in mouseListeners) { listener.Press(button, position); } }
private void Place(GameManager game, Entity selected, Vector2f position) { selected.GetComponent<Position>().position = position + offset; Entity system = EntityFinder.GetEntityAt(game.GetEntitiesWith<SystemType>(), position); if (system != null) { game.Rules.PlaceSelected(system.GetComponent<SystemType>().info); } }
public static GameObject MakeCard(string type, Vector2f position) { GameObject card = GameObject.Instantiate(new GameObject()) as GameObject; card.name = "Card"; MakeFace(card, "Back", -0.01f, "2h", Color.clear); MakeFace(card, "Middle", 0.0f, null, Color.white); MakeFace(card, "Front", 0.01f, "2h", Color.clear); card.transform.position = new Vector3(position.x, 0.1f, position.y); return card; }
public static bool IsEntityAt(Entity entity, Vector2f point) { BoundingRectangle bound = entity.GetComponent<BoundingRectangle>(); Position position = entity.GetComponent<Position>(); if (position != null && bound != null) { Vector2f min = bound.min + position.position; Vector2f max = bound.max + position.position; if (TestCollision(point, min, max)) { return true; } } return false; }
public void UpdateAll(GameManager game, float delta) { if (selected != null) { selected.GetComponent<Position>().position = game.Inputs.Mouse.Position + offset; if (game.Inputs.Mouse.Left.Released) { Place (game, selected, game.Inputs.Mouse.Position); selected = null; } } else if (selected == null && game.Inputs.Mouse.Left.Pressed) { selected = EntityFinder.GetEntityAt(game.GetEntitiesWith<CardType>(), game.Inputs.Mouse.Position); PlayerInfo playerInfo = new PlayerInfo(); foreach(Entity player in game.GetEntitiesWith<PlayerType>()) { if (player.GetComponent<PlayerType>().info.Owner) { playerInfo = player.GetComponent<PlayerType>().info; break; } } if (selected != null) { if (!game.Rules.CanPickUpCard(playerInfo, selected.GetComponent<CardType>().info)) { selected = null; } else { offset = selected.GetComponent<Position>().position - game.Inputs.Mouse.Position; } } } }
public static float Distance(Vector2f v1, Vector2f v2) { return (float)Math.Sqrt(Math.Pow(v1.x - v2.x, 2) + Math.Pow(v1.y - v2.y, 2)); }
public static bool TestCollision(Vector2f position, Vector2f min, Vector2f max) { return (position.x <= max.x && position.x >= min.x && position.y <= max.y && position.y >= min.y); }
public static Vector3 FromGame(Vector2f position) { return new Vector3(position.x, 0.0f, position.y); }