/// <summary> /// Allows the app to run logic such as updating the world, /// checking for collisions, gathering input and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (ApplicationServices.WindowAvailability != WindowAvailability.Unavailable) { if (ApplicationServices.WindowAvailability == WindowAvailability.Interactive) { // TODO: Process touches, // use the following code to get the state of all current touch points. // ReadOnlyTouchPointCollection touches = touchTarget.GetState(); ReadOnlyTouchPointCollection touches = touchTarget.GetState(); if (CurrentState == GameState.play) // si on est en cours de partie { refreshGameState(); // on rafraichit la liste des objets à afficher if (DrawableObjects.ContainsKey("greenlights")) // affichage des feux de départ { GreenLights gl = (GreenLights)DrawableObjects["greenlights"]; if (gameTime.TotalGameTime.Seconds > gl.last_update + 1) // ils disparaissent au bout d'une seconde { DrawableObjects.Remove("greenlights"); } } List<String> detectedTags = new List<string>(); foreach (var t in touches) // création de la liste des tags posés { if (t.IsTagRecognized) { detectedTags.Add(t.Tag.Value.ToString()); if (!TagValues.ContainsKey(t.Tag.Value.ToString())) { TagValues.Add(t.Tag.Value.ToString(), t); // envoi de l'évent au serveur string data = wc.DownloadString(serverURL + "put_tag/" + t.Tag.Value.ToString() + "/" + t.CenterX / scale + "/" + t.CenterY / scale + "/" + t.Orientation); } } else // un doigt ou un blob { string data = wc.DownloadString(serverURL + "blob/" + t.CenterX / scale + "/" + t.CenterY / scale); } } List<string> tagsToDelete = new List<string>(); foreach (String tagV in TagValues.Keys) // et on supprime ceux qui ont été enlevés { if (!detectedTags.Contains(tagV)) { tagsToDelete.Add(tagV); string data = wc.DownloadString(serverURL + "remove_tag/" + tagV); } } foreach (String tagV in tagsToDelete) { TagValues.Remove(tagV); } } else if (CurrentState == GameState.menu) // si on est dans le menu. { bool isTrackSelected = false; foreach (var t in touches) { //spriteBatch.DrawString(spriteFont, "x : " + t.X + " y : " + t.Y, new Vector2(t.X, t.Y), Color.Black); if (t.Y > 200 && t.Y < 400) //Première ligne { if (t.X > 100 && t.X < 600) // 1ere colonne { selectedTrack = Background.Track.Classic; isTrackSelected = true; } else if (t.X > 700 && t.X < 1200) { selectedTrack = Background.Track.RainbowRoad; isTrackSelected = true; } else if (t.X > 1300 && t.X < 1850) { selectedTrack = Background.Track.City; isTrackSelected = true; } } else if (t.Y > 600 && t.Y < 875) //deuxième ligne { if (t.X > 100 && t.X < 600) // 1ere colonne { } else if (t.X > 700 && t.X < 1200) { } else if (t.X > 1300 && t.X < 1850) { } } } if (isTrackSelected) // si le joueur à cliqué sur un circuit. { CurrentState = GameState.waiting; Background trackBackground = new Background(new Vector2(0, 0), selectedTrack); trackBackground.LoadContent(this.Content); DrawableObjects["background"] = trackBackground; //envoyer circuit choisi au serveur. (/track/nomDuCircuit) string trackName = "none"; switch (selectedTrack) { case Background.Track.Classic: trackName = "classic"; break; case Background.Track.RainbowRoad: trackName = "rainbow"; break; case Background.Track.City: trackName = "city"; break; } string data = wc.DownloadString(serverURL + "track/" + trackName); } } else if (CurrentState == GameState.waiting) // état en attente du départ (après sélection du circuit et avant le départ) { refreshGameState(); GreenLights gl; if (DrawableObjects.ContainsKey("greenlights")) { gl = (GreenLights)DrawableObjects["greenlights"]; } else { Console.WriteLine("new lights"); gl = new GreenLights(); gl.LoadContent(this.Content); DrawableObjects.Add("greenlights", gl); } switch (gl.currentState) // mise à jour des feux de départ toute les secondes. { case GreenLights.GLState.Waiting: foreach (var t in touches) { if (t.Y > 220 && t.Y < 860 && t.X > 640 && t.X < 1280) //clic sur le drapeau { gl.currentState = GreenLights.GLState.R3; gl.last_update = gameTime.TotalGameTime.Seconds; } } break; case GreenLights.GLState.R3: if (gameTime.TotalGameTime.Seconds > gl.last_update + 1) { gl.currentState = GreenLights.GLState.R2; gl.last_update = gameTime.TotalGameTime.Seconds; } break; case GreenLights.GLState.R2: if (gameTime.TotalGameTime.Seconds > gl.last_update + 1) { gl.currentState = GreenLights.GLState.R1; gl.last_update = gameTime.TotalGameTime.Seconds; } break; case GreenLights.GLState.R1: if (gameTime.TotalGameTime.Seconds > gl.last_update + 1) { gl.currentState = GreenLights.GLState.GO; gl.last_update = gameTime.TotalGameTime.Seconds; CurrentState = GameState.play; string data = wc.DownloadString(serverURL + "start"); } break; } } } // TODO: Add your update logic here } base.Update(gameTime); }
/// <summary> /// Allows the app to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here Console.WriteLine("Initialisation du jeu"); loadConfig(); Background bBackground = new Background(new Vector2(0, 0), Background.Track.Menu); DrawableObjects.Add("background", bBackground); IsMouseVisible = true; // easier for debugging not to "lose" mouse SetWindowOnSurface(); InitializeSurfaceInput(); // Set the application's orientation based on the orientation at launch currentOrientation = ApplicationServices.InitialOrientation; // Subscribe to surface window availability events ApplicationServices.WindowInteractive += OnWindowInteractive; ApplicationServices.WindowNoninteractive += OnWindowNoninteractive; ApplicationServices.WindowUnavailable += OnWindowUnavailable; // Setup the UI to transform if the UI is rotated. // Create a rotation matrix to orient the screen so it is viewed correctly // when the user orientation is 180 degress different. Matrix inverted = Matrix.CreateRotationZ(MathHelper.ToRadians(180)) * Matrix.CreateTranslation(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height, 0); if (currentOrientation == UserOrientation.Top) { screenTransform = inverted; } base.Initialize(); }