예제 #1
0
파일: DemoGame.cs 프로젝트: dekk7/xEngine
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            m_spriteBatch = new SpriteBatch(GraphicsDevice);
            m_xnaDisplayDevice = new XnaDisplayDevice(Content, GraphicsDevice);

            // load font for help text
            m_spriteFontDemo = Content.Load<SpriteFont>("Fonts/Demo");

            m_textureLeaf = Content.Load<Texture2D>("Graphics/Leaf");

            // load map from content pipeline and initialise it
            m_map = Content.Load<Map>("Maps\\Map01");
            m_map.LoadTileSheets(m_xnaDisplayDevice);

            m_map.Layers[3].BeforeDraw += OnBeforeLayerDraw;

            // prepare translucent panel for help text
            m_texturePanel = new Texture2D(GraphicsDevice, 1, 1);
            m_texturePanel.SetData<Color>(new Color[] { new Color(0, 0, 0, 128) });
        }
예제 #2
0
        /// <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
        }
예제 #3
0
파일: Game1.cs 프로젝트: keynone/enigma
        protected override void Initialize()
        {
            base.Initialize();

            RandomSeed = new Random();

            //Sony's localization decisions be damned...
            InputManager.JapaneseButtonSwap = true;

            // What exactly does distinationRect represent?
            /*
             * The destinationRect defines the area of the screen
             * that the rendertarget gets rendered to.
             * In the Draw() loop, the rendertarget is drawn with destinationRect as its
             * rectangle. This means that the "game window" can be any size within the
             * "program window."
             *
             * The below code centers it and sets it to fill the height of the screen
             * while scaling width to match the intended aspect ratio.
            */
            ScaleFactorX = (((int)ScreenResolution.Y / (int)AspectRatio.Y) * (int)AspectRatio.X);
            destinationRect.X = ((int)ScreenResolution.X / 2);
            destinationRect.Y = ((int)ScreenResolution.Y / 2);
            destinationRect.Height = (int)ScreenResolution.Y;
            destinationRect.Width = (ScaleFactorX);

            Camera.X = 0;
            Camera.Y = 0;
            mapDisplayDevice = new XnaDisplayDevice(
                this.Content, this.GraphicsDevice);

            viewport = new xTile.Dimensions.Rectangle(new Size ( (int)TempResolution.X, (int) TempResolution.Y) );
            ///For one-axis map wrapping
            viewportNorth = new xTile.Dimensions.Rectangle(new Size( (int)TempResolution.X, (int)TempResolution.Y) );
            viewportSouth = new xTile.Dimensions.Rectangle(new Size( (int)TempResolution.X, (int)TempResolution.Y) );
            viewportEast = new xTile.Dimensions.Rectangle(new Size( (int)TempResolution.X, (int)TempResolution.Y) );
            viewportWest = new xTile.Dimensions.Rectangle(new Size( (int)TempResolution.X, (int)TempResolution.Y) );

            renderTarget = new RenderTarget2D(GraphicsDevice, (int)TempResolution.X, (int)TempResolution.Y, false, SurfaceFormat.Color, 0);

            ///Initialize Objects
            //Characters
            mapCharacter = new MapCharacter[255];
            for (int i = 0; i < 255; i++)
                mapCharacter[i] = new MapCharacter(Content.Load<Texture2D>("Texture//Character//00"), 9, 8, 6, RandomSeed.Next());
            mapCharacter[0].Visible = true;
            mapCharacter[1].Visible = true;
            mapCharacter[1].IsWandering = true;

            for (int i = 2; i < 14; i++)
            {
                mapCharacter[i].Visible = true;
                mapCharacter[i].IsWandering = true;
            }

            //Maps
            GameMap.LoadTileSheets(mapDisplayDevice);

            GlobalVariables.TileMapWidth = (GameMap.Layers[0].LayerWidth);
            GlobalVariables.TileMapHeight = (GameMap.Layers[0].LayerHeight);
            GlobalVariables.TileMapResolutionX = (GlobalVariables.TileMapWidth * GlobalVariables.TileSize);
            GlobalVariables.TileMapResolutionY = (GlobalVariables.TileMapHeight * GlobalVariables.TileSize);
        }
예제 #4
0
파일: Game1.cs 프로젝트: dekk7/xEngine
        protected override void Initialize()
        {
            base.Initialize();

            m_xnaDisplayDevice = new XnaDisplayDevice(this.Content, graphics.GraphicsDevice);
            map.LoadTileSheets(m_xnaDisplayDevice);
            viewport = new xTile.Dimensions.Rectangle(new Size(800,600));

            viewport.X = 0;
            viewport.Y = 280;
        }
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            world = new World(new Vector2(0f, 9.8f));
            mapDisaplayDevice = new XnaDisplayDevice(this.content, ScreenManager.GraphicsDevice);

            map = content.Load<Map>("Maps\\lvl1");
            map.LoadTileSheets(mapDisaplayDevice);

               collisionLayers = new CollisionLayers(ScreenManager.Game, world, map);

            gamePlayButtons = new GamePlayButtons(ScreenManager.Game, world);
            gamePlayButtons.LoadContent();

            playerManager = new PlayerManager(ScreenManager.Game, world, map);
            gameObjects.AddRange(playerManager.players);

            GameObjectLayersManager xTileGameObjects = new GameObjectLayersManager(ScreenManager.Game, world, map);
            gameObjects.AddRange(xTileGameObjects.GameObjects);

            //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();
        }