Beispiel #1
0
 private NucleusDriftoid(Player Owner, MotionState MotionState, double Mass, double Radius)
     : base(MotionState, Mass, Radius)
 {
     this._Owner = Owner;
 }
Beispiel #2
0
 /// <summary>
 /// Gets a constructor for a nucleus driftoid owned by the specified player.
 /// </summary>
 public static DriftoidConstructor GetConstructor(Player Owner)
 {
     return new DriftoidConstructor((MotionState MotionState, double Mass, double Radius) => new NucleusDriftoid(Owner, MotionState, Mass, Radius),
         20.0, 3.0);
 }
Beispiel #3
0
        private static int _CreateTexture(Player Player)
        {
            Color primary = Player.FadedColor;
            Color secondary = Player.SecondaryColor;
            int texsize = 256;
            float actualsize = (float)texsize;
            using (Bitmap bm = new Bitmap(texsize, texsize))
            {
                Driftoid.DrawSolid(bm, 0.15, primary, secondary);
                using (Graphics g = Graphics.FromImage(bm))
                {
                    int dashamount = 9;
                    double dashdelta = Math.PI * 2.0 / (double)dashamount;
                    Vector center = new Vector(actualsize / 2.0f, actualsize / 2.0f);
                    using (Pen p = new Pen(primary, actualsize * 0.05f))
                    {
                        for (int t = 0; t < dashamount; t++)
                        {
                            double dashangle = dashdelta * (double)t;
                            Vector dashunit = Vector.Unit(dashangle) * (double)actualsize * 0.5;

                            g.DrawLine(p, dashunit * 0.3 + center, dashunit * 0.6 + center);
                        }
                    }
                }
                return Texture.Create(bm);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Indicates that a player is trying to manually delink a driftoid from its parent.
 /// </summary>
 public void TryDelink(Player Player, LinkedDriftoid Target)
 {
     if (Target.LinkedParent != null && Target.Reaction == null)
     {
         if (this.HasLinkControl(Player, Target))
         {
             LinkedDriftoid._Delink(Target.LinkedParent, Target);
         }
     }
 }
Beispiel #5
0
 /// <summary>
 /// Issues or updates a drift command for the specified player.
 /// </summary>
 public void IssueCommand(Player Player, DriftCommand Command)
 {
     this._DriftCommands[Player] = Command;
 }
Beispiel #6
0
        /// <summary>
        /// Gets if a player can control the links associated with the target.
        /// </summary>
        public bool HasLinkControl(Player Player, LinkedDriftoid Target)
        {
            LinkedDriftoid cur = Target;
            while (cur != null)
            {
                NucleusDriftoid ndr = cur as NucleusDriftoid;
                if (ndr != null)
                {
                    if (ndr.Owner == Player)
                    {
                        return true;
                    }
                }

                cur = cur.LinkedParent;
            }
            return false;
        }
Beispiel #7
0
 /// <summary>
 /// Cancels all drift commands for the specified player.
 /// </summary>
 public void CancelDriftCommand(Player Player)
 {
     this._DriftCommands.Remove(Player);
 }
Beispiel #8
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);
                            }
                        }
                    }
                }
            };
        }