コード例 #1
0
        public void NewScene()
        {
            EditGraph = new SceneGraph();
            var l = new GraphLight();

            l.Diffuse = new OpenTK.Vector3(1, 1, 1);
            l.Range   = 600;
            EditGraph.Add(l);
        }
コード例 #2
0
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            var lp = EditGraph.GetPoint(MX, MY);
            var nl = new GraphLight();

            nl.X = lp.X;
            nl.Y = lp.Y;
            nl.Z = 1.0f;
            if (LightIcon == null)
            {
                Environment.Exit(1);
            }
            nl.ImgFrame = LightIcon;
            nl.W        = 32;
            nl.H        = 32;
            EditGraph.Add(nl, true);
            SyncUI();
        }
コード例 #3
0
 public void AddLight(GraphLight l)
 {
     Lights.Add(l);
     sceneChanged = true;
 }
コード例 #4
0
        public override void Update()
        {
            if (AimSprite == null)
            {
                AimSprite   = new GraphSprite(PulseAimImg, null);
                AimSprite.X = X;
                AimSprite.Y = Y;
                Graph.Add(AimSprite);
                aimLight         = new GraphLight();
                aimLight.Diffuse = new OpenTK.Vector3(0, 0.2f, 0.2f);
                aimLight.Range   = 150;

                Graph.Add(aimLight);
            }
            else
            {
                if (usePad)
                {
                    float xi = XIn.rightX();
                    float yi = XIn.rightY();

                    float dis = (float)Math.Sqrt((xi * xi) + (yi * yi));

                    if (dis > 0.5)
                    {
                        float ang = (float)Math.Atan2(-yi, xi);

                        aimAngle = OpenTK.MathHelper.RadiansToDegrees(ang);


                        //aimAngle = ang;


                        AimSprite.Rot = aimAngle;

                        float xo = (float)Math.Cos(ang);
                        float yo = (float)Math.Sin(ang);

                        xo = xo * 64;
                        yo = yo * 64;


                        AimSprite.X = X + xo;
                        AimSprite.Y = Y + yo;
                        aimLight.X  = AimSprite.X;
                        aimLight.Y  = AimSprite.Y;
                    }
                }
                else
                {
                    float rx = RealX;
                    float ry = RealY;

                    float mx = Vivid.Input.Input.MX;
                    float my = Vivid.Input.Input.MY;

                    float ang = (float)Math.Atan2(my - ry, mx - rx);

                    aimAngle = ang;

                    AimSprite.Rot = OpenTK.MathHelper.RadiansToDegrees(aimAngle);

                    //Console.WriteLine("Rot:" + AimSprite.Rot);

                    float xo = (float)Math.Cos(aimAngle);
                    float yo = (float)Math.Sin(aimAngle);

                    xo = xo * 64;
                    yo = yo * 64;


                    AimSprite.X = X + xo;
                    AimSprite.Y = Y + yo;
                    aimLight.X  = AimSprite.X;
                    aimLight.Y  = AimSprite.Y;
                }
            }


            if (!changedSlot)
            {
                if (XIn.DLeft() || Vivid.Input.Input.KeyIn(OpenTK.Input.Key.Q))
                {
                    CurSlot--;
                    if (CurSlot < 0)
                    {
                        if (Slots[2] == null)
                        {
                            CurSlot = 1;
                        }
                        else
                        {
                            CurSlot = 2;
                        }
                    }
                    changedSlot = true;
                    RebuildWeaponHud();
                    Songs.PlaySource(ChangeSrc, false);
                }
                if (XIn.DRight() || Vivid.Input.Input.KeyIn(OpenTK.Input.Key.E))
                {
                    CurSlot++;
                    if (CurSlot == 3)
                    {
                        CurSlot = 0;
                    }
                    if (Slots[CurSlot] == null)
                    {
                        CurSlot = 0;
                    }
                    changedSlot = true;
                    RebuildWeaponHud();
                    Songs.PlaySource(ChangeSrc, false);
                }
            }
            else
            {
                if (XIn.DLeft() == false && XIn.DRight() == false && Input.KeyIn(OpenTK.Input.Key.Q) == false && Input.KeyIn(OpenTK.Input.Key.E) == false)
                {
                    changedSlot = false;
                }
            }

            switch (State)
            {
            case ScopeState.Idle:
                if (CurAnim != Anims["Idle1"])
                {
                    SetAnim("Idle1");
                }
                break;

            case ScopeState.Walking:
                if (CurAnim != Anims["Walk1"])
                {
                    SetAnim("Walk1");
                }
                break;

            case ScopeState.Running:
                if (CurAnim != Anims["Run1"])
                {
                    SetAnim("Run1");
                }
                break;
            }

            base.Update();
            ImgFrame = GetAnimFrame();

            float xm = XIn.LeftX();

            if (Vivid.Input.Input.MB[0] && !ShotAlready && Environment.TickCount > (lastShot + 800))
            {
                var shotSpr = Slots[CurSlot].GetNew();
                shotSpr.X = AimSprite.X;
                shotSpr.Y = AimSprite.Y;
                Graph.Add(shotSpr);
                Graph.Add(shotSpr.Light1);

                shotSpr.XM = (float)Math.Cos(aimAngle);
                shotSpr.YM = (float)Math.Sin(aimAngle);

                ShotAlready = true;
                lastShot    = Environment.TickCount;
            }
            if (Vivid.Input.Input.MB[0] == false)
            {
                ShotAlready = false;
            }

            if (Vivid.Input.Input.KeyIn(OpenTK.Input.Key.A))
            {
                xm = -1;
            }

            if (Vivid.Input.Input.KeyIn(OpenTK.Input.Key.D))
            {
                xm = 1;
            }


            xm = xm * 0.4f;

            if (XIn.bX() || Input.KeyIn(OpenTK.Input.Key.Space))
            {
                if (onGround && Environment.TickCount > (lastJump + 500))
                {
                    Move2D(0, -10);
                    onGround = false;
                    //State = ScopeState.Jumping;
                    Y = Y - 10;

                    lastJump = Environment.TickCount;
                }
            }

            if (XIn.leftB() || Input.KeyIn(OpenTK.Input.Key.ShiftLeft))
            {
                xm = xm * 2;

                if (Math.Abs(xm) > 0)
                {
                    State = ScopeState.Running;
                }
            }
            else
            {
                if (Math.Abs(xm) > 0)
                {
                    State = ScopeState.Walking;
                }
                else
                {
                    State = ScopeState.Idle;
                }
            }

            if (Math.Abs(xm) < 0.2)
            {
                State = ScopeState.Idle;
            }
            else
            {
                //State = ScopeState.Walking;
            }

            Move2D(xm * 0.35f, 0);

            if (xm > 0)
            {
                FlipDrawX = false;
            }
            else if (xm < 0)
            {
                FlipDrawX = true;
            }

            //X = X + xm;
            var cm = Graph.CreateCollisionMap(0.05f);


            Graph.StoreCam();
            Graph.X   = 0;
            Graph.Y   = 0;
            Graph.Z   = 1;
            Graph.Rot = 0;
            float cx = this.RealX;
            float cy = this.RealY;

            Graph.RestoreCam();


            if (Environment.TickCount > (lastJump + 500))
            {
                var hit = cm.RayCast(cx, cy, cx, cy + 32);

                if (hit == null)
                {
                    //X = hit.HitX;
                    Move2D(0, 0.3f);
                    onGround = false;
                }
                else
                {
                    //Y =
                    //Y = hit.HitY - 40;
                    Yi       = 0;
                    onGround = true;

                    /*
                     * Environment.Exit(1);
                     * float dis = hit.HitY - 32;
                     *
                     * dis = Math.Abs((dis - Y));
                     *
                     *
                     * if (dis < 32)
                     * {
                     *
                     *  Yi = 0;
                     *  Y = cy; // hit.HitY - 32 * Graph.Z;
                     *  onGround = true;
                     * }
                     */
                }
            }

            //Rot += 0.1f;

            //vironment.Exit(1);
            //base.Update();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: VividMaster/StarKnights
            public override void InitApp() 
            {
               
                Img1 = new Tex2D("Data/ship1.png", true);
                fx = new FXLitImage();
                G1 = new SceneGraph();
                S1 = new GraphSprite("Data/ship1.png", 128, 128);
                var t1 = new Tex2D("Data/tile1.jpg");

                for (int y = 0; y < 32; y++)
                {
                    for (int x = 0; x < 32; x++)
                    {

                        var ns = new GraphSprite(t1, 128, 128);
                        G1.Add(ns);
                        ns.X = -(128 * 16) + x * 128;
                        ns.Y = -(128 * 16) + y * 128;
                        ns.Z = 1.0f;
                    }
                }
                G1.Add(S1);
                S1.X = 0;
                S1.Y = 0;

                // G1.X = -16 * 32;
                //  G1.Y = 16 * 32;
                S1.X = 0;
                S1.Y = 0;
                S1.Z = 1.3f;
                // G1.Add(S1);

                var rnd = new Random();
                for (int i = 0; i < 25; i++)
                {

                    var ns = new GraphSprite(S1.ImgFrame, 128, 128);
                    ns.X = rnd.Next(-500, 500);
                    ns.Y = rnd.Next(-500, 500);
                    ns.Z = 0.1f + (float)rnd.NextDouble() * 3;
                    //    G1.Add(ns);

                }

                l1 = new GraphLight()
                {
                    Range = 650,
                    X = -100,
                    Y = -100,
                    Diffuse = new Vector3(0.4f, 1, 0.5f)
                };
                l2 = new GraphLight()
                {
                    Range = 640,
                    X = 0,
                    Y = 0,
                    Diffuse = new Vector3(1.8f, 1.2f, 1.2f)
                };
                G1.X = 0;
                G1.Y = 0;
                G1.Add(l1);
                l2.X = 300;
                VisualFX.Init();
                PS1 = new VFXParticleSystem();
                VisualFX.Add(PS1);
                VisualFX.Graph = G1;

                Part1 = new Tex2D("Data/part1.png", true);

               // var b1 = new
                    
                
                var b1 = new SoftParticle(Part1);
                b1.XDrag = 0.95f;
                b1.YDrag = 0.95f;
                b1.ZDrag = 0.95f;
                b1.RDrag = 0.95f;
                PS1.XIJit = 5;
                PS1.YIJit = 2;

                PS1.PowerSmall = 1;
                PS1.PowerBig = 5;

                PS1.AddBase(b1);
                

            }
コード例 #6
0
        private void starButton2_ClickButton(object sender, EventArgs e)
        {
            Random r      = new Random(int.Parse(SeedBox.Text));
            int    uw     = 2048;
            int    uh     = 2048;
            int    pg     = (uw + uh) / 120;
            int    numgal = r.Next(pg / 2, pg);

            var uniscene = new SceneGraph();

            uniscene.Root.Name = "Universe Root";
            int bs = r.Next(100, 200);

            var ul = new GraphLight();

            ul.Name    = "Universe Light 1";
            ul.Range   = 3000;
            ul.Diffuse = new OpenTK.Vector3(3, 3, 3);
            uniscene.Add(ul);

            for (int i = 0; i < bs; i++)
            {
                int x  = r.Next(-uw / 2, uw / 2);
                int y  = r.Next(-uh / 2, uh / 2);
                var sn = new GraphNode();
                sn.X        = x;
                sn.Y        = y;
                sn.Rot      = r.Next(0, 360);
                sn.Z        = 0.1f + (float)r.NextDouble() * 1.2f;
                sn.Name     = "BgStar" + i.ToString();
                sn.ImgFrame = BgStarImg[r.Next(0, BgStarImg.Length - 1)];
                uniscene.Root.Nodes.Add(sn);
                sn.Root  = uniscene.Root;
                sn.Graph = uniscene;
            }

            for (int i = 0; i < numgal; i++)
            {
                int x  = r.Next(-uw / 2, uw / 2);
                int y  = r.Next(-uh / 2, uh / 2);
                var gn = new GraphNode();
                gn.X        = x;
                gn.Y        = y;
                gn.Z        = 0.3f + (float)r.NextDouble() * 1.5f;
                gn.Rot      = r.Next(0, 360);
                gn.Name     = "Galaxy:" + i;
                gn.ImgFrame = GalImg[r.Next(0, GalImg.Length - 1)];
                uniscene.Root.Nodes.Add(gn);
                gn.Root  = uniscene.Root;
                gn.Graph = uniscene;
            }

            if (new FileInfo("Data/Uni/UniGraph.graph").Exists)
            {
                File.Delete("Data/Uni/UniGraph.graph");
            }

            var ufs = new VirtualFileSystem();

            ufs.Add(uniscene);
            ufs.Save("Data/Uni/UniGraph", true);
            Console.WriteLine("Wrote unifs");

            //uniscene.Save("Data/Uni/UniGraph.graph");
            Console.WriteLine("Universed created and saved.");
        }