Ejemplo n.º 1
0
        public Game(int width, int height)
            : base(width, height)
        {
            GL.Enable(EnableCap.Texture2D);

            //change numbers to rotate or zoom
            //to rotate use : MathHelper.PiOver2 or 3 or 4...
            view = new View(Vector2.Zero, 1.0, MathHelper.PiOver3);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws the starfield with the specified view, reseting the current view.
        /// </summary>
        public void Draw(View View, double AspectRatio)
        {
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.MatrixMode(MatrixMode.Texture);
            double zoom = View.Zoom;

            foreach (Layer l in this.Layers)
            {
                double visibility = 0.7 - Math.Abs(Math.Log10(l.Scale * 2.0) - Math.Log10(1.0 / zoom)) * 1.6;
                if (visibility > 0.0)
                {
                    GL.LoadIdentity();
                    GL.Scale(1.0 / l.Scale, 1.0 / l.Scale, 1.0);
                    GL.Translate(View.Center.X / 2.0 * l.Offset, -View.Center.Y / 2.0 * l.Offset, 0.0);
                    GL.Rotate(View.Angle * 180 / Math.PI, 0.0, 0.0, 1.0);
                    if (AspectRatio > 1.0)
                    {
                        GL.Scale(AspectRatio / zoom, 1.0 / zoom, 1.0);
                    }
                    else
                    {
                        GL.Scale(1.0 / zoom, 1.0 / zoom / AspectRatio, 1.0);
                    }
                    GL.Translate(-0.5, -0.5, 1.0);

                    Texture.Bind2D(l.TextureID);
                    GL.Begin(BeginMode.Quads);
                    GL.Color4(1.0, 1.0, 1.0, visibility);
                    GL.Vertex2(-1.0f, -1.0f); GL.TexCoord2(0f, 0f);
                    GL.Vertex2(-1.0f, 1.0f); GL.TexCoord2(1f, 0f);
                    GL.Vertex2(1.0f, 1.0f); GL.TexCoord2(1f, 1f);
                    GL.Vertex2(1.0f, -1.0f); GL.TexCoord2(0f, 1f);
                    GL.End();
                }
            }
        }
Ejemplo n.º 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);
                            }
                        }
                    }
                }
            };
        }