Esempio n. 1
0
		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;
		}
Esempio n. 2
0
		public void SendMouseRelease(int button, Vector2f position)
		{
			foreach (IMouseListener listener in mouseListeners)
			{
				listener.Release(button, position);
			}
		}
Esempio n. 3
0
		public void SendMousePosition(Vector2f position)
		{
			foreach (IMouseListener listener in mouseListeners)
			{
				listener.Move(position);
			}
		}
Esempio n. 4
0
		public void SendMousePress(int button, Vector2f position)
		{
			foreach (IMouseListener listener in mouseListeners)
			{
				listener.Press(button, position);
			}
		}
Esempio n. 5
0
		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);
			}
		}
Esempio n. 6
0
		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;
		}
Esempio n. 7
0
		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;
		}
Esempio n. 8
0
		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;
					}
				}
			}
		}
Esempio n. 9
0
		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));
		}
Esempio n. 10
0
		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);
		}
Esempio n. 11
0
		public static Vector3 FromGame(Vector2f position)
		{
			return new Vector3(position.x, 0.0f, position.y);
		}