Advertisement
Wolvenspud

gameManager

Oct 18th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Graphics;
  8. using Microsoft.Xna.Framework.Input;
  9. using Microsoft.Xna.Framework.Content;
  10. using Microsoft.Xna.Framework.Media;
  11. using Microsoft.Xna.Framework.Audio;
  12. namespace GameTemplate
  13. {
  14.     public enum GameState
  15.     {
  16.         MainMenu,
  17.         Game,
  18.         GameOver,
  19.         Credits,
  20.         Options,
  21.     }
  22.     public class GameManager
  23.     {
  24.         public Camera2d Tehcamera;
  25.  
  26.         public GameState CurrentState;
  27.  
  28.         public SpriteBatch spriteBatch;
  29.  
  30.         public List<GameObject> MainMenuGO;
  31.  
  32.         public LevelManager TheLevelManager;
  33.         public List<GameObject> GameGO;
  34.  
  35.         public List<GameObject> GameOverGO;
  36.  
  37.         Song Gm;
  38.  
  39.         public GameManager(SpriteBatch TheSpriteBatch, ContentManager Content)
  40.         {
  41.             CurrentState = GameState.MainMenu;
  42.             spriteBatch = TheSpriteBatch;
  43.            
  44.  
  45.            
  46.             MainMenuGO = new List<GameObject>();
  47.             GameObject MenuBack = new GameObject(Vector2.Zero, Content.Load<Texture2D>("mainMenu"));
  48.             MainMenuGO.Add(MenuBack);
  49.  
  50.             TheLevelManager = new LevelManager(Content);
  51.  
  52.  
  53.  
  54.             GameGO = new List<GameObject>();
  55.  
  56.             Gm = Content.Load<Song>("SuperHero_original");
  57.  
  58.             GameOverGO = new List<GameObject>();
  59.         }
  60.  
  61.         public void SewtCamera(Camera2d cam)
  62.         {
  63.             Tehcamera = cam;
  64.             if (TheLevelManager != null)
  65.             {
  66.                 TheLevelManager.SewtCamera(cam);
  67.             }
  68.         }
  69.         public void Update(float DT)
  70.         {
  71.             if (CurrentState == GameState.MainMenu)
  72.             {
  73.                 MediaPlayer.Play(Gm);
  74.                 if (Keyboard.GetState().IsKeyDown(Keys.Enter))
  75.                 {
  76.                     CurrentState = GameState.Game;
  77.                 }
  78.  
  79.                 for (int i = 0; i < MainMenuGO.Count; ++i)
  80.                 {
  81.                     MainMenuGO[i].Update(DT);
  82.                 }
  83.             }
  84.             else if(CurrentState == GameState.Game)
  85.             {
  86.  
  87.                 TheLevelManager.Update(DT);
  88.  
  89.                 for (int i = 0; i < GameGO.Count; ++i)
  90.                 {
  91.                     GameGO[i].Update(DT);
  92.                 }
  93.             }
  94.             else if (CurrentState == GameState.GameOver)
  95.             {
  96.                 for (int i = 0; i < GameOverGO.Count; ++i)
  97.                 {
  98.                     GameOverGO[i].Update(DT);
  99.                 }
  100.             }
  101.             else if(CurrentState == GameState.Credits)
  102.             {
  103.  
  104.             }
  105.             else if (CurrentState == GameState.Options)
  106.             {
  107.  
  108.             }
  109.         }
  110.         public void Draw(SpriteBatch spriteBatch)
  111.         {
  112.             if (CurrentState == GameState.MainMenu)
  113.             {
  114.                 for (int i = 0; i < MainMenuGO.Count; ++i)
  115.                 {
  116.                     MainMenuGO[i].Draw(spriteBatch);
  117.                 }
  118.             }
  119.             else if (CurrentState == GameState.Game)
  120.             {
  121.                 TheLevelManager.Draw(spriteBatch);
  122.  
  123.                 for (int i = 0; i < GameGO.Count; ++i)
  124.                 {
  125.                     GameGO[i].Draw(spriteBatch);
  126.                 }
  127.             }
  128.             else if (CurrentState == GameState.GameOver)
  129.             {
  130.                 for (int i = 0; i < GameOverGO.Count; ++i)
  131.                 {
  132.                     GameOverGO[i].Draw(spriteBatch);
  133.                 }
  134.             }
  135.             else if (CurrentState == GameState.Credits)
  136.             {
  137.  
  138.             }
  139.             else if (CurrentState == GameState.Options)
  140.             {
  141.  
  142.             }
  143.         }
  144.  
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement