Beispiel #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 };
		}
Beispiel #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));
		}
 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());
 }
		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
		}
 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
 }
Beispiel #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
				};
		}
 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
 }
		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];
			}
		}
 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);
 }
 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>();
 }
Beispiel #11
0
		private void CreateRabbitHealthBar()
		{
			var healthBar = new FilledRect(new Rectangle(), Color.Red) { IsVisible = false };
			healthBar.RenderLayer = RenderLayer + 1;
			Add(healthBar);
		}
Beispiel #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));
		}
Beispiel #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; });
		}
Beispiel #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; });
		}
Beispiel #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; });
		}
Beispiel #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;
		}
Beispiel #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);
		}
Beispiel #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);
		}
Beispiel #19
0
		public void AddSnakeBody()
		{
			var snakeHead = BodyParts[BodyParts.Count - 1].DrawArea;
			var newTail = new FilledRect(CalculateBodyDrawArea(snakeHead), color){RenderLayer = 3};
			BodyParts.Add(newTail);
		}
Beispiel #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;
		}
Beispiel #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;
		}
 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);
 }
Beispiel #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);
 }