Advertisement
KoMeDiAnT

Levels

Mar 19th, 2017
2,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 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 double distance;
  11.         static Rocket rocket = new Rocket(new Vector(200, 500), Vector.Zero, -0.5*Math.PI);
  12.         static Vector target = new Vector(600, 200);
  13.  
  14.         public static Vector GravityWhiteHole(double x, double y)
  15.         {
  16.             var vector = new Vector(x - 600, y - 200);
  17.             distance = Math.Sqrt(Math.Pow(600 - x, 2.0) + Math.Pow(200 - y, 2.0));
  18.             return vector.Normalize() * (140 * distance) / (distance * distance + 1);
  19.         }
  20.  
  21.         public static Vector GravityBlackHole(double x, double y)
  22.         {
  23.             var coorXOfAnomalies = (200 + 600) / 2.0;
  24.             var coorYOfAnomalies = (500 + 200) / 2.0;
  25.             var vector = new Vector(x - coorXOfAnomalies, y - coorYOfAnomalies);
  26.             distance =
  27.                 Math.Sqrt(Math.Pow(coorXOfAnomalies - x, 2.0) + Math.Pow(coorYOfAnomalies - y, 2.0));
  28.             return -1 * vector.Normalize() * (300 * distance) / (distance * distance + 1);
  29.         }
  30.  
  31.         public static Level CreateLevel(string name, Gravity gravity)
  32.         {
  33.             return new Level(name, rocket, target, gravity, StandardPhysics);
  34.         }
  35.         public static IEnumerable<Level> CreateLevels()
  36.         {
  37.             yield return CreateLevel("Zero", (size, location) => Vector.Zero);
  38.  
  39.             yield return CreateLevel("Heavy", (size, location) => new Vector(0.0, 0.9));
  40.  
  41.             yield return new Level("Up", rocket, new Vector(700, 500),
  42.                 (size, location) => new Vector(0, -(300 / (size.Height - location.Y + 300.0))), StandardPhysics);
  43.  
  44.             yield return CreateLevel("WhiteHole",
  45.                 (size, location) => GravityWhiteHole(location.X, location.Y));
  46.  
  47.             yield return CreateLevel("BlackHole",
  48.                 (size, location) => GravityBlackHole(location.X, location.Y));
  49.  
  50.             yield return CreateLevel("BlackAndWhite",
  51.                     (size, location) => (GravityBlackHole(location.X, location.Y) + GravityWhiteHole(location.X, location.Y))/2);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement