Пример #1
0
        private static void Main(string[] args)
        {
            #region Variables
            if (args.Length == 3 && args[0] == "-r" && int.TryParse(args[1], out resolution[0]) &&
                int.TryParse(args[2], out resolution[1])) { }
            int menu_running = 1;
            // 0 -> jeu en cours
            // 1 -> menu de demarrage
            // 2 -> menu de jeu
            #endregion

            #region Fenêtre
            form = new RenderForm("Underground - Horror game");
            form.Width = resolution[0];
            form.Height = resolution[1];

            // Intro
            panel1 = new Panel();
            panel1.Name = "panel1";
            panel1.Size = new System.Drawing.Size(resolution[0], resolution[1]);
            panel1.TabIndex = 1;
            form.Controls.Add(panel1);

            m_play = new DxPlay(panel1, @"Ressources\Video\UndergroundPS.avi");
            //m_play = new DxPlay(panel1, @"Ressources\Video\UndergrounFinal_Introduction_vidonly.avi");

            // Fonction à éxécuter après
            m_play.StopPlay += new DxPlay.DxPlayEvent(MediaPlayer.Fin_intro);

            Direct3D direct3D = new Direct3D();
            PresentParameters Parametres = new PresentParameters(
                form.Width,
                form.Height,
                Format.X8R8G8B8,
                1,
                MultisampleType.None,
                0,
                SwapEffect.Discard,
                IntPtr.Zero,
                true,
                true,
                Format.D24X8,
                PresentFlags.None,
                0,
                PresentInterval.Immediate);
            input = new Input(form);
            device = new Device(direct3D, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, Parametres);
            vertexElems3D = new[] {
                new VertexElement(0, // POSITION
                    0,
                    DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                new VertexElement(0, // TEXCOORD0
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()),
                    DeclarationType.Float2, DeclarationMethod.Default,DeclarationUsage.TextureCoordinate,0),
                new VertexElement(0, // COLOR0
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector2>()),
                    DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                new VertexElement(0, // NORMAL0
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector2>()+Utilities.SizeOf<Vector4>()),
                    DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
                new VertexElement(0, // TANGENT
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector2>()+Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector4>()),
                    DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
                VertexElement.VertexDeclarationEnd,
                new VertexElement(0, // booléen de bump mapping
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector2>()+Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector4>()),
                    DeclarationType.Float1, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                VertexElement.VertexDeclarationEnd,
            };
            vertexElems2D = new[] {
                new VertexElement(0,0,DeclarationType.Float4,DeclarationMethod.Default,DeclarationUsage.PositionTransformed,0),
                new VertexElement(0,16,DeclarationType.Float2,DeclarationMethod.Default,DeclarationUsage.TextureCoordinate,0),
                VertexElement.VertexDeclarationEnd
            };

            VertexDeclaration3D = new VertexDeclaration(Program.device, Program.vertexElems3D);
            VertexDeclaration2D = new VertexDeclaration(Program.device, Program.vertexElems2D);
            VertexBufferZero = new VertexBuffer(IntPtr.Zero);

            device.VertexDeclaration = VertexDeclaration3D;

            Program.device.SetRenderState(RenderState.AlphaBlendEnable, true); // graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true;
            Program.device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); // graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One;
            Program.device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); // graphics.GraphicsDevice.RenderState.SourceBlend = Blend.One;
            Program.device.SetRenderState(RenderState.AlphaFunc, BlendOperation.Maximum); // graphics.GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add;
            Program.device.SetRenderState(RenderState.AlphaTestEnable, true);
            Program.device.SetRenderState(RenderState.MinTessellationLevel, 8);
            #endregion

            Liste_textures = new List<structTexture>();
            Liste_binaires = new List<structBinary>();
            Liste_OBJ = new List<structOBJ>();
            Liste_Lights = new Light[2];
            Liste_Lights[0].Type = LightType.Point;
            Liste_Lights[0].Position = new Vector3(0, 0, 0);
            Liste_Lights[0].Ambient = new Color4(0.5f, 0.5f, 0.5f, 1);
            Liste_Lights[0].Range = 30f * 70;
            Liste_Lights[1].Type = LightType.Point;
            Liste_Lights[1].Position = new Vector3(-100, -100, -100);
            Liste_Lights[1].Ambient = new Color4(0.5f,0,0,1);
            Liste_Lights[1].Range = 5f * 70;
            Liste_textures.Add(new structTexture("null.bmp", Texture.FromFile(device, "null.bmp")));
            //Ingame.Slender.doit_etre_recharge = true;

            // Creation du fichier effect de référence
            Macro macro = new Macro("nblights", 2.ToString());
            BaseEffect = Effect.FromFile(Program.device, "Underground.fx", new Macro[] { macro }, null, "", ShaderFlags.OptimizationLevel3);
            BaseEffect.Technique = BaseEffect.GetTechnique(0);
            BaseEffect.SetValue("AmbientLightColor", new Vector4(0f, 0f, 0f, 0f));
            Matrix proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, Program.form.ClientSize.Width / (float)Program.form.ClientSize.Height, 0.1f, 7000.0f);
            BaseEffect.SetValue("Projection", proj);
            BaseEffect.SetValue("LightDiffuseColor[0]", Liste_Lights[0].Ambient);
            BaseEffect.SetValue("LightDiffuseColor[1]", Liste_Lights[1].Ambient);
            BaseEffect.SetValue("LightDistanceSquared[1]", Liste_Lights[1].Range);

            Thread ThSound = new Thread(Sound.main);
            Thread ThEvents = new Thread(Ingame.fevents);
            ThSound.Start();
            ThEvents.Start();

            Menu.Initialize_Menu();
            ObjLoader.Initialize();
            newmaze = new Maze(10, 10);
            newmaze.Initecelles();
            newmaze.Generate(newmaze.maze[0, 0]);
            newmaze.impefectGenerate();
            newmaze.Setaffichage();

            Ingame.ingame();

            Menu.Dispose();
            ThSound.Abort();
            ThEvents.Abort();
            VertexBufferZero.Dispose();
            VertexDeclaration3D.Dispose();
            VertexDeclaration2D.Dispose();
            device.Dispose();
            direct3D.Dispose();
        }