/// <summary> /// Kör kod som ska köras när spelet startas /// </summary> protected override void Initialize() { IsMouseVisible = true; highscoreManager = new HighscoreManager( $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\.World of Wealth\\"); // Sätter upplösningen till 1280x720 graphics.PreferredBackBufferWidth = 1366; graphics.PreferredBackBufferHeight = 768; graphics.ApplyChanges(); //graphics.ToggleFullScreen(); //Kör Komponenterna till klasserna för spelaren och fienden Components.Add(enemyManager); Components.Add(playerManager); // Components.Add(skybox); highscoreManager.Initilize(); highscoreManager.Load(); Application.VisualStyleState = VisualStyleState.ClientAndNonClientAreasEnabled; menuManager = new MenuManager(this, GraphicsDevice); base.Initialize(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Gray); switch (gameStates) { case GameStates.Menu: spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); menuManager.Draw(spriteBatch); spriteBatch.DrawString(scoreFont, "Controls:\r\nMove with the A-S-D keys.\r\nA = left, S = middle, D = right", new Vector2(900, 10), Color.SandyBrown, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); if (highscoreManager.Highscores.HighscoreData.Count != 0) { sortedHighscores = (from keyvalue in highscoreManager.Highscores.HighscoreData orderby keyvalue.Value descending select keyvalue).ToList(); spriteBatch.DrawString(scoreFont, "Local highscore list:", new Vector2(15, 10), Color.SandyBrown, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); int r = 5; if (sortedHighscores.Count < 5) { r = sortedHighscores.Count; } for (int i = 0; i < r; i++) { KeyValuePair <DateTime, int> d = sortedHighscores[i]; spriteBatch.DrawString(scoreFont, $"{i + 1} " + System.Environment.MachineName + " got a score of: " + $"{d.Value}", new Vector2(10, 40 + (i * 20)), Color.SandyBrown, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); } } spriteBatch.End(); break; case GameStates.Maingame: GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = DepthStencilState.Default; bBase.Draw(cam.View, cam.Projection, Vector3.Up, Vector3.Right); skyBox.Draw(cam); // Loops through the list of models foreach (var data in Models) { data.Draw(cam.View, cam.Projection, cam.Position); } trail.Draw(cam.View, cam.Projection, Vector3.Up, Vector3.Right); Components.ForEach(x => x.Draw(spriteBatch, cam)); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); spriteBatch.DrawString(scoreFont, "Score:" + points, new Vector2(10, 650), Color.Wheat, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); spriteBatch.DrawString(scoreFont, "HP:" + lives, new Vector2(10, 700), Color.Wheat, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); spriteBatch.End(); break; case GameStates.Reset: GraphicsDevice.Clear(Color.Gray); break; case GameStates.Highscores: spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); if (highscoreManager.Highscores == null) { highscoreManager.Load(); } for (var i = 0; i > sortedHighscores.Count; i++) { var data = sortedHighscores[i]; // Rectangle playRect = new Rectangle(533, 360, 300, 75); spriteBatch.DrawString(scoreFont, data.ToString(), new Vector2(533 + 10 * i, 360 + 10 * i), Color.White); } spriteBatch.End(); break; } base.Draw(gameTime); }