/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { base.LoadContent(); g = new SpriteBatch(GraphicsDevice); SpriteSheet = new SpriteSheet(Content.Load <Texture2D>("SpriteSheet"), 16, 16); EntitySheet = new EntitySpriteSheet(Content.Load <Texture2D>("EntitySheet"), 2, 16); World = new World(1000, 1000); player = new Player(0); player.SetLocation(World, 300, 600); ScreenWidth = GraphicsDevice.Viewport.Width; ScreenHeight = GraphicsDevice.Viewport.Height; }
public void Draw(float x, float y, float ScreenHeight, float ScreenWidth, SpriteBatch g, SpriteSheet sheet, EntitySpriteSheet ESheet) { int xoffset = (int)(x * SpriteSheet.SpriteSize % SpriteSheet.SpriteSize) * -1; int yoffset = (int)(y * SpriteSheet.SpriteSize % SpriteSheet.SpriteSize); int BlockWidth = (int)(ScreenWidth) / SpriteSheet.SpriteSize; int BlockHeight = (int)(ScreenHeight) / SpriteSheet.SpriteSize; x -= BlockWidth / 2; y -= BlockHeight / 2; int WidthBuffer = (int)(ScreenWidth * .1) / SpriteSheet.SpriteSize; int HeightBuffer = (int)(ScreenHeight * .1) / SpriteSheet.SpriteSize; for (int CurX = -1 * WidthBuffer; CurX < BlockWidth + WidthBuffer; CurX++) { for (int CurY = -1 * HeightBuffer; CurY < BlockHeight + HeightBuffer; CurY++) { try { if (BackTiles[CurX + (int)x, CurY + (int)y].NeedsToDraw) { BackTiles[CurX + (int)x, CurY + (int)y].Draw((int)(CurX * SpriteSheet.SpriteSize + xoffset), (int)(ScreenHeight - SpriteSheet.SpriteSize - CurY * SpriteSheet.SpriteSize + yoffset), SpriteSheet.SpriteSize, SpriteSheet.SpriteSize, g, sheet, 1); } if (Tiles[CurX + (int)x, CurY + (int)y].NeedsToDraw) { Tiles[CurX + (int)x, CurY + (int)y].Draw((int)(CurX * SpriteSheet.SpriteSize + xoffset), (int)(ScreenHeight - SpriteSheet.SpriteSize - CurY * SpriteSheet.SpriteSize + yoffset), SpriteSheet.SpriteSize, SpriteSheet.SpriteSize, g, sheet, .5f); } } catch { } } } foreach (IEntity Entity in Entities) { if (Entity is Player) { Entity.Draw((int)(ScreenWidth / 2), (int)(ScreenHeight / 2), g, ESheet, 0); } else { } } }