Exemplo n.º 1
0
		private void SetupPlayArea()
		{
			window.Title = "Snake - Let's go";
			window.BackgroundColor = menu.gameColors[0];
			rectangleBorder = new FilledRect(Rectangle.One, menu.gameColors[1]) { RenderLayer = 0 };
			rectangleField = new FilledRect(CalculateBackgroundDrawArea(), menu.gameColors[0]) { RenderLayer = 1 };
		}
Exemplo n.º 2
0
		public void MovingARectangleWithTheArrows()
		{
			var rect = new FilledRect(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f), Color.Green);
			new Command(Command.MoveDown, () => rect.DrawArea = rect.DrawArea.Move(0, 0.01f));
			new Command(Command.MoveUp, () => rect.DrawArea = rect.DrawArea.Move(0, -0.01f));
			new Command(Command.MoveLeft, () => rect.DrawArea = rect.DrawArea.Move(-0.01f, 0));
			new Command(Command.MoveRight, () => rect.DrawArea = rect.DrawArea.Move(0.01f, 0));
		}
Exemplo n.º 3
0
 public void HoldMouseHovering()
 {
     var drawArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.25f);
     var rect = new FilledRect(drawArea, Color.Blue);
     var trigger = new MouseHoldTrigger(drawArea);
     trigger.Invoked += () => rect.Color = Color.Red;
     trigger.Position = new Vector2D(0.3f, 0.3f);
     Assert.IsFalse(trigger.IsHovering());
     AdvanceTimeAndUpdateEntities(1.05f);
     Assert.IsFalse(trigger.IsHovering());
 }
Exemplo n.º 4
0
		internal static void DragToCreateRectangles(InputTrigger trigger)
		{
			var rectangle = new FilledRect(Rectangle.Unused, Color.GetRandomColor());
			new Command((start, end, done) =>
			//ncrunch: no coverage start
			{
				rectangle.DrawArea = Rectangle.FromCorners(start, end);
				if (done)
					rectangle = new FilledRect(Rectangle.Unused, Color.GetRandomColor());
			}).Add(trigger);
			//ncrunch: no coverage end
		}
Exemplo n.º 5
0
 public void DragMouseHorizontalToCreateRectangles()
 {
     var rectangle = new FilledRect(Rectangle.Unused, Color.GetRandomColor());
     //ncrunch: no coverage start
     new Command((start, end, done) =>
     {
         rectangle.DrawArea = new Rectangle(start.X, start.Y - 0.01f, end.X - start.X, 0.02f);
         if (done)
             rectangle = new FilledRect(Rectangle.Unused, Color.GetRandomColor());
     }).Add(new MouseDragTrigger(MouseButton.Left, DragDirection.Horizontal));
     //ncrunch: no coverage end
 }
Exemplo n.º 6
0
		private void CreateLineMarkers(float partsWidth)
		{
			if (lineMarkers != null)
				foreach (var lineMarker in lineMarkers)
					lineMarker.IsActive = false;

			var numberOfLines = colorIntervals.Values.Length;
			lineMarkers = new FilledRect[numberOfLines];
			for (int i = 0; i < numberOfLines; i++)
				lineMarkers[i] = new FilledRect(CreateMarkerDrawAreaForIndex(i, partsWidth), Color.Gray)
				{
					RenderLayer = RenderLayer + 1
				};
		}
Exemplo n.º 7
0
 public void ShowRedSquare()
 {
     new FontText(Font.Default, "Pinch screen to show red circle", Rectangle.One);
     var rect = new FilledRect(new Rectangle(0.1f, 0.1f, 0.1f, 0.1f), Color.Red);
     var trigger = new TouchRotateTrigger();
     var touch = Resolve<Touch>();
     new Command(() =>
     //ncrunch: no coverage start
     {
         rect.Center = touch.GetPosition(0);
         rect.RotationCenter = rect.Center;
         rect.Rotation = trigger.Angle;
     }).Add(trigger);
     //ncrunch: no coverage end
 }
Exemplo n.º 8
0
		private void Initialize()
		{
			if (map.RenderIn3D)
			{
				if (grid3D != null)
					Dispose3D(); //ncrunch: no coverage
				grid3D = new Grid3D(map.Size) { RenderLayer = 10 };
				models = new Model[(int)map.Size.Width * (int)map.Size.Height];
			}
			else
			{
				if (grid2D != null)
					Dispose2D(); //ncrunch: no coverage
				grid2D = new Grid2D(map.Size, Vector2D.Half, GridScale) { RenderLayer = 10 };
				rectangles = new FilledRect[(int)map.Size.Width * (int)map.Size.Height];
			}
		}
Exemplo n.º 9
0
 public void BounceOffScreenEdge()
 {
     var rect =
         new FilledRect(new Rectangle(ScreenSpace.Current.Viewport.TopLeft, new Size(0.2f)),
             Color.Red);
     rect.Add(new SimplePhysics.Data
     {
         Gravity = Vector2D.Zero,
         Velocity = new Vector2D(-0.1f, 0.0f)
     });
     rect.Start<SimplePhysics.Move>();
     rect.Start<SimplePhysics.BounceIfAtScreenEdge>();
     var collided = false;
     rect.Get<SimplePhysics.Data>().Bounced += () => collided = true;
     AdvanceTimeAndUpdateEntities();
     Assert.IsTrue(collided);
     Assert.AreEqual(0.1f, rect.Get<SimplePhysics.Data>().Velocity.X);
 }
