public void Draw(SpriteBatch spriteBatch, Camera camera, Rectangle screenBounds) { spriteBatch.Begin(); Point offset = new Point(-camera.Screen.X, -camera.Screen.Y); foreach (ICell cell in CellMap) { Texture2D texture; if (camera.Zoom == 0) { texture = cell.IsAlive ? GameTextures.CellAlive16 : GameTextures.CellDead16; } else if (camera.Zoom == 1) { texture = cell.IsAlive ? GameTextures.CellAlive8 : GameTextures.CellDead8; } else if (camera.Zoom == 2) { texture = cell.IsAlive ? GameTextures.CellAlive4 : GameTextures.CellDead4; } else if (camera.Zoom == 3) { texture = cell.IsAlive ? GameTextures.CellAlive2 : GameTextures.CellDead2; } else { texture = cell.IsAlive ? GameTextures.CellAlive1 : GameTextures.CellDead1; } Vector2 location = new Vector2(offset.X + (cell.Location.X * texture.Width), offset.Y + (cell.Location.Y * texture.Height)); spriteBatch.Draw(texture, location, null, Color.White); } spriteBatch.End(); }
public void Draw(SpriteBatch spriteBatch, Camera camera, Rectangle screenBounds) { //Set sampler to tile sprites instead of stretching spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone); //Get Textures based on zoom level Texture2D liveTexture; Texture2D deadTexture; if (camera.Zoom == 0) { deadTexture = GameTextures.CellDead16; liveTexture = GameTextures.CellAlive16; } else if (camera.Zoom == 1) { deadTexture = GameTextures.CellDead8; liveTexture = GameTextures.CellAlive8; } else if (camera.Zoom == 2) { deadTexture = GameTextures.CellDead4; liveTexture = GameTextures.CellAlive4; } else if (camera.Zoom == 3) { deadTexture = GameTextures.CellDead2; liveTexture = GameTextures.CellAlive2; } else { deadTexture = GameTextures.CellDead1; liveTexture = GameTextures.CellAlive1; } //Draw offset based on camera position Point offset = new Point(-camera.Screen.X, -camera.Screen.Y); //Small offset for the background texture so the background is always aligned with the map cells Vector2 backgroundNudge = new Vector2(offset.X % deadTexture.Width, offset.Y % deadTexture.Height); backgroundNudge += new Vector2(-deadTexture.Width, -deadTexture.Height); //Draw the background screen Rectangle screen = new Rectangle(0, 0, screenBounds.Width + deadTexture.Width * 2, screenBounds.Height + deadTexture.Height * 2); spriteBatch.Draw(deadTexture, backgroundNudge, screen, Color.White); foreach (ICell cell in Cells.Values) { Texture2D texture = cell.IsAlive ? liveTexture : deadTexture; Vector2 location = new Vector2(offset.X + (cell.Location.X * texture.Width), offset.Y + (cell.Location.Y * texture.Height)); spriteBatch.Draw(texture, location, null, Color.White); } spriteBatch.End(); }
public void Initialize() { Camera = new Camera(new Point(800, 600)); SetupMap(); }