void Options_ScreenResolutionChanged(object sender, EventArgs e) { //Get the new viewport from EventArgs Viewport viewport = e.Cast <ViewportEventArgs>().Viewport; //Re-position title based on new viewport gameTitle.X = gameTitle.GetCenterPosition(viewport).X; gameTitle.Y = viewport.Height; //Re-position all credits based on new viewport for (int i = 0; i < AdditionalSprites.Count; i++) { TextSprite credit = AdditionalSprites[i].Cast <TextSprite>(); credit.X = credit.GetCenterPosition(viewport).X; if (i == 0) { credit.Y = gameTitle.Y + gameTitle.Height; } else { TextSprite prevCredit = AdditionalSprites[i - 1].Cast <TextSprite>(); credit.Y = prevCredit.Y + prevCredit.Height + (_creditsFont.LineSpacing - _creditsFont.MeasureString("A").Y); } } }
public MultiplayerScreen(SpriteBatch sb) : base(sb, Color.Chocolate * 0.9f) { ClearColor.A = 255; Name = "MultiPlayer"; GLibXNASampleGame.Instance.SessionManagement.SessionsFound += new EventHandler <Glib.XNA.NetworkLib.NetworkSessionsFoundEventArgs>(SessionManagement_SessionsFound); GLibXNASampleGame.Instance.SessionManagement.SessionJoined += new EventHandler <Glib.XNA.NetworkLib.NetworkSessionJoinedEventArgs>(SessionManagement_SessionJoined); //See MainMenu for TextSprite sample comments title = new TextSprite(sb, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("Title"), "Networking Sample", Color.Gold); title.Position = new Vector2(title.GetCenterPosition(Graphics.Viewport).X, 15); AdditionalSprites.Add(title); hostSession = new TextSprite(sb, new Vector2(0, title.Y + title.Height + 5), GLibXNASampleGame.Instance.Content.Load <SpriteFont>("MenuItem"), "Host Session", Color.MediumSpringGreen); hostSession.X = hostSession.GetCenterPosition(Graphics.Viewport).X; hostSession.IsHoverable = true; hostSession.HoverColor = Color.SpringGreen; hostSession.Pressed += new EventHandler(hostSession_Pressed); AdditionalSprites.Add(hostSession); joinSession = new TextSprite(sb, new Vector2(0, hostSession.Y + hostSession.Height + 5), GLibXNASampleGame.Instance.Content.Load <SpriteFont>("MenuItem"), "Join Session", Color.MediumSpringGreen); joinSession.X = joinSession.GetCenterPosition(Graphics.Viewport).X; joinSession.IsHoverable = true; joinSession.HoverColor = Color.SpringGreen; joinSession.Pressed += new EventHandler(joinSession_Pressed); AdditionalSprites.Add(joinSession); }
/// <summary> /// Creates and initializes the video player sample screen. /// </summary> /// <param name="spriteBatch">The <see cref="SpriteBatch"/> to render to.</param> public VideoPlayerScreen(SpriteBatch spriteBatch) : base(spriteBatch, Color.DarkGray) { Name = "VideoPlayer"; //Reduces the ARGB values, then resets alpha to 255 ClearColor *= 1f / 6f; ClearColor.A = 255; //See MainMenu for TextSprite sample comments title = new TextSprite(spriteBatch, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("Title"), "VideoPlayer Sample", Color.PaleGoldenrod); title.Position = new Vector2(title.GetCenterPosition(spriteBatch.GraphicsDevice.Viewport).X, 15); AdditionalSprites.Add(title); escapeReturnDesc = new TextSprite(spriteBatch, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("Details"), "Press escape\nto return to\nthe main menu", Color.PaleGoldenrod); escapeReturnDesc.Position = new Vector2(3); AdditionalSprites.Add(escapeReturnDesc); //This event is fired when a key is pressed KeyboardManager.KeyDown += new SingleKeyEventHandler(KeyboardManager_KeyDown); creditTextSprite = new TextSprite(spriteBatch, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("Details"), "Video obtained from nps.gov/cany/planyourvisit/rivervideos.htm", Color.Goldenrod); creditTextSprite.Color.A = 32; creditTextSprite.Position = new Vector2(creditTextSprite.GetCenterPosition(spriteBatch.GraphicsDevice.Viewport).X, spriteBatch.GraphicsDevice.Viewport.Height - creditTextSprite.Height - 5); AdditionalSprites.Add(creditTextSprite); //VideoSprite: Like a sprite, but displays a video video = new VideoSprite(GLibXNASampleGame.Instance.Content.Load <Video>("VideoSample"), Vector2.Zero, spriteBatch); video.Video.Stop(); video.Position = video.GetCenterPosition(spriteBatch.GraphicsDevice.Viewport); Sprites.Add(video); }
public LoadingScreen(SpriteBatch sb) : base(sb, Color.DarkOliveGreen) { Name = "Loading"; loadingText = new TextSprite(sb, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("Subtitle"), "Loading...", Color.Cornsilk); loadingText.Position = loadingText.GetCenterPosition(Graphics.Viewport); AdditionalSprites.Add(loadingText); }
void Options_ScreenResolutionChanged(object sender, EventArgs e) { //relocate buttons and labels on the screen! PauseLabel.Position = new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width / 2 - PauseLabel.Width / 2, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .1f); ResumeButton.Position = new Vector2(ResumeButton.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .2f); ExitButton.Position = new Vector2(ResumeButton.X, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .8f); ExitLabel.Position = new Vector2(ExitLabel.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, ExitButton.Y + (ExitButton.Height / 2 - ExitLabel.Height / 2)); ShopButton.Position = new Vector2(ResumeButton.X, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .53f); ResumeLabel.Position = new Vector2(ResumeLabel.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, ResumeButton.Y + (ResumeButton.Height / 2 - ResumeLabel.Height / 2)); OptionButton.Position = new Vector2(ResumeButton.X, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .37f); ShopLabel.Position = new Vector2(ShopLabel.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, ShopButton.Y + (ShopButton.Height / 2 - ShopLabel.Height / 2)); OptionsLabel.Position = new Vector2(OptionsLabel.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, OptionButton.Y + (OptionButton.Height / 2 - OptionsLabel.Height / 2)); }
public GameLobbyScreen(SpriteBatch sb) : base(sb, Color.Gainsboro * 0.75f) { ClearColor.A = 255; Name = "NetworkLobby"; title = new TextSprite(sb, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("Title"), "Lobby", Color.ForestGreen); title.X = title.GetCenterPosition(Graphics.Viewport).X; title.Y = 15; AdditionalSprites.Add(title); gamerList = new TextSprite(sb, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("MenuItem"), "", Color.IndianRed); gamerList.Position = gamerList.GetCenterPosition(Graphics.Viewport); AdditionalSprites.Add(gamerList); KeyboardManager.KeyDown += new SingleKeyEventHandler(KeyboardManager_KeyDown); }
/// <summary> /// Creates and initializes the main menu. /// </summary> /// <param name="sb">The <see cref="SpriteBatch"/> to render to.</param> public MainMenu(SpriteBatch sb) : base(sb, Color.Lime) { Name = "MainMenu"; //TextureFactory: Creates textures at runtime TextureFactory factory = new TextureFactory(sb.GraphicsDevice); //Sprite: A simple bitmap image, with convenient methods and properties //Yet it has so many possibilities... //Here it is used as a mouse cursor //Star image courtesy of Wikimedia user Felipe Micaroni Lalli //Image obtained from http://commons.wikimedia.org/wiki/File:Star_Ouro.svg mouseCursor = new Sprite(GLibXNASampleGame.Instance.Content.Load <Texture2D>("Star"), Vector2.Zero, sb); mouseCursor.Scale = new Vector2(.1f); mouseCursor.UseCenterAsOrigin = true; //OverlayImage overlays the second image onto the first (not in place) Texture2D imageOverlay = factory.CreateSquare(15, Color.DarkGray * 0.65F); TextureFactory.OverlayImage(imageOverlay, factory.CreateSquare(11, Color.Black * 0.75F), new Point(2, 2)); TextureFactory.OverlayImage(imageOverlay, factory.CreateSquare(7, Color.DarkOrange * 0.85F), new Point(4, 4)); TextureFactory.OverlayImage(imageOverlay, factory.CreateSquare(3, Color.DarkRed * 0.95F), new Point(6, 6)); fadingImage = new Sprite(imageOverlay, Vector2.Zero, sb); fadingImage.Position = new Vector2(15, 25); //The CreateFade method creates an array of textures, each one closer to the final texture than the last //It is used for fades Texture2D finalFadeImage = factory.CreateRectangle(fadingImage.Texture.Width, fadingImage.Texture.Height, Color.Red); TextureFactory.OverlayImage(finalFadeImage, factory.CreateHollowRectangle(fadingImage.Texture.Width - 4, fadingImage.Texture.Height - 4, Color.DarkRed), new Point(2, 2)); fades = TextureFactory.CreateFade(fadingImage.Texture, finalFadeImage, 300); mouseBoundingBox = new Sprite(factory.CreateHollowCircle((mouseCursor.Width / 2).Round(), Color.Navy), mouseCursor.Position, sb) { UseCenterAsOrigin = true }; //TextSprite: Displays text //Can be used for titles, descriptions, etc title = new TextSprite(sb, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("Title"), "GlenLibrary XNA"); //Extension method: GetCenterPosition: Returns the position required to center the object on the specified viewport title.Position = new Vector2(title.GetCenterPosition(sb.GraphicsDevice.Viewport).X, 15); //Fancy color constructor: Uses a Vector4 with RGBA values expressed as floats from 0 to 1, basically dark gray shadow with 128 alpha title.Shadow = new TextShadow(title, new Vector2(-2, 2), new Color(new Vector4(Color.DarkGray.ToVector3(), 0.5f))); AdditionalSprites.Add(title); desc = new TextSprite(sb, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("Subtitle"), "A general purpose XNA library", Color.Chocolate); desc.Color *= 0.75f; desc.Color.A = 255; desc.X = desc.GetCenterPosition(Graphics.Viewport).X; desc.Y = title.Y + title.Height + 5; AdditionalSprites.Add(desc); //Add items to the buttons dictionary buttons.Add("Video Player", "VideoPlayer"); buttons.Add("Multiplayer", "MultiPlayer"); buttons.Add("Animated Sprite", "AnimatedScreen"); #region Generation of buttons systematically float yCoord = desc.Y + desc.Height + 10; foreach (var element in buttons) { Sprite buttonSprite = new Sprite(GLibXNASampleGame.Instance.TextureCreator.CreateSquare(1, Color.Red), Vector2.Zero, sb); TextSprite button = new TextSprite(sb, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("MenuItem"), element.Key); //Allows hovering (and therefore clicking) on a sprite button.IsHoverable = true; // These are the colors that are displayed at the various hovering states button.HoverColor = Color.DarkCyan; button.NonHoverColor = Color.Black; // "Pressed" event handler lambda expression button.Pressed += (src, args) => GLibXNASampleGame.Instance.SetScreen(buttons[((TextSprite)src).Text]); // Setting width and height on a Sprite scales it buttonSprite.Width = button.Width + 6; buttonSprite.Height = button.Height + 4; buttonSprite.Position = new Vector2(buttonSprite.GetCenterPosition(sb.GraphicsDevice.Viewport).X, yCoord); // ParentSprite: Allows for a "button" behind a clickable TextSprite (or not clickable), all collision and position logic done with this sprite button.ParentSprite = buttonSprite; // Round to look better button.Scale.X = button.Scale.X.Round(); button.Scale.Y = button.Scale.Y.Round(); button.X = button.X.Round(); button.Y = button.Y.Round(); Sprites.Add(buttonSprite); AdditionalSprites.Add(button); yCoord += buttonSprite.Height; yCoord += 7.5f; yCoord = yCoord.Round(); } #endregion // ProgressBar: A dynamically generated progress bar, could be used to represent asset loading progress // Here it is just used for effects :-) progressBar = new ProgressBar(Vector2.Zero, _filledColors[0], _emptyColors[0], sb); //HeightScale: The progress bar shall be 7 pixels high progressBar.HeightScale = 7; progressBar.Denominator = Graphics.Viewport.Width - 20; progressBar.Value = 0; progressBar.X = progressBar.GetCenterPosition(sb.GraphicsDevice.Viewport).X; progressBar.Y = Graphics.Viewport.Height - progressBar.Height - 5; Sprites.Add(progressBar); caption = new TextSprite(sb, GLibXNASampleGame.Instance.Content.Load <SpriteFont>("Details"), "A caption!"); caption.X = caption.GetCenterPosition(Graphics.Viewport).X; caption.Y = progressBar.Y - caption.Height - 2; caption.Visible = false; AdditionalSprites.Add(caption); // Random Particle Generator: A particle generator that uses a Random instance to set properties of the generated particles RandomParticleGenerator particlegen = new RandomParticleGenerator(sb, GLibXNASampleGame.Instance.Content.Load <Texture2D>("Star")); particlegen.MinimumParticleColorChangeRate = 0.925f; particlegen.MinimumTimeToLive = TimeSpan.FromMilliseconds(400); particlegen.MaximumTimeToLive = TimeSpan.FromMilliseconds(780); particlegen.ParticlesToGenerate = 1; particlegen.ScaleFactor = 15; // TimeToLiveSettings: When to make a particle expire, binary flaggable enumerator particlegen.TTLSettings = TimeToLiveSettings.AlphaLess100 | TimeToLiveSettings.StrictTTL; // Particle engine: Generates particles using the specified particle generator mouseParticleGen = new ParticleEngine(particlegen); mouseParticleGen.FramesPerGeneration = 3; mouseParticleGen.Tracked = mouseCursor; AdditionalSprites.Add(mouseParticleGen); AdditionalSprites.Add(mouseCursor); AdditionalSprites.Add(mouseBoundingBox); Sprites.Add(fadingImage); }
private void ShowCaption() { caption.X = caption.GetCenterPosition(Graphics.Viewport).X; caption.Y = progressBar.Y - caption.Height - 2; caption.Visible = true; }
public override void InitScreen(ScreenType screenType) { base.InitScreen(screenType); MediaPlayer.MediaStateChanged -= musicHandler; MediaPlayer.MediaStateChanged += musicHandler; BackgroundSprite = new Sprite(GameContent.GameAssets.Images.Backgrounds.Screens[ScreenBackgrounds.Credits], Vector2.Zero, Sprites.SpriteBatch); SpriteFont SegoeUIMono = GameContent.GameAssets.Fonts.NormalText; _scrollingSpeed = new Vector2(0, -1); Texture2D logo = GameContent.GameAssets.Images.Controls.Title; gameTitle = new Sprite(logo, new Vector2(0, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height), Sprites.SpriteBatch); gameTitle.X = gameTitle.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X; //credits = new TextSprite(Sprites.SpriteBatch, , "\n\n\n\nWeek 1 - Functional Spec, GameState Management\n //Week 3 - AI's\n\n\n\n\n\n\n\n\n\n\n\nWeek 4 - Xbox Converson\n\n\n\n\nUnderlying Library written by:\nGlen Husman (glen3b)\nGlib is available on github! \n\n\n\n\n\n\n Music:\n\nFailing Defense - Kevin MacLeod\n\nAll music obtained from Incompetech.com", Color.White); //credits = new TextSprite(Sprites.SpriteBatch, GameContent.GameAssets.Fonts.NormalText, " Plequarius: Galactic Commanders\n\n\n\n\n\nAll Developement:\nGlen Husman\n\nMinor Assistance:\nAbe", Color.White); //credits.Position = new Vector2(credits.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height+imgSprite.Height); _creditsSong = GameContent.GameAssets.Music[ScreenMusic.Credits]; int lastWeekID = 0; foreach (KeyValuePair <XmlCredits.Week, XmlCredits.Student> weekStudent in _xmlCredits.Students) { int weekID = weekStudent.Key.ID; if (lastWeekID != weekID) { StringBuilder title = new StringBuilder(); title.AppendFormat("\n\n\n\nWeek {0} - ", weekID); for (int topicCounter = 0; topicCounter < weekStudent.Key.Topics.Count; topicCounter++) { KeyValuePair <int, string> topic = weekStudent.Key.Topics[topicCounter]; title.AppendFormat("{0}{1}", topic.Value, topicCounter == weekStudent.Key.Topics.Count - 1 ? "\n" : ", "); } TextSprite credit = new TextSprite(Sprites.SpriteBatch, _boldCreditsFont, title.ToString()); credit.X = credit.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X; credit.Color = Color.White; if (credits.Count == 0) { credit.Y = gameTitle.Y + gameTitle.Height; } else { credit.Y = credits[credits.Count - 1].Y + credits[credits.Count - 1].Height + (_creditsFont.LineSpacing - _creditsFont.MeasureString("A").Y); } credits.Add(credit); lastWeekID = weekID; } TextSprite student = new TextSprite(Sprites.SpriteBatch, _creditsFont, String.Format("{0} {1}\n", weekStudent.Value.FirstName, weekStudent.Value.LastName)); student.X = student.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X; student.Color = Color.White; student.Y = credits[credits.Count - 1].Y + credits[credits.Count - 1].Height + (_creditsFont.LineSpacing - _creditsFont.MeasureString("A").Y); credits.Add(student); } //The IEnumerable cast method AdditionalSprites.AddRange(credits.Cast <ISprite>()); Sprites.Add(gameTitle); _elapsedTime = TimeSpan.Zero; }
public override void InitScreen(ScreenType screenType) { base.InitScreen(screenType); Texture2D button = GameContent.GameAssets.Images.Controls.Button; StateManager.Options.ScreenResolutionChanged += new EventHandler(Options_ScreenResolutionChanged); PauseLabel = new TextSprite(Sprites.SpriteBatch, Vector2.Zero, GameContent.GameAssets.Fonts.BoldText, "Paused"); PauseLabel.Position = new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width / 2 - PauseLabel.Width / 2, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .1f); PauseLabel.Color = Color.White; AdditionalSprites.Add(PauseLabel); ResumeButton = new Sprite(button, Vector2.Zero, Sprites.SpriteBatch); ResumeButton.Position = new Vector2(ResumeButton.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .2f); #if WINDOWS ResumeButton.MouseEnter += new EventHandler(ResumeButton_MouseEnter); ResumeButton.MouseLeave += new EventHandler(ResumeButton_MouseLeave); #endif Sprites.Add(ResumeButton); ExitButton = new Sprite(button, new Vector2(ResumeButton.X, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .8f), Sprites.SpriteBatch); #if WINDOWS ExitButton.MouseEnter += new EventHandler(BackButton_MouseEnter); ExitButton.MouseLeave += new EventHandler(BackButton_MouseLeave); #endif Sprites.Add(ExitButton); ResumeLabel = new TextSprite(Sprites.SpriteBatch, Vector2.Zero, GameContent.GameAssets.Fonts.NormalText, "Resume"); ResumeLabel.Position = new Vector2(ResumeLabel.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, ResumeButton.Y + (ResumeButton.Height / 2 - ResumeLabel.Height / 2)); ResumeLabel.Color = Color.White; ResumeLabel.IsHoverable = true; ResumeLabel.IsManuallySelectable = true; ResumeLabel.HoverColor = Color.MediumAquamarine; ResumeLabel.NonHoverColor = Color.White; AdditionalSprites.Add(ResumeLabel); ExitLabel = new TextSprite(Sprites.SpriteBatch, Vector2.Zero, GameContent.GameAssets.Fonts.NormalText, "Exit"); ExitLabel.Position = new Vector2(ExitLabel.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, ExitButton.Y + (ExitButton.Height / 2 - ExitLabel.Height / 2)); ExitLabel.Color = Color.White; ExitLabel.IsHoverable = true; ExitLabel.IsManuallySelectable = true; ExitLabel.HoverColor = Color.MediumAquamarine; ExitLabel.NonHoverColor = Color.White; AdditionalSprites.Add(ExitLabel); ShopButton = new Sprite(button, Vector2.Zero, Sprites.SpriteBatch); ShopButton.Position = new Vector2(ResumeButton.X, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .53f); #if WINDOWS ShopButton.MouseEnter += new EventHandler(ShopButton_MouseEnter); ShopButton.MouseLeave += new EventHandler(ShopButton_MouseLeave); #endif Sprites.Add(ShopButton); ShopLabel = new TextSprite(Sprites.SpriteBatch, Vector2.Zero, GameContent.GameAssets.Fonts.NormalText, "Shop"); ShopLabel.Position = new Vector2(ShopLabel.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, ShopButton.Y + (ShopButton.Height / 2 - ShopLabel.Height / 2)); ShopLabel.Color = Color.White; ShopLabel.IsHoverable = true; ShopLabel.IsManuallySelectable = true; ShopLabel.HoverColor = Color.MediumAquamarine; ShopLabel.NonHoverColor = Color.White; AdditionalSprites.Add(ShopLabel); OptionButton = new Sprite(button, Vector2.Zero, Sprites.SpriteBatch); OptionButton.Position = new Vector2(ResumeButton.X, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .37f); #if WINDOWS OptionButton.MouseEnter += new EventHandler(OptionButton_MouseEnter); OptionButton.MouseLeave += new EventHandler(OptionButton_MouseLeave); #endif Sprites.Add(OptionButton); OptionsLabel = new TextSprite(Sprites.SpriteBatch, Vector2.Zero, GameContent.GameAssets.Fonts.NormalText, "Options"); OptionsLabel.Position = new Vector2(OptionsLabel.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport).X, OptionButton.Y + (OptionButton.Height / 2 - OptionsLabel.Height / 2)); OptionsLabel.Color = Color.White; OptionsLabel.IsHoverable = true; OptionsLabel.IsManuallySelectable = true; OptionsLabel.HoverColor = Color.MediumAquamarine; OptionsLabel.NonHoverColor = Color.White; AdditionalSprites.Add(OptionsLabel); }
void Session_GamerLeft(object sender, GamerLeftEventArgs e) { gamerList.Text.Replace(e.Gamer.Gamertag + Environment.NewLine, ""); gamerList.Position = gamerList.GetCenterPosition(Graphics.Viewport); }