Esempio n. 1
0
        protected override void Initialize()
        {
            GestionInput = new InputManager(this);
            Services.AddService(typeof(InputManager), GestionInput);
            //serveur



            readStream  = new MemoryStream();
            writeStream = new MemoryStream();

            reader = new BinaryReader(readStream);
            writer = new BinaryWriter(writeStream);

            //
            //joueur
            enemy  = new Maison(this, 1f, Vector3.Zero, Vector3.Zero, INTERVALLE_MAJ_STANDARD);
            player = new Maison(this, 1f, Vector3.Zero, Vector3.Zero, new Vector3(5f, 5f, 5f), "brique1", "roof", INTERVALLE_MAJ_STANDARD);
            Vector3 positionCaméra = new Vector3(200, 10, 200);
            Vector3 cibleCaméra    = new Vector3(10, 0, 10);

            ListeSections = new List <Section>();

            Components.Add(GestionInput);
            CaméraJeu = new CaméraSubjective(this, positionCaméra, cibleCaméra, Vector3.Up, INTERVALLE_MAJ_STANDARD);
            Components.Add(CaméraJeu);
            Sections = new List <Section>();
            Components.Add(new Afficheur3D(this));
            //Components.Add(new ArrièrePlanDéroulant(this, "CielÉtoilé", INTERVALLE_MAJ_STANDARD));
            for (int i = 0; i < 2; ++i)
            {
                for (int j = 0; j < 2; ++j)
                {
                    Section newSection = new Section(this, new Vector2(200 * i, 100 * j), new Vector2(200, 200), 1f, Vector3.Zero, Vector3.Zero, new Vector3(200, 25, 200), new string[] { "Herbe", "Sable" }, INTERVALLE_MAJ_STANDARD);
                    Sections.Add(newSection);
                    ListeSections.Add(newSection);
                }
            }
            foreach (Section s in ListeSections)
            {
                Components.Add(s);
            }

            //Components.Add(new Terrain(this, 1f, Vector3.Zero, Vector3.Zero, new Vector3(256, 25, 256), "GrandeCarte", "DétailsTerrain", 5, INTERVALLE_MAJ_STANDARD));
            //Components.Add(new Terrain(this, 1f, Vector3.Zero, Vector3.Zero, new Vector3(200, 25, 200), "CarteTest", "DétailsTerrain", 5, INTERVALLE_MAJ_STANDARD));
            Components.Add(new AfficheurFPS(this, "Arial20", Color.Red, INTERVALLE_CALCUL_FPS));
            Components.Add(new Piste(this, 1f, Vector3.Zero, Vector3.Zero, INTERVALLE_MAJ_STANDARD, 20000, 20000));

            //Services.AddService(typeof(Random), new Random());
            Services.AddService(typeof(RessourcesManager <SpriteFont>), new RessourcesManager <SpriteFont>(this, "Fonts"));
            Services.AddService(typeof(RessourcesManager <Texture2D>), new RessourcesManager <Texture2D>(this, "Textures"));
            Services.AddService(typeof(Caméra), CaméraJeu);
            Services.AddService(typeof(DataPiste), new DataPiste("SplineX.txt", "SplineY.txt"));
            GestionSprites = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), GestionSprites);
            Components.Add(player);
            base.Initialize();
        }
Esempio n. 2
0
        private void ProcessData(byte[] data)
        {
            readStream.SetLength(0);
            readStream.Position = 0;
            readStream.Write(data, 0, data.Length);
            readStream.Position = 0;

            Protocoles p;

            //try
            //{
            p = (Protocoles)reader.ReadByte();

            if (p == Protocoles.Connected)
            {
                if (!enemyConnected)
                {
                    byte   id = reader.ReadByte();
                    string ip = reader.ReadString();
                    enemyConnected = true;
                    enemy          = new Maison(this, 1f, Vector3.Zero, new Vector3(0, 0, 5), new Vector3(5f, 5f, 5f), "PlayerPaper", "EnemyPaper", INTERVALLE_MAJ_STANDARD);
                    Components.Add(enemy);


                    writeStream.Position = 0;
                    writer.Write((byte)Protocoles.Connected);
                    SendData(GetDataFromMemoryStream(writeStream));
                }
            }
            else if (p == Protocoles.Disconnected)
            {
                byte   id = reader.ReadByte();
                string ip = reader.ReadString();
                enemyConnected = false;
            }
            else if (p == Protocoles.PlayerMoved)
            {
                float  X  = reader.ReadSingle();
                float  Y  = reader.ReadSingle();
                float  Z  = reader.ReadSingle();
                byte   id = reader.ReadByte();
                string ip = reader.ReadString();
                enemy.Position = new Vector3(enemy.Position.X + X, enemy.Position.Y + Y, enemy.Position.Z + Z);
                enemy.CalculerMatriceMonde();
            }
            //}
            //catch (Exception exception)
            //{
            //    MessageBox.Show(exception.Message + "2");
            //}
        }
Esempio n. 3
0
 private void CréerMaisons()
 {
     if (ContientMaison && Piste.NbPtsCentraux > 0)
     {
         List <Vector2> vecteursPerpendiculaires = Piste.ObtenirVecteurPerp();
         for (int i = 0; i < vecteursPerpendiculaires.Count; i += 2)
         {
             Vector2 temp   = 4 * vecteursPerpendiculaires[i] + vecteursPerpendiculaires[i + 1];
             Maison  maison = new Maison(Game, HOMOTHÉTIE_MAISON, Vector3.Zero, new Vector3(temp.X, 0, temp.Y), new Vector3(2, 2, 2), "brique1", "roof", 0.01f);
             Components.Add(maison);
             Game.Components.Add(maison);
         }
     }
 }