Ejemplo n.º 1
0
        public static void recup_env()
        {
            // Transformation des coordonnées dans l'espaces aux coordonnées du laby de Charles
            int a = ((int)macamera.position.X + rayon_salles) / (2 * rayon_salles);
            int b = ((int)macamera.position.Z + rayon_salles) / (2 * rayon_salles);
            ab_stay_in_bounds(ref a, ref b);
            RoomsBuilder RoomsBuilder = new RoomsBuilder();
            PlaceMonster PlaceMonster = new PlaceMonster();
            //string pathL = @"Ressources\Game\C(L).obj";
            //string pathX = @"Ressources\Game\C(X).obj";
            //string pathIf = @"Ressources\Game\C(If).obj";
            //string pathT = @"Ressources\Game\C(T).obj";
            //string path2 = @"Ressources\Game\cabine.obj";
            string pathStatue = @"Ressources\Game\statue.obj";
            //string pathStatue = @"Ressources\Game\sql5_000049.obj";
            if (Slender.doit_etre_recharge)
            {
                Slender.doit_etre_recharge = false;
                Program.freeModel(new Point(-137, -137), true, false);
                if (Slender.seraaffiche)
                {
                    compteur_slender = compteur_slender % 4 + 1;
                    float ang;
                    Slender.position = PlaceMonster.GetPositionMonster(out ang);
                    if (first_loop)
                    {
                        first_loop = false;
                        Slender.position = new Vector3(30000, 30000, 30000);
                    }
                    Program.Liste_Lights[1].Position = new Vector3(Slender.position.X, Slender.position.Y + 100, Slender.position.Z);
                    Program.getModel(pathStatue,
                                     Matrix.Scaling(2f * 75/*10*/) * Matrix.RotationY(ang) *
                                     Matrix.Translation(Slender.position), new Point(-137, -137));
                }
                else
                {
                    compteur_slender = 1;
                }
            }

            /// RECHERCHE S'IL Y A DES SALLES QUI DOIVENT ETRE CHARGEES PUIS RECHARGEES DE SUITE APRES ///
            //try
            //{
            // Recupere la liste des cases vues
            ////Console.WriteLine("Zone [{0},{1}] [{2},{3}]", a, b, macamera.position.X, macamera.position.Z);
            List<Case> cases = new List<Case>(Program.newmaze.maze[a, b].see);

            // Init
            bool[] idadecharger = new bool[previous_cases.Count];
            for (int i = 0; i < previous_cases.Count; i++)
            {
                idadecharger[i] = true;
            }

            // Recupere la liste des cases à décharger
            for (int i = 0; i < cases.Count; i++)
            {
                for (int j = 0; j < previous_cases.Count && cases.Count != 0; j++)
                {
                    if (previous_cases[j].x == cases[i].x && previous_cases[j].y == cases[i].y && idadecharger[j] == true)
                    {
                        idadecharger[j] = false;
                        cases.RemoveAt(i);
                        i--;
                        break;
                    }
                }
            }

            // Decharge les cases à être déchargées
            for (int i = 0; i < previous_cases.Count; i++)
            {
                if (idadecharger[i])
                {
                    Program.freeModel(new Point(previous_cases[i].x, previous_cases[i].y), true, false);
                    previous_cases.RemoveAt(i);
                    i--;
                }
            }

            // sauvegarde des cases
            previous_cases.AddRange(cases);
            // Charges les nouvelles cases
            for (int i = 0; i < cases.Count; i++)
            {
                if (cases[i].type == 3) // L
                {
                    RoomsBuilder.buildLRoom(rayon_salles, cases[i]);
                    /*Program.getModel(@"Ressources\Game\C(L).obj", Matrix.RotationY((float)Math.PI / 2 * (cases[i].rot - 1))
                                     * Matrix.Translation(
                                        -(2 * rayon_salles) * cases[i].x,
                                        0,
                                        -(2 * rayon_salles) * cases[i].y),
                                     new Point(cases[i].x, cases[i].y));*/
                }
                else if (cases[i].type == 2) // T
                {
                    RoomsBuilder.buildTRoom(rayon_salles, cases[i]);
                    /*Program.getModel(@"Ressources\Game\C(T).obj", Matrix.RotationY((float)Math.PI / 2 * (cases[i].rot - 1 + 1))
                                     * Matrix.Translation(
                                        -(2 * rayon_salles) * cases[i].x,
                                        0,
                                        -(2 * rayon_salles) * cases[i].y),
                                     new Point(cases[i].x, cases[i].y));*/
                }
                else if (cases[i].type == 4) // Io
                {
                    RoomsBuilder.buildIoRoom(rayon_salles, cases[i]);
                    /*Program.getModel(@"Ressources\Game\caca2.obj", Matrix.Scaling(30) * Matrix.RotationY((float)Math.PI / 2 * (cases[i].rot - 1 + 1))
                                     * Matrix.Translation(
                                        -(2 * rayon_salles) * cases[i].x,
                                        0,
                                        -(2 * rayon_salles) * cases[i].y),
                                     new Point(cases[i].x, cases[i].y));*/
                }
                else if (cases[i].type == 5) // If
                {
                    RoomsBuilder.buildIfRoom(rayon_salles, cases[i]);
                    /*Program.getModel(@"Ressources\Game\C(If).obj", Matrix.Scaling(30) * Matrix.RotationY((float)Math.PI / 2 * (cases[i].rot - 1 + 2))
                                     * Matrix.Translation(
                                        -(2 * rayon_salles) * cases[i].x,
                                        0,
                                        -(2 * rayon_salles) * cases[i].y),
                                     new Point(cases[i].x, cases[i].y));*/
                }
                else if (cases[i].type == 1) // X
                {
                    RoomsBuilder.buildXRoom(rayon_salles, cases[i]);
                    /*Program.getModel(@"Ressources\Game\C(X).obj", Matrix.Scaling(30) * Matrix.RotationY((float)Math.PI / 2 * (cases[i].rot - 1))
                                     * Matrix.Translation(
                                        -(2 * rayon_salles) * cases[i].x,
                                        0,
                                        -(2 * rayon_salles) * cases[i].y),
                                     new Point(cases[i].x, cases[i].y));*/
                }
            }
        }
