Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.38 KB | None | 0 0
  1. namespace TeamPlatformer
  2. {
  3.    abstract class GameScreen
  4.     {
  5.         public enum ScreenStatus { Activ, Inactiv, inTransition}
  6.  
  7.         abstract public event ScreenHandler ScreenChanged;
  8.  
  9.         abstract public void LoadContent(ContentManager content);
  10.  
  11.         abstract public void Update(GameTime gameTime);
  12.  
  13.         abstract public void Draw(SpriteBatch spriteBatch);
  14.     }
  15. }
  16.  
  17. #################################################################
  18.  
  19. namespace TeamPlatformer
  20. {
  21.     public delegate void ScreenHandler();
  22.  
  23.     class ScreenManager : DrawableGameComponent
  24.     {
  25.         SpriteBatch spriteBatch;
  26.         ContentManager content;
  27.  
  28.         List<GameScreen> screenList;
  29.         GameScreen currentScreen;
  30.  
  31.         public ScreenManager(Game game): base(game)
  32.         {
  33.             content = new ContentManager(game.Content.ServiceProvider, game.Content.RootDirectory);
  34.  
  35.             screenList = new List<GameScreen>();
  36.             screenList.Add(new MenuScreen());
  37.             screenList.Add(new PauseScreen());
  38.             screenList.Add(new IntroScreen());
  39.  
  40.             screenList[2].ScreenChanged += IntroEndHandler;
  41.  
  42.             currentScreen = screenList[2];
  43.         }
  44.  
  45.  
  46.         protected override void LoadContent()
  47.         {
  48.             spriteBatch = new SpriteBatch(GraphicsDevice);
  49.            
  50.             //foreach (GameScreen screen in screenList)
  51.             //{
  52.             //    screen.LoadContent(content);
  53.             //}
  54.  
  55.             currentScreen.LoadContent(content);
  56.  
  57.             base.LoadContent();
  58.         }
  59.  
  60.         public override void Update(GameTime gameTime)
  61.         {
  62.             currentScreen.Update(gameTime);
  63.             base.Update(gameTime);
  64.         }
  65.  
  66.         private void IntroEndHandler()
  67.         {
  68.             currentScreen = screenList[0];
  69.         }
  70.  
  71.         public override void Draw(GameTime gameTime)
  72.         {
  73.             GraphicsDevice.Clear(Color.CornflowerBlue);
  74.             currentScreen.Draw(spriteBatch);
  75.             base.Draw(gameTime);
  76.         }
  77.     }
  78. }
  79.  
  80. ######################################################################
  81.  
  82. namespace TeamPlatformer
  83. {
  84.     class IntroScreen : GameScreen
  85.     {
  86.         //Intro Länge hier einstellen
  87.  
  88.         private const int introDuration = 5;
  89.         private double elapsedTime = 0f;
  90.  
  91.         //Screen Switch Event
  92.  
  93.         public override event ScreenHandler ScreenChanged;
  94.  
  95.         private Texture2D Intro;
  96.         private Rectangle BackgroundRectangle;
  97.  
  98.         public IntroScreen()
  99.         {
  100.             BackgroundRectangle = new Rectangle(0, 0, 800, 600);
  101.         }
  102.  
  103.         public override void LoadContent(ContentManager content)
  104.         {
  105.             Intro = content.Load<Texture2D>("Logo");
  106.         }
  107.  
  108.         public override void Update(GameTime gameTime)
  109.         {
  110.             elapsedTime += gameTime.ElapsedGameTime.TotalSeconds;
  111.  
  112.             if(elapsedTime >= introDuration)
  113.             {
  114.                 if(ScreenChanged != null)
  115.                 OnIntroEnd();
  116.             }
  117.         }
  118.  
  119.         protected void OnIntroEnd()
  120.         {
  121.             elapsedTime = 0;
  122.             ScreenChanged();
  123.         }
  124.  
  125.         public override void Draw(SpriteBatch spriteBatch)
  126.         {
  127.             spriteBatch.Begin();
  128.             spriteBatch.Draw(Intro, BackgroundRectangle, Color.White);
  129.             spriteBatch.End();
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement