void Ecouter() { UdpClient listener = new UdpClient(Port); listener.EnableBroadcast = true; IPEndPoint client = new IPEndPoint(IPAddress.Any, Port); while (true) { byte[] data = listener.Receive(ref client); if (client.Address.ToString() != "127.0.0.1") { object c = Serializer.GetObjectFromBytes <object>(data); if (c is PlayerInfo) { PlayerInfo cam = c as PlayerInfo; Console.WriteLine("Données reçues en provenance de {0} : {1}.", client.Address, client.Port); if (JoueurDeux == null) { JoueurDeux = new Player(Jeu, "Superboy", "Default Take", "Lambent_Femal", 1, new Vector3(-MathHelper.PiOver2, 0, 0), new Vector3(-5, 0.5f, -5), 15f, "jump", "landing", "walk", "walk_slow", PlayerIndex.One, false, 5001, ""); Jeu.Components.Add(JoueurDeux); } JoueurDeux.Position = cam.Position; JoueurDeux.PreviousPosition = cam.PreviousPosition; JoueurDeux.Rotation = cam.Rotation; } if (c is ZombieInfo) { ZombieInfo z = c as ZombieInfo; if (z.ShouldCreate) { BandeDeZombies.Add(new Zombie(Game, z.NomModèle, z.ÉchelleInitiale, z.Position, z.NomTexture, z.Rotation, z.IntervalleMAJ, z.Grognement, z.NomAnim, z.Vitesse, z.Numéro)); } else { BandeDeZombies[z.Numéro].Rotation = z.Rotation; BandeDeZombies[z.Numéro].Position = z.Position; } } if (c is ObjetTournoyantInfo) { ObjetTournoyantInfo o = c as ObjetTournoyantInfo; if (o.ShouldCreate) { Clé = new ObjetTournoyant(Jeu, "key", 0.01f, o.Rotation, o.Position, 1 / 60f, Port, "", false); Game.Components.Add(Clé); } else if (o.ShouldRemove) { Game.Components.Remove(Clé); } } } } }
public override void Update(GameTime gameTime) { if (PreviousPosition != Position) { AnimationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); } else { AnimationPlayer.Update(new TimeSpan(0, 0, 0), true, Matrix.Identity); } PreviousPosition = Position; float TempsÉcoulé = (float)gameTime.ElapsedGameTime.TotalSeconds; CurrentGamePad = GamePad.GetState(PlayerIndex); CurrentMouseState = Mouse.GetState(); if (GestionInput.EstManetteActivée) { GérerManette(TempsÉcoulé); } else if (GestionInput.EstSourisActive || GestionInput.EstClavierActivé) { GérerControlePC(TempsÉcoulé); } else { GestionSons.PauseSoundEffect(NomMarcheLente); GestionSons.PauseSoundEffect(NomMarche); } if (!PeutSauter) { VitesseSaut += TempsÉcoulé * GRAVITY; PositionCamera.Y += VitesseSaut; CaméraJeu.CameraLookAt.Y += VitesseSaut; } if (PositionCamera.Y < PositionInitialeCamera - 1) { VitesseSaut = ASCEND_JUMP_SPEED; Remonte = true; } // je peux surement mettre les deux methode ensemble if (Remonte) { GestionSons.Play(NomLandingSon, false, VOLUME_FAIBLE); VitesseSaut -= (TempsÉcoulé * GRAVITY); PositionCamera.Y += VitesseSaut; CaméraJeu.CameraLookAt.Y += VitesseSaut; if (PositionCamera.Y > PositionInitialeCamera) { float ajusterVue = CaméraJeu.CameraLookAt.Y - PositionCamera.Y; PositionCamera.Y = PositionInitialeCamera; CaméraJeu.CameraLookAt.Y = ajusterVue + PositionCamera.Y; PeutSauter = true; Remonte = false; } } // a voir ZoneCollisionPowerUps = new BoundingSphere(Position, RAYON_COLLISION); ZoneBruit = new BoundingSphere(Position, RAYON_ZONE_BRUIT); foreach (GameComponent c in Game.Components) { if (c is ObjetTournoyant) { ObjetTournoyant o = c as ObjetTournoyant; if (GestionCollisions.CollisionJoueurObjet(o.ZoneCollision, ZoneCollisionPowerUps)) { Game.Components.Remove(c); LampeDePoche.TempsÉcouléeDepuisBatterieTrouvée = 0; break; } } } Frustum = new BoundingFrustum(Matrix.Multiply(View, Projection)); if (IsCurrentPlayer) { PlayerInfo p = new PlayerInfo(Position, Rotation, PreviousPosition, Port, IP); } CalculerMonde(); base.Update(gameTime); }