Ejemplo n.º 2
0
        //> Color codes for WriteNicely :
        // 0: Black.
        // 1: DarkBlue.
        // 2: DarkGreen.
        // 3: DarkCyan.
        // 4: DarkRed.
        // 5: DarkMagenta.
        // 6: DarkYellow.
        // 7: Gray.
        // 8: DarkGray.
        // 9: Blue.
        //10: Green.
        //11: Cyan.
        //12: Red.
        //13: Magenta.
        //14: Yellow.
        //15: White.
        public static void ingame()
        {
            //Matrix view = Matrix.LookAtLH(new Vector3(0, 0, -0.00002f), new Vector3(0, 0, 0), Vector3.UnitY);
            List<structModelFiles> ModelFiles = new List<structModelFiles>();

            macamera = new Camera();
            HUD hud = new HUD();
            Stopwatch clock = new Stopwatch();
            clock.Start();

            Int64 previous_time = clock.ElapsedTicks;
            Int64 previous_clignement = clock.ElapsedTicks;
            Collision.Initialize();

            Matrix oldView = macamera.view;
            Vector3 oldPos = macamera.position;
            Vector3 oldAngle = macamera.angle;

            // Préchargement des salles
            RoomsBuilder RoomsBuilder = new RoomsBuilder();

            // MAXIMUM (impossible à otimiser)
            RoomsBuilder.buildIfRoom(400, new Case(0, Case.CaseType.If, new Point(-1, -1)));
            RoomsBuilder.buildIfRoom(400, new Case(0, Case.CaseType.If, new Point(-1, -1)));
            RoomsBuilder.buildIfRoom(400, new Case(0, Case.CaseType.If, new Point(-1, -1)));

            // MAXIMUM
            RoomsBuilder.buildLRoom(400, new Case(0, Case.CaseType.L, new Point(-1, -1)));
            RoomsBuilder.buildLRoom(400, new Case(0, Case.CaseType.L, new Point(-1, -1)));
            RoomsBuilder.buildLRoom(400, new Case(0, Case.CaseType.L, new Point(-1, -1)));
            RoomsBuilder.buildLRoom(400, new Case(0, Case.CaseType.L, new Point(-1, -1)));

            // pas de maximum
            RoomsBuilder.buildIoRoom(400, new Case(0, Case.CaseType.Io, new Point(-1, -1)));
            RoomsBuilder.buildIoRoom(400, new Case(0, Case.CaseType.Io, new Point(-1, -1)));
            RoomsBuilder.buildIoRoom(400, new Case(0, Case.CaseType.Io, new Point(-1, -1)));
            RoomsBuilder.buildIoRoom(400, new Case(0, Case.CaseType.Io, new Point(-1, -1)));

            // pas de maximum
            RoomsBuilder.buildTRoom(400, new Case(0, Case.CaseType.T, new Point(-1, -1)));
            RoomsBuilder.buildTRoom(400, new Case(0, Case.CaseType.T, new Point(-1, -1)));
            RoomsBuilder.buildTRoom(400, new Case(0, Case.CaseType.T, new Point(-1, -1)));
            RoomsBuilder.buildTRoom(400, new Case(0, Case.CaseType.T, new Point(-1, -1)));
            RoomsBuilder.buildTRoom(400, new Case(0, Case.CaseType.T, new Point(-1, -1)));

            // pas de maximum
            RoomsBuilder.buildXRoom(400, new Case(0, Case.CaseType.X, new Point(-1, -1)));
            RoomsBuilder.buildXRoom(400, new Case(0, Case.CaseType.X, new Point(-1, -1)));

            // On cache les salles préchargées
            Program.freeModel(new Point(-1, -1), true, false);

            // On lance la boucle de rendu
            RenderLoop.Run(Program.form, () =>
            {
                Program.device.BeginScene();

                if (!MediaPlayer.intro_finished)
                {
                    MediaPlayer.Intro();
                }
                else if (Menu.IsInMenu)
                {
                    Cursor.Show();
                    Program.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                    Menu.InMenu();
                }
                else
                {
                    Cursor.Hide();
                    recup_env();
                    //effect.SetValue("LightPosition", new Vector4(-macamera.position.X, macamera.position.Y, -macamera.position.Z, 1));
                    /*if (clock.ElapsedTicks - previous_clignement > 100000000) // 1 tick != 100ns (cf diff entre Date et Stopwatch) utiliser Stopwatch.Frequency
                    {
                        //Console.WriteLine(Stopwatch.Frequency);
                        previous_clignement = clock.ElapsedTicks;
                    }*/
                    oldAngle = macamera.angle;
                    Int64 timer = clock.ElapsedTicks - previous_time;
                    previous_time = clock.ElapsedTicks;
                    macamera.orient_camera(timer);

                    //--------------------------------------------------------
                    // Died
                    //--------------------------------------------------------
                    #region died
                    if (kill == false)
                    {
                        if (distanceSlender_var <= 100)
                        {
                            kill = true;
                            if (!Sound.dead.IsAlive)
                            {
                                if (Sound.dead.ThreadState == System.Threading.ThreadState.Stopped)
                                {
                                    Sound.soundContinue = true;
                                    Sound.dead = new Thread(Sound.bruitpas);
                                }
                                Sound.dead.Start();
                            }
                        }
                    }

                    if (kill == true)
                    {
                        Time.Start();

                        if (Time.ElapsedMilliseconds < 500)
                        {
                            macamera.position.Y += (0.000006f * Time.ElapsedMilliseconds) * 70;
                        }

                        else if (Time.ElapsedMilliseconds == 500)
                        {

                            if (stateinflash == 0)
                            {
                                stateinflash = -1;
                            }

                        }
                        else if ((Time.ElapsedMilliseconds > 1500) && (Time.ElapsedMilliseconds < 4650))
                        {
                            macamera.angle.Z -= (0.00000006f * Time.ElapsedMilliseconds);
                            macamera.angle.Y += 0.00000006f * Time.ElapsedMilliseconds;
                            macamera.position.Y += (0.00000006f * Time.ElapsedMilliseconds) * 70;
                        }

                        else if ((Time.ElapsedMilliseconds > 4650) && (Time.ElapsedMilliseconds < 4700))
                        {
                            macamera.angle.Z -= (0.0000006f * Time.ElapsedMilliseconds);
                            macamera.position.Y += (0.00000006f * Time.ElapsedMilliseconds) * 70;
                        }

                        else if ((Time.ElapsedMilliseconds > 4700) && (Time.ElapsedMilliseconds < 5200))
                        {
                            macamera.position.Y += (0.00000006f * Time.ElapsedMilliseconds) * 70;
                        }

                        else if (Time.ElapsedMilliseconds >= 5200)
                        {
                            if (stateinflash == 0)
                            {
                                stateinflash = -1;
                            }
                            //kill = false;
                            Time.Stop();
                            Time.Reset();
                            Thread.Sleep(1000);
                            Sound.dead.Abort();
                            Menu.IsInMenu = true;

                        }
                    }
                    #endregion
                    //--------------------------------------------------------
                    previous_time = clock.ElapsedTicks;

                    bool collide = Collision.CheckCollisions(macamera.position);
                    //collide = false;
                    if (collide)
                    {

                        macamera.position = oldPos;
                        oldView =
                            Matrix.Translation(oldPos.X, oldPos.Y + (float)Math.Sin(Ingame.sinusoide) / 45f * 70, oldPos.Z) *
                            Matrix.RotationAxis(new Vector3(0, 1, 0), macamera.angle.Y + Ingame.parasitesCamera[0]) *
                                Matrix.RotationAxis(new Vector3(1, 0, 0), macamera.angle.X + Ingame.parasitesCamera[1]) *
                                Matrix.RotationAxis(new Vector3(0, 0, 1), macamera.angle.Z);
                        macamera.view = oldView;

                    }
                    else
                    {
                        oldPos = macamera.position;
                        oldView = macamera.view;
                    }

                    Program.Liste_Lights[0].Position = -Ingame.macamera.position;
                    Program.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                    for (int k = 0; k < Program.Liste_OBJ.Count; k++)
                    {
                        Program.Liste_OBJ[k].effect.SetValue("LightPosition[0]", new Vector4(Program.Liste_Lights[0].Position, 1));
                        Program.Liste_OBJ[k].effect.SetValue("LightPosition[1]", new Vector4(Program.Liste_Lights[1].Position.X, Program.Liste_Lights[1].Position.Y + 2f, Program.Liste_Lights[1].Position.Z, 1));
                        Program.Liste_OBJ[k].effect.SetValue("LightDistanceSquared[0]", lightDistanceSquared0calcul);
                        Program.Liste_OBJ[k].effect.SetValue("LightDistanceSquared[1]", lightDistanceSquared1calcul);
                        Program.Liste_OBJ[k].effect.SetValue("percent_Negatif", percent_negatif);
                        Program.Liste_OBJ[k].effect.SetValue("View", macamera.view);
                        Program.Liste_OBJ[k].effect.SetValue("Sepia", Sepia);
                        Program.Liste_OBJ[k].effect.SetValue("luminosity", luminosity);
                        Program.Liste_OBJ[k].effect.Begin();
                        Program.Liste_OBJ[k].effect.BeginPass(0);
                        Program.Liste_OBJ[k].effect.SetValue("World", Program.Liste_OBJ[k].Transformation);
                        Program.Liste_OBJ[k].effect.SetValue("WorldInverseTranspose", Matrix.Transpose(Matrix.Invert(Program.Liste_OBJ[k].Transformation)));
                        for (int i = 0; i < Program.Liste_OBJ[k].data.Count; i++)
                        {
                            if (Program.Liste_OBJ[k].sera_affiche)
                            {
                                Program.device.SetStreamSource(0, Program.Liste_OBJ[k].data[i].VertexBuffer, 0, Utilities.SizeOf<structVertex>());
                                Program.device.SetTexture(0, Program.Liste_textures[Program.getTexture(Program.Liste_OBJ[k].data[i].map_Kd)].texture);
                                Program.device.SetTexture(1, Program.Liste_textures[Program.getTexture(Program.Liste_OBJ[k].data[i].map_Ns)].texture);
                                Program.device.DrawPrimitives(PrimType, 0, Program.Liste_OBJ[k].data[i].nbfaces);
                            }
                        }
                        Program.Liste_OBJ[k].effect.EndPass();
                        Program.Liste_OBJ[k].effect.End();
                    }
                    hud.Display_HUD();
                }
                Program.device.EndScene(); // Okay
                Program.device.Present();
            });
            Cursor.Show();
            Menu.Dispose();
            hud.Dispose();
            for (int k = 0; k < Program.Liste_OBJ.Count; k++)
            {
                for (int i = 0; i < Program.Liste_OBJ[k].data.Count; i++)
                {
                    Program.Liste_OBJ[k].data[i].VertexBuffer.Dispose();
                }
            }
            foreach (structTexture TextureElt in Program.Liste_textures)
            {
                TextureElt.texture.Dispose();
            }
            clock.Stop();
        }