Exemplo n.º 10
0
 public void RenderRotatingRect()
 {
     var rect = new FilledRect(Rectangle.FromCenter(Vector2D.Half, new Size(0.2f)), Color.Orange)
     {
         Rotation = 0
     };
     rect.Add(new SimplePhysics.Data { Gravity = Vector2D.Zero, RotationSpeed = 5 });
     rect.Start<SimplePhysics.Rotate>();
 }
Exemplo n.º 11
0
		private void CreateRabbitHealthBar()
		{
			var healthBar = new FilledRect(new Rectangle(), Color.Red) { IsVisible = false };
			healthBar.RenderLayer = RenderLayer + 1;
			Add(healthBar);
		}
Exemplo n.º 12
0
		public void PitchToChangeTheScale()
		{
			var rect = new FilledRect(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f), Color.Green);
			new Command(Command.Pinch, point => rect.DrawArea = rect.DrawArea.Reduce((Size)point));
		}
Exemplo n.º 13
0
		public void TouchToMoveTheRectangleARound()
		{
			var rect = new FilledRect(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f), Color.Green);
			new Command(Command.Drag, point => { rect.Center = point; });
		}
Exemplo n.º 14
0
		public void BackWillRemoveRectangle()
		{
			var rect = new FilledRect(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f), Color.Green);
			new Command(Command.Back, () => { rect.IsActive = false; });
		}
Exemplo n.º 15
0
		public void RotateRectangleWithMouse()
		{
			var rect = new FilledRect(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f), Color.Green);
			new Command(Command.RotateDirectly, delegate(Vector2D point) { rect.Rotation += 1; });
		}
Exemplo n.º 16
0
		private bool SnakeCollidesWithBorders(FilledRect snakeHead)
		{
			if ((snakeHead.DrawArea.Left < blockSize - 0.01f ||
				snakeHead.DrawArea.Top < blockSize - 0.01f ||
				snakeHead.DrawArea.Left > 1 - blockSize - 0.01f ||
				snakeHead.DrawArea.Top > 1 - blockSize - 0.01f))
				return true;
			return false;
		}
Exemplo n.º 17
0
		public void UsingRotationOnATouchPadWillRotateTheRectangle()
		{
			var rect = new FilledRect(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f), Color.Green);
			new Command(Command.Rotate, point => rect.Rotation += point.X);
		}
Exemplo n.º 18
0
		private void PlaceSnakeHead()
		{
			var startPosition = blockSize * (float)Math.Floor(gridSize / 2.0f);
			var firstPart = new FilledRect(CalculateHeadDrawArea(startPosition), color) {RenderLayer = 3};
			BodyParts.Add(firstPart);
		}
Exemplo n.º 19
0
		public void AddSnakeBody()
		{
			var snakeHead = BodyParts[BodyParts.Count - 1].DrawArea;
			var newTail = new FilledRect(CalculateBodyDrawArea(snakeHead), color){RenderLayer = 3};
			BodyParts.Add(newTail);
		}
Exemplo n.º 20
0
		private void GrowSnakeInSize(Vector2D trailingVector)
		{
			var snakeBodyParts = snakeBody.BodyParts;
			var tail = snakeBodyParts[snakeBodyParts.Count - 1].DrawArea.TopLeft;
			var newBodyPart = new FilledRect(CalculateTrailDrawArea(trailingVector, tail),
				menu.gameColors[2]) { RenderLayer = 3 };
			snakeBodyParts.Add(newBodyPart);
			window.Title = "Snake - Length: " + snakeBodyParts.Count;
		}
Exemplo n.º 21
0
		private bool SnakeCollidesWithItself(FilledRect snakeHead)
		{
			for (int count = 3; count < BodyParts.Count; count++)
				if (snakeHead.DrawArea.TopLeft == BodyParts[count].DrawArea.TopLeft)
					return true;
			return false;
		}
Exemplo n.º 22
0
 public void RotateAdvancesAngleCorrectly()
 {
     var rect = new FilledRect(new Rectangle(ScreenSpace.Current.Viewport.TopLeft, new Size(0.2f)),
         Color.Red);
     rect.Rotation = 0;
     rect.Add(new SimplePhysics.Data { Gravity = Vector2D.Zero, RotationSpeed = 0.1f });
     rect.Start<SimplePhysics.Rotate>();
     AdvanceTimeAndUpdateEntities();
     Assert.Greater(rect.Rotation, 0);
 }
Exemplo n.º 23
0
 private void AddBackgroundAndColorDisplay()
 {
     Add(new FilledRect(new Rectangle(0.15f, 0.15f, 0.7f, 0.7f), Color.DarkGray)
     {
         RenderLayer = 4
     });
     currentColorShown = new FilledRect(new Rectangle(0.2f, 0.45f, 0.1f, 0.1f),
         parentMenu.gameColors[currentColorIndex]) { RenderLayer = 5 };
     Add(currentColorShown);
 }