Beispiel #1
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _screenArea = new Rectangle(
                _graphics.GraphicsDevice.Viewport.X,
                _graphics.GraphicsDevice.Viewport.Y,
                _graphics.GraphicsDevice.Viewport.Width,
                _graphics.GraphicsDevice.Viewport.Height
            );

            _spritesheet = Content.Load<Texture2D>("Spritesheet");

            _renderManager = new RenderManager(_graphics, _spriteBatch, _spritesheet, _screenArea);

            _world = new Level();
        }
Beispiel #2
0
        public void Render(RenderManager renderManager)
        {
            renderManager.ClearScreen(Color.Black);

            var camera = new Camera(this, _player.Position + new Vector2(-renderManager.ViewportWidth >> 1, -renderManager.ViewportHeight >> 1));

            RenderBackground(renderManager, camera);

            foreach (var entity in _entities)
            {
                entity.Render(renderManager, camera);
            }

            int truncPlayerX = (int)_player.Position.X;
            int truncPlayerY = (int)_player.Position.Y;

            int offsetX = truncPlayerX - (renderManager.ViewportWidth >> 1);
            int offsetY = truncPlayerY - (renderManager.ViewportHeight >> 1);

            int tileStartX = offsetX / Tile.Width;
            int tileStartY = offsetY / Tile.Height;

            int horizTiles = renderManager.ViewportWidth / Tile.Width;
            int vertTiles = renderManager.ViewportHeight / Tile.Height;

            for (int y = tileStartY - 1; y < tileStartY + vertTiles + 1; y++)
            {
                for (int x = tileStartX - 1; x < tileStartX + horizTiles + 1; x++)
                {
                    GetTile(x, y).Render(renderManager,
                        x * Tile.Width - offsetX,
                        y * Tile.Height - offsetY
                    );
                }
            }
        }
Beispiel #3
0
 public override void Render(RenderManager renderManager, int x, int y)
 {
 }
Beispiel #4
0
 public abstract void Render(RenderManager renderManager, int x, int y);
Beispiel #5
0
        private void RenderBackground(RenderManager renderManager, Camera camera)
        {
            Random rand = new Random();

            if (_stars == null)
            {
                _stars = new List<Star>();

                for (var i = 0; i < starDensity; i++)
                    _stars.Add(new Star(new Vector2(rand.Next(0, renderManager.ViewportWidth), rand.Next(0, renderManager.ViewportHeight))));
            }

            foreach (var star in _stars)
            {
                var sx = (star.Position.X + camera.Position.X / 5f).NFMod(renderManager.ViewportWidth);
                var sy = (star.Position.Y + camera.Position.Y / 5f).NFMod(renderManager.ViewportHeight);

                var tiledPosition = new Vector2(sx, sy);
                var starCrop = new Rectangle(96, 0, star.Size, star.Size);

                if (rand.Next(0, 90) == 45)
                    renderManager.DrawTexture(starCrop, tiledPosition, rand.Next(0, 100) / 100);
                else
                    renderManager.DrawTexture(starCrop, tiledPosition);
            }
        }
Beispiel #6
0
 public override void Render(RenderManager renderManager, Camera camera)
 {
 }
Beispiel #7
0
 public override void Render(RenderManager renderManager, int x, int y)
 {
     renderManager.DrawTexture(new Rectangle(32, 0, Tile.Width, Tile.Height), new Vector2(x, y));
 }
Beispiel #8
0
 public override void Render(RenderManager renderManager, Camera camera)
 {
     var offsetPosition = Position - camera.Position - HalfDimensions;
     renderManager.DrawTexture(new Rectangle(64, 0, (int)(HalfDimensions.X * 2), (int)(HalfDimensions.Y * 2)), offsetPosition);
 }
Beispiel #9
0
 public abstract void Render(RenderManager renderManager, Camera camera);