/// <summary> /// Serialize the current instance and write the result into a specified XML writer. /// </summary> /// <param name="writer">The XML writer into which to write the serialized instance.</param> public void WriteXml(XmlWriter writer) { writer.WriteStartElement("YachtStep"); writer.WriteAttributeString("PlayerIndex", PlayerIndex.ToString()); writer.WriteAttributeString("ScoreLine", ScoreLine.ToString()); writer.WriteAttributeString("Score", Score.ToString()); writer.WriteAttributeString("StepNumber", StepNumber.ToString()); }
/// <summary> /// Draw a map with points for each level, and way between them /// </summary> /// <param name="spriteBatch"></param> /// <param name="Game"></param> public void Draw(TGPASpriteBatch spriteBatch) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); //Background spriteBatch.Draw(background, new Rectangle(0, 0, TGPAContext.Instance.ScreenWidth, TGPAContext.Instance.ScreenHeight), null, Color.White); Rectangle LastLevelDst = Rectangle.Empty; //Draw levels and a way between them for (int i = 0; i < WorldCount; i++) { //The player need to have unlocked the level to display it Rectangle levelDst = Rectangle.Empty; if ((i <= TGPAContext.Instance.Saver.SaveData.LastLevel) && (i < WorldCount)) { Vector2 loc = levelPositionOnMap[i]; levelDst = new Rectangle( (int)loc.X - levelSrc.Width / 2, (int)loc.Y - levelSrc.Height / 2, levelSrc.Width, levelSrc.Height ); Color levelColor = Color.White; Color blinkColor = Color.Gray * alphaColorForLevelBlinking; if ((selectedIndex == i) & (!shipIsMoving)) { levelColor = Color.Red; blinkColor = Color.OrangeRed * 0.0f; } else if (pointedIndex == i) { levelColor = Color.SpringGreen; blinkColor = Color.White * 0.0f; } else if (i == TGPAContext.Instance.Saver.SaveData.LastLevel) { blinkColor = Color.PaleVioletRed * alphaColorForLevelBlinking; } spriteBatch.Draw(buttons, levelDst, levelSrc, levelColor); spriteBatch.Draw(buttons, levelDst, levelSrc, blinkColor); //Draw the way if (i > 0) { Vector2 p1 = levelPositionOnMap[i - 1]; Vector2 p2 = pointsBezier[i - 1][0]; Vector2 p3 = pointsBezier[i - 1][1]; Vector2 p4 = levelPositionOnMap[i]; int requiredPoints = (int)(Math.Sqrt(Math.Pow(p4.X - p1.X, 2) + Math.Pow(p4.Y - p1.Y, 2)) / 50) + 2; //evaluate number of point to show depending of the distance between p1 an p4 Rectangle wayDst = waySrc; for (int x = 1; x < requiredPoints; x++) { float t = (float)x / (float)(requiredPoints); //quadratic bezier equation need a parameter t, with 0<=t<=1 if (t <= 1) { wayDst.X = (int)((Math.Pow(1 - t, 3)) * p1.X + 3 * (Math.Pow(1 - t, 2)) * t * p2.X + 3 * (1 - t) * t * t * p3.X + t * t * t * p4.X) - wayDst.Width / 2; wayDst.Y = (int)((Math.Pow(1 - t, 3)) * p1.Y + 3 * (Math.Pow(1 - t, 2)) * t * p2.Y + 3 * (1 - t) * t * t * p3.Y + t * t * t * p4.Y) - wayDst.Height / 2; spriteBatch.Draw(buttons, wayDst, waySrc, Color.White, 0.0f, new Vector2(waySrc.Width / 2, waySrc.Height / 2), SpriteEffects.None, 1.0f); } } } } } //Draw little ship spriteBatch.Draw(buttons, shipDst, shipSrc, Color.White, 0.0f, Vector2.Zero, shipFlip, 1.0f); //Draw selected world information Vector2 v = levelPositionOnMap[selectedIndex]; Color whiteColor = Color.White * alphaPostIt; spriteBatch.Draw(buttons, postitDst, postitSrc, whiteColor); //Play and back Buttonfor PC if (TGPAContext.Instance.Player1.IsPlayingOnWindows()) { //Launch game if (focus == LevelSelectionScreenButton.Play) { Rectangle srcBis = arrowSrc; srcBis.Y += srcBis.Height; spriteBatch.Draw(buttons, playDst, srcBis, whiteColor, 0.0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 1.0f); } else { spriteBatch.Draw(buttons, playDst, arrowSrc, whiteColor, 0.0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 1.0f); } //Back if (focus == LevelSelectionScreenButton.Back) { Rectangle srcBis = arrowSrc; srcBis.Y += srcBis.Height; spriteBatch.Draw(buttons, backDst, srcBis, whiteColor); } else { spriteBatch.Draw(buttons, backDst, arrowSrc, whiteColor); } } spriteBatch.End(); //Play and back text for PC if (TGPAContext.Instance.Player1.IsPlayingOnWindows()) { if (alphaPostIt > 0.8f) { playDst.X = 290; playDst.Y = 485; backDst.X = 90; backDst.Y = 555; string playText = "Play"; string backText = "Back to title"; TGPAContext.Instance.TextPrinter.Color = Color.Navy; TGPAContext.Instance.TextPrinter.Write(spriteBatch, playDst.X - (playText.Length * 12), playDst.Y + 5, playText); TGPAContext.Instance.TextPrinter.Color = Color.Red; TGPAContext.Instance.TextPrinter.Write(spriteBatch, backDst.X + backDst.Width, backDst.Y + 5, backText); TGPAContext.Instance.TextPrinter.Color = Color.Black; } } TGPAContext.Instance.TextPrinter.Color = (Color.Black * alphaPostIt); TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 20, postitDst.Y + 100, "Level " + overview.Level); TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 20, postitDst.Y + 130, overview.Name); TGPAContext.Instance.TextPrinter.Size = 0.8f; for (int i = 0; i < this.levelParts.Length; i++) { TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 25, postitDst.Y + 170 + (80 * i), LocalizedStrings.GetString("LevelSelectionScreenPart") + " " + i + " - " + LocalizedStrings.GetString("LevelSelectionScreenBestScore")); ScoreLine bestScore = TGPAContext.Instance.Saver.GetBestScoreForLevel(this.levelParts[i], this.scoreType); if (bestScore.Score > 0) { TGPAContext.Instance.TextPrinter.Color = (Color.Blue * alphaPostIt); TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 25, postitDst.Y + 190 + (80 * i), bestScore.ToString()); TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 105, postitDst.Y + 210 + (80 * i), bestScore.GetDifficultyString()); } else { TGPAContext.Instance.TextPrinter.Color = (Color.Red * alphaPostIt); TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 25, postitDst.Y + 190 + (80 * i), LocalizedStrings.GetString("LevelSelectionScreenNoHighscore")); } TGPAContext.Instance.TextPrinter.Color = (Color.Black * alphaPostIt); } TGPAContext.Instance.TextPrinter.Color = Color.Black; TGPAContext.Instance.TextPrinter.Size = 1f; if (launchLevel == false) { //Buttons //*************************************************************************** if (TGPAContext.Instance.Player1.IsPlayingOnWindows() == false) { TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Move", TGPAContext.Instance.Player1.Device.Type, 535, 630); TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Confirm", TGPAContext.Instance.Player1.Device.Type, 535, 700); TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Cancel", TGPAContext.Instance.Player1.Device.Type, 150, 630); TGPAContext.Instance.TextPrinter.Write(spriteBatch, 595, 650, LocalizedStrings.GetString("LevelSelectionScreenMove")); TGPAContext.Instance.TextPrinter.Write(spriteBatch, 595, 700, LocalizedStrings.GetString("LevelSelectionScreenPressA")); TGPAContext.Instance.TextPrinter.Write(spriteBatch, 205, 650, LocalizedStrings.GetString("LevelSelectionScreenPressB")); } TGPAContext.Instance.TextPrinter.Write(spriteBatch, 170, 700, LocalizedStrings.GetString(this.scoreType == ScoreType.Single ? "SwitchToScoreTypeCoop" : "SwitchToScoreTypeSingle")); TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Plus", TGPAContext.Instance.Player1.Device.Type, 115, 690); } if (fadeoutAlpha > 0f) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); spriteBatch.Draw(background, new Rectangle(0, 0, TGPAContext.Instance.ScreenWidth, TGPAContext.Instance.ScreenHeight), null, (Color.Black * fadeoutAlpha)); spriteBatch.End(); } if (launchLevel) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); spriteBatch.Draw(TGPAContext.Instance.HudTex, rectDst, TGPAContext.Instance.PaperRect, Color.White); spriteBatch.End(); TGPAContext.Instance.TextPrinter.Write(spriteBatch, rectDst.X + 50, rectDst.Y + 60, LocalizedStrings.GetString("Difficulty")); difficultyListControl.Draw(spriteBatch); TGPAContext.Instance.TextPrinter.Size = 0.8f; TGPAContext.Instance.TextPrinter.Write(spriteBatch, rectDst.X + 40, rectDst.Y + 125, LocalizedStrings.GetString((Difficulty)this.difficultyListControl.FocusedElement.Value + "Desc"), 50); TGPAContext.Instance.TextPrinter.Size = 1f; TGPAContext.Instance.TextPrinter.Color = Color.White; TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Back", TGPAContext.Instance.Player1.Device.Type, 350, 550); TGPAContext.Instance.TextPrinter.Write(spriteBatch, 400, 560, LocalizedStrings.GetString("CancelLaunchLevel")); TGPAContext.Instance.TextPrinter.Color = Color.Black; } }