using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace Blackjack { /// /// This is a game component that implements IUpdateable. /// public class StartScreen{ MainGame game; KeyboardState lastKeystate; Texture2D titlesprite; Texture2D bgsplash; Texture2D pressstart; Texture2D blackoverlay; Rectangle overlayRect; Vector2 titlesprite_pos = new Vector2(0, 0); Vector2 pressstart_pos = new Vector2(0, 0); SoundEffect bgmusic; SoundEffectInstance sfxin; double closing_delay = 0.005f; double pressstart_fadedelay = 0.001f; bool pressstart_isfading = true; int pressstart_alpha = 255; int overlay_alpha = 0; bool screenclosing = false; public StartScreen(MainGame game) { this.game = game; titlesprite = game.Content.Load("blackjack_logo"); bgsplash = game.Content.Load("bg_splash"); pressstart = game.Content.Load("press_enter_to_start"); bgmusic = game.Content.Load("cybersoldier"); sfxin = bgmusic.CreateInstance(); sfxin.IsLooped = true; sfxin.Volume = 0.3f; sfxin.Play(); titlesprite_pos = new Vector2((game.GraphicsDevice.Viewport.Width - titlesprite.Width) / 2, 100); pressstart_pos = new Vector2((game.GraphicsDevice.Viewport.Width - pressstart.Width) / 2, 280); blackoverlay = new Texture2D(game.GraphicsDevice, 1, 1); overlayRect = new Rectangle(0, 0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height); blackoverlay.SetData(new Color[] { Color.Black}); } public void Unload() { sfxin.Stop(); sfxin.Dispose(); titlesprite.Dispose(); bgsplash.Dispose(); pressstart.Dispose(); blackoverlay.Dispose(); } private void CloseScreen() { screenclosing = true; } public void Update(GameTime gameTime) { KeyboardState keystate = Keyboard.GetState(); if (keystate.IsKeyDown(Keys.Enter) && lastKeystate.IsKeyUp(Keys.Enter)) { //Start game. CloseScreen(); } lastKeystate = keystate; if (pressstart_alpha <= 0) pressstart_isfading = false; else if (pressstart_alpha >= 255) pressstart_isfading = true; //Press start fade in/out animation. pressstart_fadedelay -= gameTime.ElapsedGameTime.TotalSeconds; if (pressstart_fadedelay <= 0) { pressstart_fadedelay = 0.001f; if (pressstart_isfading) { pressstart_alpha -= 5; } else { pressstart_alpha += 5; } } if (screenclosing) { closing_delay -= gameTime.ElapsedGameTime.TotalSeconds; if (closing_delay <= 0) { closing_delay = 0.05f; overlay_alpha += 25; } if (overlay_alpha > 255) { Unload(); game.StartGame(); } } } //override draw component. public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(bgsplash, new Vector2(0, 0), Color.White); spriteBatch.Draw(titlesprite, titlesprite_pos, new Color(255, 255, 255, 255)); spriteBatch.Draw(pressstart, pressstart_pos, new Color(255, 255, 255, pressstart_alpha)); spriteBatch.Draw(blackoverlay, overlayRect, new Color(255, 255, 255, overlay_alpha)); } public void StartGame() { } } }