Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TeamPlatformer
- {
- abstract class GameScreen
- {
- public enum ScreenStatus { Activ, Inactiv, inTransition}
- abstract public event ScreenHandler ScreenChanged;
- abstract public void LoadContent(ContentManager content);
- abstract public void Update(GameTime gameTime);
- abstract public void Draw(SpriteBatch spriteBatch);
- }
- }
- #################################################################
- namespace TeamPlatformer
- {
- public delegate void ScreenHandler();
- class ScreenManager : DrawableGameComponent
- {
- SpriteBatch spriteBatch;
- ContentManager content;
- List<GameScreen> screenList;
- GameScreen currentScreen;
- public ScreenManager(Game game): base(game)
- {
- content = new ContentManager(game.Content.ServiceProvider, game.Content.RootDirectory);
- screenList = new List<GameScreen>();
- screenList.Add(new MenuScreen());
- screenList.Add(new PauseScreen());
- screenList.Add(new IntroScreen());
- screenList[2].ScreenChanged += IntroEndHandler;
- currentScreen = screenList[2];
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- //foreach (GameScreen screen in screenList)
- //{
- // screen.LoadContent(content);
- //}
- currentScreen.LoadContent(content);
- base.LoadContent();
- }
- public override void Update(GameTime gameTime)
- {
- currentScreen.Update(gameTime);
- base.Update(gameTime);
- }
- private void IntroEndHandler()
- {
- currentScreen = screenList[0];
- }
- public override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- currentScreen.Draw(spriteBatch);
- base.Draw(gameTime);
- }
- }
- }
- ######################################################################
- namespace TeamPlatformer
- {
- class IntroScreen : GameScreen
- {
- //Intro Länge hier einstellen
- private const int introDuration = 5;
- private double elapsedTime = 0f;
- //Screen Switch Event
- public override event ScreenHandler ScreenChanged;
- private Texture2D Intro;
- private Rectangle BackgroundRectangle;
- public IntroScreen()
- {
- BackgroundRectangle = new Rectangle(0, 0, 800, 600);
- }
- public override void LoadContent(ContentManager content)
- {
- Intro = content.Load<Texture2D>("Logo");
- }
- public override void Update(GameTime gameTime)
- {
- elapsedTime += gameTime.ElapsedGameTime.TotalSeconds;
- if(elapsedTime >= introDuration)
- {
- if(ScreenChanged != null)
- OnIntroEnd();
- }
- }
- protected void OnIntroEnd()
- {
- elapsedTime = 0;
- ScreenChanged();
- }
- public override void Draw(SpriteBatch spriteBatch)
- {
- spriteBatch.Begin();
- spriteBatch.Draw(Intro, BackgroundRectangle, Color.White);
- spriteBatch.End();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement