pevel

Untitled

Feb 6th, 2023
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4.  
  5. namespace func_rocket
  6. {
  7.     public class LevelsTask
  8.     {
  9.         static readonly Physics StandardPhysics = new Physics();
  10.         static readonly Vector DefaultLocation = new Vector(200, 500);
  11.         static readonly Vector DefaultTarget = new Vector(600, 200);
  12.         static readonly Vector DefaultVelocity = Vector.Zero;
  13.         static readonly double DefaultDirection = -0.5 * Math.PI;
  14.         static readonly Gravity DefaultGravity = (size, location) => Vector.Zero;
  15.         static readonly Rocket DefaultRocket = new Rocket(DefaultLocation, DefaultVelocity, DefaultDirection);
  16.  
  17.  
  18.         public static IEnumerable<Level> CreateLevels()
  19.         {
  20.             yield return LevelBuilder("Zero");
  21.             yield return LevelBuilder("Up",
  22.                 gravity: (size, location) => new Vector(0, -300 / (size.Height - location.Y + 300.0)),
  23.                 target: new Vector(700, 500));
  24.             yield return LevelBuilder("Heavy",
  25.                 gravity: (size, location) => new Vector(0, 0.9));
  26.             yield return LevelBuilder("WhiteHole",
  27.                 gravity: WhiteHoleGravity(DefaultTarget));
  28.             yield return LevelBuilder("BlackHole",
  29.                 gravity: BlackHoleGravity(DefaultTarget, DefaultLocation));
  30.             yield return LevelBuilder("BlackAndWhite",
  31.                 gravity: (size, location) => BlackAndAndWhiteGravity(size, location, DefaultTarget, DefaultLocation));
  32.         }
  33.  
  34.         public static Gravity WhiteHoleGravity(Vector target)
  35.         {
  36.             return (size, location) =>
  37.             {
  38.                 var direction = target - location;
  39.                 return direction.Normalize() * -140 * direction.Length / (direction.Length * direction.Length + 1);
  40.             };
  41.         }
  42.  
  43.         public static Gravity BlackHoleGravity(Vector target, Vector start)
  44.         {
  45.             return (size, location) =>
  46.             {
  47.                 var direction = (target + start) * 0.5 - location;
  48.                 return direction.Normalize() * 300 * direction.Length / (direction.Length * direction.Length + 1);
  49.             };
  50.         }
  51.  
  52.         public static Vector BlackAndAndWhiteGravity(Size size, Vector location, Vector target, Vector start) =>
  53.             (WhiteHoleGravity(target)(size, location) + BlackHoleGravity(target, start)(size, location)) / 2;
  54.  
  55.  
  56.         public static Level LevelBuilder(string name, Rocket rocket = null, Vector target = null,
  57.             Gravity gravity = null, Physics physics = null)
  58.         {
  59.             if (rocket == null)
  60.                 rocket = DefaultRocket;
  61.             if (target == null)
  62.                 target = DefaultTarget;
  63.             if (gravity == null)
  64.                 gravity = DefaultGravity;
  65.             if (physics == null)
  66.                 physics = StandardPhysics;
  67.  
  68.             return new Level(name, rocket, target, gravity, physics);
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment