Beispiel #1
0
        internal void _Pull(double Time, Driftoid Driftoid, Driftoid Target, Vector Position)
        {
            double dis = (Target.Position - Driftoid.Position).Length;
            if (dis < this.MaxDistance)
            {
                Vector vel = Target.MotionState.Velocity;
                double vellen = vel.Length;
                vel = vel * vellen;

                Vector gpos = Target.Position + vel * (Target.Mass / this.MaxForce);
                Vector vec = (Position - gpos);
                double mdis = vec.Length;
                Vector nvec = vec * (1.0 / mdis);
                vec = nvec * this.MaxForce;
                Target._ApplyForce(Time, vec);
                Driftoid._ApplyForce(Time, -vec);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Gets if the specified driftoid is an ancestor of this.
 /// </summary>
 public bool IsAncestor(Driftoid Driftoid)
 {
     if (this == Driftoid)
     {
         return true;
     }
     if (this._LinkedParent == null)
     {
         return false;
     }
     return this._LinkedParent.IsAncestor(Driftoid);
 }
Beispiel #3
0
        public Window()
            : base(640, 480, GraphicsMode.Default, "Driftoid")
        {
            this.VSync = VSyncMode.Off;
            this.WindowState = WindowState.Maximized;
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.ColorMaterial);

            this._Area = new Area();

            for (int x = 0; x < 6; x++)
            {
                for (int y = 0; y < 6; y++)
                {
                    this._Area.Spawn(
                        Driftoid.Make(
                            PrimitiveDriftoid.GetConstructor((PrimitiveType)y),
                            new Vector((double)x * 3.0, (double)y * 3.0 - 7.5)) as LinkedDriftoid);
                }
            }

            this._Area.Spawn(
                Driftoid.Make(
                    NucleusDriftoid.GetConstructor(this._Player = new Player(Color.RGB(1.0, 0.0, 0.0))),
                    new Vector(-8.0, 0.0)) as LinkedDriftoid);
            this._Area.Spawn(
                Driftoid.Make(
                    WeightedDriftoid.GetConstructor(0),
                    new Vector(-8.0, 7.0)) as LinkedDriftoid);
            this._Starfield = Starfield.CreateDefault(512, 5);

            this._View = new View(new Vector(), 0.0, 0.1);

            this.Mouse.ButtonDown += delegate(object sender, MouseButtonEventArgs e)
            {
                if (e.Button == MouseButton.Left)
                {
                    Vector pos = this.MouseWorldPosition;
                    this._Dragged = this._Area.Pick(pos);
                }
                if (e.Button == MouseButton.Right)
                {
                    Vector pos = this.MouseWorldPosition;
                    LinkedDriftoid ldr = this._Area.Pick(pos) as LinkedDriftoid;
                    if (ldr != null)
                    {
                        this._Area.TryDelink(this._Player, ldr);
                    }
                }
            };

            this.Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e)
            {
                // Test reaction
                if (e.Key == Key.F)
                {
                    Vector mousepos = this.MouseWorldPosition;
                    LinkedDriftoid ldr = this._Area.Pick(mousepos);
                    if (ldr != null)
                    {
                        if (ldr.ReactionClear && this._Area.HasLinkControl(this._Player, ldr))
                        {
                            //DriftoidConstructor product = Recipe.Master.GetProduct(new Structure(ldr));
                            DriftoidConstructor product = PrimitiveDriftoid.GetConstructor(PrimitiveType.Sulfur);
                            if (product != null)
                            {
                                Reaction r = new Reaction()
                                {
                                    Product = product,
                                    Target = ldr
                                };
                                this._Area.BeginReaction(r);
                            }
                        }
                    }
                }
            };
        }