// Object cannot move outside the window private void BlockedWindow(BetterShape s) { // WPF IS BAD if (s.Bottom > this.ActualHeight - 35) { s.Bottom = this.ActualHeight - 35; s.VelocityY = -s.VelocityY; } else if (s.Top < 0) { s.Top = 0; s.VelocityY = -s.VelocityY; } if (s.Right > this.ActualWidth - 20) { s.Right = this.ActualWidth - 20; s.VelocityY -= gravity * (decimal)dt.Elapsed.TotalSeconds; s.VelocityX = -s.VelocityX; } else if (s.Left < 0) { s.Left = 0; s.VelocityX = -s.VelocityX; } }
public static bool RectRect(BetterShape r1, BetterShape r2) { if (r1.Left < r2.Right && r1.Right > r2.Left && r1.Top < r2.Bottom && r1.Bottom > r2.Top) { return(true); } else { return(false); } }
private void UpdatePosition(BetterShape s) { if (!s.IsHeld && dt.ElapsedMilliseconds > 1000 / maxFPS) { s.VelocityY += gravity * (decimal)dt.Elapsed.TotalSeconds; s.X += (double)s.VelocityX * dt.Elapsed.TotalSeconds; s.Y += (double)s.VelocityY * dt.Elapsed.TotalSeconds; } else if (s.IsHeld) { s.VelocityY = Math.Abs(s.VelocityY); } }
public static bool CircleCircle(BetterShape c1, BetterShape c2) { double x = c1.X - c2.X; double y = c1.Y - c2.Y; double distance = Math.Sqrt((x * x) + (y * y)); if (distance < c1.Height / 2 + c2.Height / 2) { return(true); } else { return(false); } }
// Object can move outside and return to the window private void FreeWindow(BetterShape s) { if (s.Top > this.ActualHeight) { s.Bottom = 0; } else if (s.Bottom < 0) { s.Top = this.ActualHeight; } if (s.Left > this.ActualWidth) { s.Right = 0; } else if (s.Right < 0) { s.Left = this.ActualWidth; } }
private void HandleInput(BetterShape s, KeyEventArgs e) { switch (e.Key) { // TO DO: FIX case Key.Up: if (!IsGKeyDown) { s.VelocityY -= 50.0m; } break; case Key.Down: if (!IsGKeyDown) { s.VelocityY += 50.0m; } break; case Key.Right: s.VelocityX += 50.0m; break; case Key.Left: s.VelocityX -= 50.0m; break; case Key.G: IsGKeyDown = true; break; } if (e.Key == Key.Down && IsGKeyDown) { gravity += 10.0m; } if (e.Key == Key.Up && IsGKeyDown) { gravity -= 10.0m; } }
public static bool Any(BetterShape s1, BetterShape s2) { if (s1.shape is Rectangle && s2.shape is Rectangle) { return(RectRect(s1, s2)); } else if (s1.shape is Ellipse && s2.shape is Rectangle) { return(CircleRect(s1, s2)); } else if (s1.shape is Rectangle && s2.shape is Ellipse) { return(CircleRect(s2, s1)); } else if (s1.shape is Ellipse && s2.shape is Ellipse) { return(CircleCircle(s1, s2)); } else { return(false); } }
// DUMB public static Side RectColidedSide(BetterShape r1, BetterShape r2) { if (r1.Left < r2.Right) { return(Side.Right); } else if (r1.Right > r2.Left) { return(Side.Left); } else if (r1.Top < r2.Bottom) { return(Side.Top); } else if (r1.Bottom > r2.Top) { return(Side.Bottom); } else { return(Side.None); } }
public static bool CircleRect(BetterShape c1, BetterShape r2) { double circleX = c1.X; double circleY = c1.Y; if (c1.X < r2.Left) { circleX = r2.Left; } else if (c1.X > r2.Right) { circleX = r2.Right; } if (c1.Y < r2.Top) { circleY = r2.Top; } else if (c1.Y > r2.Bottom) { circleY = r2.Bottom; } double distX = c1.X - circleX; double distY = c1.Y - circleY; double distance = Math.Sqrt((distX * distX) + (distY * distY)); if (distance <= c1.Height / 2) { return(true); } else { return(false); } }