Ejemplo n.º 1
0
        private static float CountMassAmount(Cell source, Cell target)
        {
            var r1       = Math.Max(source.Radius, target.Radius);
            var r2       = Math.Min(source.Radius, target.Radius);
            var distance = Point2D.DistanceBetween(source.Position, target.Position);
            //var mass1 = Math.PI * Math.Pow(r1 + (2 * r1 * distance - distance * distance) / (2 * r1 - 2 * distance + 2 * r2) -
            //            distance, 2) - Math.PI * r1 * r1;

            //var x = (2 * r1 * distance - distance * distance) / (2 * r1 - 2 * distance + 2 * r2);

            //var mass2 = Math.PI * r2 * r2 - Math.PI * Math.Pow(r2 - (2 * r1 * distance - distance * distance) / (2 * r1 - 2 * distance + 2 * r2), 2);

            var y = (r1 * r1 - r2 * r2 - distance * distance + 2 * distance * r2) / (2 * distance);

            //var x = distance - r1 - r2 + y;
            //var mass1 = Math.PI * (Math.Pow(r1 + x, 2) - Math.Pow(r1, 2));

            if (y > r2)
            {
                return(target.Mass);
            }

            var mass2 = Math.PI * (Math.Pow(r2, 2) - Math.Pow(r2 - y, 2));

            return((float)mass2);
        }
Ejemplo n.º 2
0
        private static Point2D SetNewCellMovementVector()
        {
            Point2D clickPosition = GameWindow.GameFieldCursorPosition;
            var     distance      = Point2D.DistanceBetween(player.Position, clickPosition);

            float lambda    = (float)(distance / Math.Pow(distance, 2));
            var   xOnCircle = (player.Position.X + lambda * clickPosition.X) / (1 + lambda);
            var   yOnCircle = (player.Position.Y + lambda * clickPosition.Y) / (1 + lambda);
            var   xSpeed    = player.Position.X - xOnCircle;
            var   ySpeed    = player.Position.Y - yOnCircle;

            return(new Point2D(-xSpeed, -ySpeed));
        }
Ejemplo n.º 3
0
        public void Move()
        {
            Point2D clickPosition = GameWindow.GameFieldCursorPosition;
            var     distance      = Point2D.DistanceBetween(source.Position, clickPosition);

            var xDifference = clickPosition.X - source.Position.X;
            var yDifference = clickPosition.Y - source.Position.Y;

            var ratio = Math.Min(xDifference, yDifference) / Math.Max(xDifference, yDifference);

            float lambda    = (float)(distance / Math.Pow(distance, 2));
            var   xOnCircle = (source.Position.X + lambda * clickPosition.X) / (1 + lambda);
            var   yOnCircle = (source.Position.Y + lambda * clickPosition.Y) / (1 + lambda);
            var   xSpeed    = source.Position.X - xOnCircle;
            var   ySpeed    = source.Position.Y - yOnCircle;

            source.MovementVector.X += xSpeed;
            source.MovementVector.Y += ySpeed;
        }
Ejemplo n.º 4
0
        public static void PushCell()
        {
            var cellMass = player.Mass / 10;

            player.Mass -= cellMass;
            var cellRadius = (float)Math.Sqrt(cellMass / Math.PI);

            var cellMovementVector = SetNewCellMovementVector();

            var distanceMultiplier = (player.Radius + cellRadius) / Point2D.DistanceBetween(player.Position, cellMovementVector + player.Position);
            var position           = player.Position + cellMovementVector * distanceMultiplier;

            cells.Add(
                CellFactory.Create(
                    position,
                    cellMass,
                    cellMovementVector));
            player.MovementVector -= cellMovementVector;
        }
Ejemplo n.º 5
0
 private static bool DoCellsIntersect(Cell source, Cell target)
 {
     return(Point2D.DistanceBetween(source.Position, target.Position) < source.Radius + target.Radius);
 }