private void DrawOccluders() { Rectangle[] rects = new Rectangle[4]; rects[0] = new Rectangle(80, 200, 64, 200); rects[1] = new Rectangle(180, 200, 64, 200); rects[2] = new Rectangle(270, 200, 64, 200); rects[3] = new Rectangle(400, 200, 64, 200); //GraphicsDevice.SetRenderTarget(0, sceneRenderTarget); //graphics.GraphicsDevice.Clear(ClearOptions.Target, Color.Blue, 1f, 0, rects); //GraphicsDevice.SetRenderTarget(0, null); for (int i = 0; i < rects.Count(); i++) DrawSprite(blackTexture, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height, SpriteBlendMode.None, Color.Black); }
public override void Draw(GameTime gameTime) { bool current = data[index]; float transitionOffset = TransitionPosition; if (lastIndex == -1) transitionOffset *= (ScreenState == ScreenState.TransitionOn) ? 1 : -1; else if (ScreenState == ScreenState.TransitionOn) transitionOffset *= (lastIndex > index) ? -1 : 1; else { if (nextIndex == -1) transitionOffset *= -1; else transitionOffset *= (index > nextIndex) ? 1 : -1; } SpriteBatch spriteBatch = Manager.SpriteBatch; spriteBatch.Begin(); float scale = 3.5f; Rectangle source = spriteSheet[currentKey][0]; Vector2 spriteLoc = ScreenHelper.Center; spriteLoc -= (new Vector2(source.Width / 2, source.Height / 2) * scale); Rectangle destination; Color color = current ? Color.White : Color.Black; destination = new Rectangle((int)spriteLoc.X, (int)spriteLoc.Y, (int)(source.Width * scale), (int)(source.Height * scale)); #region Special Cases Rectangle[] extraSource = new Rectangle[10]; Rectangle[] extra = new Rectangle[10]; if (currentKey.Equals("smasher")) { //special draw handling extraSource[0] = spriteSheet["smasherball"][0]; extra[0] = new Rectangle(destination.X - destination.Width, destination.Y, (int)(extraSource[0].Width * scale), (int)(extraSource[0].Height * scale)); } else if (currentKey.Equals("birdbody")) { //bird contains two sprites so needs special draw handling extraSource[0] = spriteSheet["birdhead"][2]; extra[0] = new Rectangle(destination.X + (int)(73 * scale), destination.Y + (int)(51 * scale), (int)(extraSource[0].Width * scale), (int)(extraSource[0].Height * scale)); } else if (currentKey.Equals("blimp")) { scale = 4.5f; } else if (currentKey.Equals("giantgraybossship")) { scale = 4f; } else if (currentKey.Equals("killerhead")) { //likewise here extraSource[0] = spriteSheet["killerleftgun"][0]; extraSource[1] = spriteSheet["killerrightgun"][0]; extra[0] = new Rectangle(destination.X - (int)(25 * scale), destination.Y + (int)(19 * scale), (int)(extraSource[0].Width * scale), (int)(extraSource[0].Height * scale)); extra[1] = new Rectangle(destination.X + (int)(118 * scale), destination.Y + (int)(18 * scale), (int)(extraSource[1].Width * scale), (int)(extraSource[1].Height * scale)); } if (scale != 5f) { spriteLoc = ScreenHelper.Center; spriteLoc -= (new Vector2(source.Width / 2, source.Height / 2) * scale); destination.X = (int)(spriteLoc.X); destination.Y = (int)(spriteLoc.Y); destination.Width = (int)(source.Width * scale); destination.Height = (int)(source.Height * scale); for (int x = 0; x < extra.Count(); ++x) { if (extra[x] != Rectangle.Empty) { extra[x].Width = (int)(extraSource[x].Width * scale); extra[x].Height = (int)(extraSource[x].Height * scale); } } } #endregion Special Cases destination.X += (int)(transitionOffset * ScreenHelper.Viewport.Width); spriteBatch.Draw(spriteSheet.Texture, destination, source, color); for (int x = 0; x < extra.Count(); ++x) { if (extra[x] != Rectangle.Empty) { extra[x].X += (int)(transitionOffset * ScreenHelper.Viewport.Width); spriteBatch.Draw(spriteSheet.Texture, extra[x], extraSource[x], color); } } string text = current ? bosses[index].BossName : "?????"; Vector2 textDest = new Vector2(ScreenHelper.Viewport.Width / 2 + (float)(transitionOffset * ScreenHelper.Viewport.Width), ScreenHelper.Viewport.Height * 0.80f); Vector2 size = Manager.Font.MeasureString(text); Vector2 textorigin = size / 2; spriteBatch.DrawString(Manager.Font, text, textDest, Color.White, 0f, textorigin, 1f, SpriteEffects.None, 0); spriteBatch.End(); }
public void LoadContent(ContentManager content, string filename, Color boundingColor, float layer) { #region Getting Colors Texture2D tex = content.Load<Texture2D>(filename); Color[] data = new Color[tex.Width * tex.Height]; tex.GetData<Color>(data); //Get the data in 2D array form Color[,] colors = new Color[tex.Width, tex.Height]; int z = 0; for (int y = 0; y < tex.Height; y++) { for (int x = 0; x < tex.Width; x++, z++) { colors[x, y] = data[z]; } } #endregion Getting Colors #region Getting Rectangles int y1 = 1; int x1 = 1; int rectCount = 0; int lastXBound = 0; int nextXBound = 0; int height = tex.Height - 2; Rectangle[] rects = new Rectangle[41]; while (rectCount < rects.Count()) { while (colors[x1, 1] != boundingColor) { x1++; } nextXBound = x1; Rectangle rect = new Rectangle(lastXBound + 1, y1, nextXBound - lastXBound - 1, height); rects[rectCount] = rect; rectCount++; lastXBound = nextXBound; x1++; } #endregion Getting Rectangles #region Removing Source Rectangles for (int j = 0; j < data.Count(); j++) { if (data[j] == boundingColor) { data[j] = new Color(0, 0, 0, 0); } } texture = new Texture2D(ScreenHelper.GraphicsDevice, tex.Width, tex.Height); texture.SetData<Color>(data); #endregion Removing Source Rectangles #region Adding chars int charNext = 65; int i = 0; while (charNext <= 90) { letters.Add((char)charNext++, rects[i++]); } charNext = 49; while (charNext <= 57) { letters.Add((char)charNext++, rects[i++]); } letters.Add('0', rects[i++]); letters.Add('%', rects[i++]); letters.Add(':', rects[i++]); letters.Add('!', rects[i++]); letters.Add('?', rects[i++]); letters.Add('.', rects[i]); #endregion Adding chars Layer = layer; }