/// <summary> /// The main game constructor. /// </summary> public GameStateManagementGame() { Content.RootDirectory = "Content"; graphics = new GraphicsDeviceManager(this); graphics.IsFullScreen = true; TargetElapsedTime = TimeSpan.FromTicks(333333); collisionManager = new CollisionManager(this); Components.Add(collisionManager); Services.AddService(typeof(CollisionManager), collisionManager); // you can choose whether you want a landscape or portait // game by using one of the two helper functions. // This game only supports Landscape view, both left and right //InitializePortraitGraphics(); InitializeLandscapeGraphics(); graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; // Create the screen manager component. screenManager = new ScreenManager(this); // Note make sure to render in correct order Components.Add(screenManager); // attempt to deserialize the screen manager from disk. if that // fails, we add our default screens. if (!screenManager.DeserializeState()) { // Activate the first screens. screenManager.AddScreen(new BackgroundScreen(), null); screenManager.AddScreen(new MainMenuScreen(), null); } }
public GameObject(Microsoft.Xna.Framework.Game game, Point position) { this.game = game; this.position = new Vector2(position.X, position.Y); this.velocity = Vector2.Zero; drawObject = true; //Letting it be default that an gameObject is drawn collisionManager = (CollisionManager) game.Services.GetService(typeof(CollisionManager)); }
protected Game game; // Instance of the base game class. #endregion Fields #region Constructors /// <summary> /// Constructor. /// </summary> /// <param name="game">Instance of base game class</param> /// <param name="position">Posision of the game object</param> public GameObject(Game game, Point position) { this.game = game; this.position = new Vector2(position.X, position.Y); this.velocity = Vector2.Zero; drawObject = true; //Letting it be default that an gameObject is drawn collisionManager = (CollisionManager)game.Services.GetService(typeof(ICollisionService)); deleteFlag = false; }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) { content = new ContentManager(ScreenManager.Game.Services, "Content"); } //Add game cam cam = new Camera(ScreenManager.GraphicsDevice.Viewport); ScreenManager.Game.Services.AddService(typeof(Camera), cam); //ScreenManager.DeserializeState(); collisionMananger = new CollisionManager(ScreenManager.Game); // Adds collision manager to Game.Service, This Service unloads when UnloadContent is called. ScreenManager.Game.Services.AddService(typeof(ICollisionService), collisionMananger); spriteBatch = ScreenManager.SpriteBatch; mapDisaplayDevice = new XnaDisplayDevice(this.content, ScreenManager.GraphicsDevice); map = content.Load<Map>(_mapLevelName); map.LoadTileSheets(mapDisaplayDevice); _collisionLayers = new CollisionLayers(ScreenManager.Game, map); _gameObjectLayerManager = new GameObjectLayersManager(ScreenManager.Game, map, cam); gameObjects.AddRange(_gameObjectLayerManager.GameObjects); soundManager = new Sound(ScreenManager.Game); ScreenManager.Game.Services.AddService(typeof(ISound), soundManager); soundManager.LoadContent(); soundManager.PlayMusic("main"); //Adds GUI buttons gamePlayButtons = new GamePlayButtons(ScreenManager.Game); //Add players playerManager = new PlayerManager(ScreenManager.Game, map, gravity); gameObjects.AddRange(playerManager.players); cam.activePlayer = playerManager.currentPlayer; // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); foreach (GameObject obj in gameObjects) { if (obj is TargetTile) { cam.center = obj.position; cam.MoveCameraToGameObject(obj, 4.0f, 800.0f); break; } } GC.Collect(); //Requesting garbage collect }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) { content = new ContentManager(ScreenManager.Game.Services, "Content"); } collisionMananger = new CollisionManager(ScreenManager.Game); // Adds collision manager to Game.Service, This Service unloads when UnloadContent is called. ScreenManager.Game.Services.AddService(typeof(ICollisionService), collisionMananger); spriteBatch = ScreenManager.SpriteBatch; gameFont = content.Load<SpriteFont>("gamefont"); //Add game world world = new World(ScreenManager.Game); world.LoadContent(); gameObjects.AddRange(world.tiles); //Add Trigger objects gameObjects.AddRange(world.triggerTile); //Add Destroyable Tile objects foreach (Trigger triggerObj in world.triggerTile) { gameObjects.Add(triggerObj.GetDestroyableTile()); } soundManager = new Sound(ScreenManager.Game); soundManager.LoadContent(); soundManager.PlayMusic("main"); //Adds GUI buttons gamePlayButtons = new GamePlayButtons(ScreenManager.Game); //Add players playerManager = new PlayerManager(ScreenManager.Game, gravity); playerManager.LoadContent(); gameObjects.AddRange(playerManager.players); endPicture = content.Load<Texture2D>("endpicture"); //Add game cam cam = new Camera(ScreenManager.GraphicsDevice.Viewport); cam.activePlayer = playerManager.currentPlayer; // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); GC.Collect(); //Requesting garbage collect }
public InvisibleCollisionBox(Game game, Rectangle collisionRect) { _collisionBox = collisionRect; collisionManager = (CollisionManager)game.Services.GetService(typeof(ICollisionService)); collisionManager.RegisterObject(this); }