public void DrawOnScreen(SpriteBatch sb, double layer) { sb.End(); sb.Begin(SpriteSortMode.Immediate,BlendState.Additive); foreach (ModWorld.Effect e in ModWorld.effects) e.Draw(sb); sb.End(); sb.Begin(); }
public override void Draw(SpriteBatch sb, Projectile p) { Vector2 pc = p.position+new Vector2(p.width/2f,p.height/2f); if (fired) { sb.End(); sb.Begin(SpriteSortMode.Immediate,BlendState.Additive); foreach (Spark spark in sparks) spark.Draw(sb,p,this); for (int i = 0; i < sparks.Count; i++) if (sparks[i].dead) sparks.RemoveAt(i--); sb.End(); sb.Begin(); if (sparks.Count == 0) p.Kill(); } else { fired = true; int r, g, b; Color c; float degrees; byte[] bytes = BitConverter.GetBytes(seed); Random rnd = new Random(); degrees = (float)(rnd.NextDouble()*360d); HsvToRgb(bytes[0]*360f/255f,bytes[1]/255f,1f,out r,out g,out b); c = new Color(r,g,b); for (int i = 0; i < 20; i++) sparks.Add(new MySpark(pc,Util.Vector((float)(1.5f+rnd.NextDouble()*.75f),360f/20f*i+degrees),c,80+rnd.Next(40))); degrees = (float)(rnd.NextDouble()*360d); HsvToRgb(bytes[2]*360f/255f,bytes[3]/255f,1f,out r,out g,out b); c = new Color(r,g,b); for (int i = 0; i < 40; i++) sparks.Add(new MySpark(pc,Util.Vector((float)(3f+rnd.NextDouble()*1.5f),360f/40f*i+degrees),c,80+rnd.Next(40))); } }
public void PreDrawItemInSlot(SpriteBatch sb, Color color, Item item, Vector2 pos, float sc, ref bool letDraw) { if (item.name != "Firefly in a Jar" && item.name != "Firefly in a Bottle") return; if (!item.RunMethod("ExternalGetFirefly")) return; ModWorld.EffectFirefly firefly = (ModWorld.EffectFirefly)Codable.customMethodReturn; if (firefly == null) return; sb.End(); sb.Begin(SpriteSortMode.Immediate,BlendState.Additive); firefly.DrawItem(sb,pos.X,(int)(pos.Y+2*sc),sc,item); sb.End(); sb.Begin(); ModWorld.effectsExtraUpdate.Add(firefly); }
internal override void DrawScene(GameTime gameTime) { if (spriteBatch != null && wallSprite != null && transform != null) { spriteBatch?.Begin(); spriteBatch?.Draw(wallSprite, transform); spriteBatch?.End(); } }
internal override void DrawScene(GameTime gameTime) { if (spriteBatch != null && playerSprite != null && plyerTextureTransform != null) { spriteBatch?.Begin(); spriteBatch?.Draw(playerSprite, plyerTextureTransform); spriteBatch?.Draw(enemySprite, enemyTextureTransform); spriteBatch?.Draw(upArrowSprite, upArrowTransform); spriteBatch?.Draw(downArrowSprite, downArrowTransForm); spriteBatch?.End(); } _guiSystem.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { // Big pixel graphics rendering { // Change the render target to surface GraphicsDevice.SetRenderTarget(renderSurface); GraphicsDevice.Clear(Color.Black); // Draws everything in the surface currentScene?.Draw(); if (currentScene != null && currentScene.HasPreMainDisplayEffectDraws) { GraphicsDevice.SetRenderTarget(preMainDisplayEffectRenderTarget); currentScene.PreMainDisplayEffectDraw(); } // Apply visual display effects if (EffectService is EffectService service && renderSurface != null) { renderSurface = service.ApplyEnabledDisplayEffects(renderSurface); } // Debug visual representation currentScene?.DebugDraw(); // Back to the normal render method GraphicsDevice.SetRenderTarget(null); // Render the surface to have the ingame screen SpriteBatch?.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp); SpriteBatch?.Draw( texture: renderSurface, destinationRectangle: new Rectangle(0, 0, (int)WindowSize.Width, (int)WindowSize.Height), sourceRectangle: new Rectangle(0, 0, InGameViewport.Width, InGameViewport.Height), color: Color.White ); SpriteBatch?.End(); } // Hi-res graphics rendering { // Render all UI elements in front of the render target texture currentScene?.UIDraw(); } base.Draw(gameTime); }
public void DrawOnScreen(SpriteBatch sb, double layer) { if (ModWorld.display == "off") return; if (Config.tileInterface != null) return; if (Config.npcInterface != null) return; sb.End(); sb.Begin(SpriteSortMode.Immediate,BlendState.NonPremultiplied); foreach (Player player in Main.player) { if (player == null) continue; if (!player.active) continue; if (player.dead || player.ghost) continue; if (ModWorld.display != "all") { if (player.whoAmi == Main.myPlayer && ModWorld.display != "my") continue; if (player.whoAmi != Main.myPlayer && ModWorld.display != "other") continue; } if (player.invis) continue; float alpha = GetBarAlpha(player); if (alpha <= 0) continue; int hp = player.statLife, hpMax = player.statLifeMax; int xx = (int)(player.position.X-Main.screenPosition.X)-12, yy = (int)(player.position.Y-16-Main.screenPosition.Y), ww = 44, hh = 12; Color color = new Color(255,255,255); color.A = (byte)(alpha*255); sb.Draw(texBack,new Rectangle(xx,yy,ww,hh),color); sb.Draw(texRed,new Rectangle(xx+2,yy+2,ww-4,hh-4),color); sb.Draw(texGreen,new Rectangle(xx+2,yy+2,(int)((1d*hp/hpMax)*(ww-4)),hh-4),color); } sb.End(); sb.Begin(); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Transparent); _spriteBatch?.Begin(transformMatrix: _camera.Transform, sortMode: SpriteSortMode.Immediate, blendState: BlendState.AlphaBlend); foreach (var effect in _effects) { effect.CurrentTechnique.Passes[0].Apply(); } foreach (var asset in _assets) { asset.Draw(_spriteBatch); } _player.Draw(_spriteBatch); _spriteBatch?.End(); base.Draw(gameTime); }
public static void BeginSpriteBatch() { SpriteBatch.Begin(blendState: BlendState.AlphaBlend, samplerState: SamplerState, rasterizerState: CropOn ? ScissorRasterizerState : null); }
protected override void Draw(GameTime gameTime) { //FIX POSTPROCESSING spriteBatch.Begin(); spriteBatch.End(); BloomComponent.BeginDraw(); GraphicsDevice.Clear(Color.Black); for (int i = 0; i < CelestialBodies.Count; i++) { if (CelestialBodies[i].RenderWithBloom) { CelestialBodies[i].Render(); } } base.Draw(gameTime); Grid.Render(Observer.Camera.ViewMatrix, Observer.Camera.ProjectionsMatrix, Matrix.CreateTranslation(new Vector3(CelestialBody.GLOBALX - 3500000, CelestialBody.GLOBALY, CelestialBody.GLOBALZ - 3500000))); GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.RasterizerState = RasterizerState.CullNone; GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; for (int i = 0; i < CelestialBodies.Count; i++) { CelestialBodies[i].DrawEllipsoid(); if (!CelestialBodies[i].RenderWithBloom) { spriteBatch.Begin(); spriteBatch.End(); var v1 = Vector3.Zero; var v2 = new Vector3((float)CelestialBodies[i].XCoord + CelestialBody.GLOBALX, (float)CelestialBodies[i].ZCoord + CelestialBody.GLOBALY, (float)CelestialBodies[i].YCoord + CelestialBody.GLOBALZ); var direction = v2 - v1; direction.Normalize(); Ray Ray = new Ray(Vector3.Zero, direction); CelestialBodies[i].IsAllowedToRender = !(Ray.Intersects(CelestialBodies.Find(p => p.Name == "Sun").BoundingBox) > 1) || (v2 - v1).Length() < (new Vector3(CelestialBody.GLOBALX, CelestialBody.GLOBALY, CelestialBody.GLOBALZ) - v1).Length(); CelestialBodies[i].Render(); } spriteBatch.Begin(); CelestialBodies[i].DrawInformation(spriteBatch); spriteBatch.End(); if (ShowDebug) { BoundingBoxRenderer.Render(CelestialBodies[i].BoundingBox, GraphicsDevice, Observer.Camera.ViewMatrix, Observer.Camera.ProjectionsMatrix, Color.Red); } } _total_frames++; if (ShowDebug) { spriteBatch.Begin(); Observer.Camera.RenderDebug(spriteBatch, DebugFont); CelestialBody.DrawDebug(spriteBatch, DebugFont); spriteBatch.DrawString(DebugFont, fps + " frames per second", new Vector2(GraphicsDevice.PresentationParameters.BackBufferWidth - UI.Width - 150, 15), Color.White); spriteBatch.End(); } }
protected override void Draw(GameTime gameTime) { spriteBatch.Begin(); Vector2 Backy = new Vector2(0, 0); Vector2 HealthPosition = new Vector2(0, 10); Vector2 VRedHP1 = new Vector2(225, 20); Vector2 VRedHP2 = new Vector2(200, 20); Vector2 VRedHP3 = new Vector2(175, 20); Vector2 VBlueHP1 = new Vector2(559, 20); Vector2 VBlueHP2 = new Vector2(584, 20); Vector2 VBlueHP3 = new Vector2(609, 20); Vector2 RightPaddleVector = new Vector2(704, RightPaddleYPosition); Vector2 LeftPaddleVector = new Vector2(0, LeftPaddleYPosition); float XPosDouble = System.Convert.ToSingle(ballXPosition); float YPosDouble = System.Convert.ToSingle(ballYPosition); Vector2 BallVector = new Vector2(XPosDouble, YPosDouble); Vector2 SpritePos = new Vector2(400, 10); Vector2 Titlevector = new Vector2(0, 0); if (GameStart == false && TitleStatus == 10) { spriteBatch.Draw(Title1, Titlevector); } if (GameStart == false && TitleStatus == 20) { spriteBatch.Draw(Title2, Titlevector); } if (GameStart == true && GameFinished == false) { spriteBatch.Draw(Background, Backy); spriteBatch.Draw(MasterBallRed, VRedHP1); //Tekent de goede hoeveelheid levens if (LeftPlayerLives >= 2) { spriteBatch.Draw(Ball2Red, VRedHP2); } if (LeftPlayerLives == 3) { spriteBatch.Draw(Ball3Red, VRedHP3); } spriteBatch.Draw(MasterBallBlue, VBlueHP1); if (RightPlayerLives >= 2) { spriteBatch.Draw(Ball2Blue, VBlueHP2); } if (RightPlayerLives == 3) { spriteBatch.Draw(Ball3Blue, VBlueHP3); } spriteBatch.Draw(Health, HealthPosition); if (LeftPlayerLives == 1) { spriteBatch.Draw(Groudon, LeftPaddleVector); GrootteSpriteRood = 144; } if (LeftPlayerLives == 2) { spriteBatch.Draw(Flareon, LeftPaddleVector); GrootteSpriteRood = 120; } if (LeftPlayerLives == 3) { spriteBatch.Draw(Charmander, LeftPaddleVector); GrootteSpriteRood = 96; } //Selecteerd de goede sprites voor de paddles if (RightPlayerLives == 1) { spriteBatch.Draw(Kyogre, RightPaddleVector); GrootteSpriteBlauw = 144; } if (RightPlayerLives == 2) { spriteBatch.Draw(Vaporeon, RightPaddleVector); GrootteSpriteBlauw = 120; } if (RightPlayerLives == 3) { spriteBatch.Draw(Squirtle, RightPaddleVector); GrootteSpriteBlauw = 96; } if (RightPlayerLives == 0) //Game einde { spriteBatch.Draw(RedVictory, Backy); GameFinished = true; } if (LeftPlayerLives == 0) { spriteBatch.Draw(BlueVictory, Backy); GameFinished = true; } spriteBatch.Draw(Ball, BallVector); } spriteBatch.End(); // TODO: Add your drawing code here base.Draw(gameTime); }
private void _drawLeaderboards(SpriteBatch spriteBatch, SpriteFont[] fonts) { spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); try { if (AppMain.dm_xbox_show_progress != 100) { spriteBatch.Draw(LiveFeature.a_bg, new Rectangle(10, 55 - (int)(40.0 * (double)((float)AppMain.dm_xbox_show_progress / 100f)), 230, (int)(220.0 * (double)((float)AppMain.dm_xbox_show_progress / 100f))), new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0.0f); spriteBatch.Draw(LiveFeature.a_bg, new Rectangle(240, 55 - (int)(40.0 * (double)((float)AppMain.dm_xbox_show_progress / 100f)), 230, (int)(220.0 * (double)((float)AppMain.dm_xbox_show_progress / 100f))), new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0f); } else { spriteBatch.Draw(LiveFeature.a_bg, new Rectangle(10, 15, 230, 220), new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0.0f); spriteBatch.Draw(LiveFeature.a_bg, new Rectangle(240, 15, 230, 220), new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0f); } if (AppMain.dm_xbox_show_progress != 100) { return; } int curStage = this.curStage; if (curStage > 23) { curStage -= 24; } string text1; if (curStage < 16) { string zoneName = LiveFeature.zone_names[curStage / 4]; if (curStage % 4 == 3) { text1 = string.Format(zoneName, (object)Strings.ID_BOSS); } else { text1 = string.Format(zoneName, (object)string.Format(Strings.ID_ACT, (object[])new string[1] { string.Concat((object)(curStage % 4 + 1)) })); } } else if (curStage == 16) { text1 = Strings.ID_FINALZONE; } else { text1 = string.Format(LiveFeature.zone_names[5], (object[])new string[1] { string.Concat((object)(curStage - 16)) }); } Vector2 vector2 = fonts[2].MeasureString(text1); spriteBatch.DrawString(fonts[2], text1, new Vector2((float)(240 - ((int)vector2.X >> 1)), 27f), Color.White); LiveFeature.arrow_offset += 2; if (LiveFeature.arrow_offset > 16) { LiveFeature.arrow_offset = -16; } Rectangle arrow1Left = LiveFeature.arrow1_Left; arrow1Left.X -= Math.Abs(LiveFeature.arrow_offset); spriteBatch.Draw(LiveFeature.arrowImg, arrow1Left, new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0.0f); Rectangle arrow1Right = LiveFeature.arrow1_Right; arrow1Right.X += Math.Abs(LiveFeature.arrow_offset); spriteBatch.Draw(LiveFeature.arrowImg, arrow1Right, new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0f); string str = string.Concat((object)(curStage + 1)); int index1 = 0; int length = str.Length; while (index1 < str.Length) { LiveFeature.num_dst_rect.X = 240 - 10 * length; LiveFeature.num_src_rect.X = str[index1] != '0' ? 16 * ((int)str[index1] - 49) : 144; spriteBatch.Draw(LiveFeature.nums, LiveFeature.num_dst_rect, new Rectangle?(LiveFeature.num_src_rect), Color.White); ++index1; --length; } LiveFeature.num_src_rect.X = 160; LiveFeature.num_src_rect.Width = 32; LiveFeature.num_dst_rect.X = 240; spriteBatch.Draw(LiveFeature.nums, LiveFeature.num_dst_rect, new Rectangle?(LiveFeature.num_src_rect), Color.White); LiveFeature.num_src_rect.Width = 16; LiveFeature.num_dst_rect.X = 250; LiveFeature.num_src_rect.X = 16; spriteBatch.Draw(LiveFeature.nums, LiveFeature.num_dst_rect, new Rectangle?(LiveFeature.num_src_rect), Color.White); LiveFeature.num_dst_rect.X = 260; LiveFeature.num_src_rect.X = 48; spriteBatch.Draw(LiveFeature.nums, LiveFeature.num_dst_rect, new Rectangle?(LiveFeature.num_src_rect), Color.White); int index2 = AppMain.g_gs_env_language == 0 || AppMain.g_gs_env_language == 1 || (AppMain.g_gs_env_language == 4 || AppMain.g_gs_env_language == 5) ? 0 : 1; string idLbRank = Strings.ID_LB_RANK; vector2 = fonts[1].MeasureString(idLbRank); spriteBatch.DrawString(fonts[1], idLbRank, new Vector2((float)(LiveFeature.table_x[0, index2] - ((int)vector2.X >> 1)), 47f), Color.White); string idLbGtag = Strings.ID_LB_GTAG; vector2 = fonts[1].MeasureString(idLbGtag); spriteBatch.DrawString(fonts[1], idLbGtag, new Vector2((float)(LiveFeature.table_x[1, index2] - ((int)vector2.X >> 1)), 47f), Color.White); string idBesttime = Strings.ID_BESTTIME; vector2 = fonts[1].MeasureString(idBesttime); spriteBatch.DrawString(fonts[1], idBesttime, new Vector2((float)(LiveFeature.table_x[2, index2] - ((int)vector2.X >> 1)), 47f), Color.White); string idLbDate = Strings.ID_LB_DATE; vector2 = fonts[1].MeasureString(idLbDate); spriteBatch.DrawString(fonts[1], idLbDate, new Vector2((float)(LiveFeature.table_x[3, index2] - ((int)vector2.X >> 1)), 47f), Color.White); int num = 67; if (this.l_status[this.curStage] == LiveFeature.LBStatus.StartedRead) { LiveFeature._drawWrapText(Strings.ID_LOADING, 240, 144, 450, Color.White, true, fonts[1], spriteBatch); } else if (this.l_status[this.curStage] == LiveFeature.LBStatus.ReadFail) { LiveFeature._drawWrapText(Strings.ID_LB_UNABLE, 240, 144, 450, Color.White, true, fonts[1], spriteBatch); } else if (this.hiScoresTables[this.curStage] != null && this.hiScoresTables[this.curStage].Length != 0) { if (AppMain.dm_xbox_show_progress != 100) { return; } Color white = Color.White; for (int index3 = 0; index3 < this.hiScoresTables[this.curStage].Length; ++index3) { if (index3 < 5 || index3 >= 5 && this.hiScoresTables[this.curStage][index3].isMe) { Color color = this.hiScoresTables[this.curStage][index3].isMe ? new Color(154 - Math.Abs(LiveFeature.arrow_offset << 3), (int)byte.MaxValue, 100 - Math.Abs(LiveFeature.arrow_offset << 2)) : Color.WhiteSmoke; string text2 = string.Concat((object)this.hiScoresTables[this.curStage][index3].index); vector2 = fonts[0].MeasureString(text2); spriteBatch.DrawString(fonts[0], text2, new Vector2((float)(LiveFeature.table_x[0, index2] - ((int)vector2.X >> 1)), (float)num), color); string name = this.hiScoresTables[this.curStage][index3].name; vector2 = fonts[0].MeasureString(name); spriteBatch.DrawString(fonts[0], name, new Vector2((float)(LiveFeature.table_x[1, index2] - ((int)vector2.X >> 1)), (float)num), color); string text3; if (this.curStage > 23) { ushort min = 0; ushort sec = 0; ushort msec = 0; AppMain.AkUtilFrame60ToTime((uint)this.hiScoresTables[this.curStage][index3].value, ref min, ref sec, ref msec); StringBuilder stringBuilder = new StringBuilder(); if (min < (ushort)10) { stringBuilder.Append("0"); } stringBuilder.Append(min); stringBuilder.Append("'"); if (sec < (ushort)10) { stringBuilder.Append("0"); } stringBuilder.Append(sec); stringBuilder.Append("''"); if (msec < (ushort)10) { stringBuilder.Append("0"); } stringBuilder.Append(msec); text3 = stringBuilder.ToString(); } else { text3 = string.Concat((object)this.hiScoresTables[this.curStage][index3].value); } vector2 = fonts[0].MeasureString(text3); spriteBatch.DrawString(fonts[0], text3, new Vector2((float)(LiveFeature.table_x[2, index2] - ((int)vector2.X >> 1)), (float)num), color); string text4 = string.Concat((object)this.hiScoresTables[this.curStage][index3].date); vector2 = fonts[0].MeasureString(text4); spriteBatch.DrawString(fonts[0], text4, new Vector2((float)(LiveFeature.table_x[3, index2] - ((int)vector2.X >> 1)), (float)num), color); num += (int)vector2.Y; } } } else { LiveFeature._drawWrapText(Strings.ID_LB_NORECORDS, 240, 144, 450, Color.White, true, fonts[1], spriteBatch); } } finally { spriteBatch.End(); } }
public static void drawgame(SpriteBatch sb, GraphicsDevice gd, Matrix matrix, PenumbraComponent penumbra, GameTime gameTime) { if (Play.mainmenu) { gd.Clear(Color.CornflowerBlue); sb.Begin(); sb.Draw(Drawing.whitetexture, new Rectangle(200, 120, 400, 30), Color.Green); sb.DrawString(Drawing.font, "Start Game", new Vector2(250, 120), Color.White); sb.Draw(Drawing.whitetexture, new Rectangle(200, 160, 400, 30), Color.Red); sb.DrawString(Drawing.font, "Exit", new Vector2(350, 160), Color.White); sb.End(); } else { if (Play.escmenu) { gd.Clear(Color.CornflowerBlue); sb.Begin(); sb.Draw(Drawing.whitetexture, new Rectangle(200, 120, 400, 30), Color.Green); sb.DrawString(Drawing.font, "Continue", new Vector2(250, 120), Color.White); sb.Draw(Drawing.whitetexture, new Rectangle(200, 160, 400, 30), Color.Orange); sb.DrawString(Drawing.font, "Restart", new Vector2(250, 160), Color.White); sb.Draw(Drawing.whitetexture, new Rectangle(200, 200, 400, 30), Color.Red); sb.DrawString(Drawing.font, "Exit", new Vector2(250, 200), Color.White); sb.End(); } else { penumbra.BeginDraw(); gd.Clear(Color.White); penumbra.Transform = matrix; sb.Begin(SpriteSortMode.Immediate, null, null, null, null, null, matrix); for (int i = 0; i < 500; i++) { if (Play.ball[i] != new Vector2(0, 0)) { sb.Draw(balltexture, new Vector2(Play.ball[i].X * 32 - 16, Play.ball[i].Y * 32 - 16), Play.balllight[i].Color); } } sb.Draw(Drawing.playertexture, new Vector2(Player.x * 32 - 32, Player.y * 32 - 32), Player.color); for (int x = 0; x < Map.width; x++) { for (int y = 0; y < Map.height; y++) { if (Map.tile[x][y] == 2) { sb.Draw(whitetexture, new Vector2(x * 32 - 16, y * 32 - 16), Color.Green); } } } sb.End(); // Draw items affected by lighting here ... penumbra.Draw(gameTime); if (Play.level == 0) { sb.Begin(SpriteSortMode.Immediate, null, null, null, null, null, matrix); sb.DrawString(Drawing.font, "WASD = move", new Vector2(100, 0), Color.White); sb.DrawString(Drawing.font, "Shift,Ctrl = Zoom", new Vector2(100, 50), Color.White); sb.DrawString(Drawing.font, "Mouse drag = Throw balls", new Vector2(100, 100), Color.White); sb.End(); } if (Play.level == 1) { sb.Begin(SpriteSortMode.Immediate, null, null, null, null, null, matrix); sb.DrawString(Drawing.font, "Level 2", new Vector2(100, 0), Color.White); sb.End(); } if (Play.level == 2) { sb.Begin(SpriteSortMode.Immediate, null, null, null, null, null, matrix); sb.DrawString(Drawing.font, "Level 3", new Vector2(100, 0), Color.White); sb.End(); } if (Play.level == 3) { sb.Begin(SpriteSortMode.Immediate, null, null, null, null, null, matrix); sb.DrawString(Drawing.font, "Level 4", new Vector2(100, 0), Color.White); sb.End(); } if (Play.level == 4) { sb.Begin(SpriteSortMode.Immediate, null, null, null, null, null, matrix); sb.DrawString(Drawing.font, "Level 5", new Vector2(100, 0), Color.White); sb.End(); } sb.Begin(); sb.DrawString(Drawing.font, "FPS: " + fps, new Vector2(0, 0), Color.White); //sb.DrawString(Drawing.font, "UPS: " + ups, new Vector2(0, 30), Color.White); sb.End(); // Draw items NOT affected by lighting here ... (UI, for example) } } }
public override void Draw(SpriteBatch spriteBatch) { //base: draw the overlay. base.Draw(spriteBatch); spriteBatch.Begin(samplerState: SamplerState.PointClamp); //draw a string telling the player how to continue/quit. spriteBatch.DrawString(font, newGameText, newGamePos, Color.Green ); //draw a string to show who won. string winText = $"Player {winner.Id + 1} Wins!"; spriteBatch.DrawString(largeFont, winText, WindowTools.PaddingToPixelCoordinate(0.5f, 0.05f, 0, 0) - new Vector2(largeFont.MeasureString(winText).X / 2, 0), winner.Colour ); //draw the final score alongside each character sprite. Vector2 spriteOffset = uiScale / 2 * UiTools.BoundsToVector(winner.CharacterSprite.Bounds); Vector2 pos = WindowTools.PaddingToPixelCoordinate(0.5f, 0.4f, 0, 0); //(character sprites) spriteBatch.Draw( texture: boundary, position: pos - spriteOffset - sepDistance - new Vector2(3 * uiScale, 0), scale: uiScaleVector, color: winner.Colour ); spriteBatch.Draw( texture: winner.CharacterSprite, position: pos - spriteOffset - sepDistance, scale: uiScaleVector); spriteBatch.Draw( texture: boundary, position: pos - spriteOffset + sepDistance + new Vector2(3 * uiScale, 0), scale: uiScaleVector, color: loser.Colour ); spriteBatch.Draw( texture: loser.CharacterSprite, position: pos - spriteOffset + sepDistance, scale: uiScaleVector); //(score) string text = $"{winner.WinProgress} - {loser.WinProgress}"; Vector2 size = font.MeasureString(text); spriteBatch.DrawString(font, text, pos - size / 2, Color.White ); spriteBatch.End(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); spaceShip.Draw(); foreach (Shield shield in shields) { shield.Draw(); } alienFleet.Draw(); ufo.Draw(spaceShip); gameBorder.Draw(); spriteBatch.DrawString(gameContent.labelFont, "Lives: " + livesRemaining.ToString(), new Vector2(40, 10), Color.White); Vector2 levelSpace = gameContent.labelFont.MeasureString("Level: " + level.ToString()); spriteBatch.DrawString(gameContent.labelFont, "Level: " + level.ToString(), new Vector2((screenWidth - levelSpace.X) / 2, 10), Color.White); spriteBatch.DrawString(gameContent.labelFont, "Score: " + score.ToString(), new Vector2(screenWidth - 200, 10), Color.White); if (readyToStart) { if (spaceShip.Visible && !hitBottom) { ufo.Visible = false; string startMsg = "Press <Space> or Click to start the level"; Vector2 startSpace = gameContent.labelFont.MeasureString(startMsg); spriteBatch.DrawString(gameContent.labelFont, startMsg, new Vector2((screenWidth - startSpace.X) / 2, screenHeight / 16), Color.White); } else if (livesRemaining > 0) { for (int x = 0; x < 11; x++) { for (int y = 0; y < 5; y++) { foreach (Blaster blaster in alienFleet.aliens[x, y].blasters) { blaster.Visible = false; } } } spaceShip.RespawnSpaceShip(); livesRemaining--; readyToStart = false; } else { string endMsg = "Game Over"; Vector2 endSpace = gameContent.labelFont.MeasureString(endMsg); spriteBatch.DrawString(gameContent.labelFont, endMsg, new Vector2((screenWidth - endSpace.X) / 2, screenHeight / 16 - endSpace.Y), Color.White); string startMsg = "Press <Space> or Click to start the level"; Vector2 startSpace = gameContent.labelFont.MeasureString(startMsg); spriteBatch.DrawString(gameContent.labelFont, startMsg, new Vector2((screenWidth - startSpace.X) / 2, screenHeight / 16 + endSpace.Y), Color.White); } } else if (aliensKilled % 55 == 0 && firstTime) { alienFleet = new AlienFleet(50, 150, screenWidth, spaceShip.Y, spriteBatch, gameContent); foreach (Bullet bullet in spaceShip.bullets) { bullet.Visible = false; } readyToStart = true; firstTime = false; alienFireRate /= 2; level++; livesRemaining++; foreach (Shield shield in shields) { for (int x = 0; x < level; x++) { shield.Rebuild(); } } } spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { //bgColor = new Color(redIntensity, greenIntensity, blueIntensity); GraphicsDevice.Clear(Color.LightBlue); if (gameState.CurrentStage == GameStage.GameStart) { spriteBatch.Begin(); spriteBatch.Draw(gameState.Background, backgroundRect, Color.White); spriteBatch.DrawString(font, "My Game", titleVector, Color.Green); spriteBatch.DrawString(font, String.Format("{0:hh:mm:ss}", DateTime.Now), timeVector, Color.Orange); spriteBatch.End(); } else if (gameState.CurrentStage == GameStage.InGame) { spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); spriteBatch.Draw(gameState.Background, Vector2.Zero, backgroundRect, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0); spriteBatch.DrawString(font, "My Game", titleVector, Color.Red, 0, Vector2.Zero, 1, SpriteEffects.None, 0.5f); spriteBatch.DrawString(font, String.Format("{0:hh:mm:ss}", DateTime.Now), timeVector, Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0.5f); spriteBatch.DrawString(font, String.Format("Shoot Count: {0}", gameState.ShootCount.ToString()), timeVector + new Vector2(-100, 10), Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0.5f); spriteBatch.DrawString(font, String.Format("Score: {0}", gameState.Score.ToString()), timeVector + new Vector2(-100, 30), Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0.5f); spriteBatch.Draw(smallBall.Texture, smallBall.Position, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1); spriteBatch.Draw(mediumBall.Texture, mediumBall.Position, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1); spriteBatch.Draw(bigBall.Texture, bigBall.Position, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1); spriteBatch.Draw(shootGun.Texture, shootGun.Position, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1); spriteBatch.End(); if (humanBallHideTime == 0) { spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); spriteBatch.Draw(animatedBall, humanBall.Position, new Rectangle(currentFrame.X * frameSize.X, currentFrame.Y * frameSize.Y, frameSize.X, frameSize.Y), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1); spriteBatch.End(); } } else if (gameState.CurrentStage == GameStage.GameOver) { spriteBatch.Begin(); spriteBatch.Draw(gameState.Background, backgroundRect, Color.White); spriteBatch.End(); } else if (gameState.CurrentStage == GameStage.GameWin) { spriteBatch.Begin(); spriteBatch.Draw(gameState.Background, backgroundRect, Color.White); spriteBatch.End(); } // TODO: Add your drawing code here base.Draw(gameTime); }
private void DrawBoundingBoxes(Meteor.Resources.Model model, Camera camera) { int meshIndex = 0; Viewport v = graphicsDevice.Viewport; float farDistance = camera.farPlaneDistance; // Matrices to project into screen space Matrix worldViewProjection = camera.view * camera.projection; Matrix invClient = Matrix.Invert(Matrix.CreateOrthographicOffCenter(0, v.Width, v.Height, 0, -1, 1)); foreach (MeshInstanceGroup instancedGroup in model.MeshInstanceGroups.Values) { BoundingBox box = instancedGroup.boundingBox; // Assign the box corners boxCorners[0] = new Vector3(box.Min.X, box.Max.Y, box.Max.Z); boxCorners[1] = new Vector3(box.Max.X, box.Max.Y, box.Max.Z); // maximum boxCorners[2] = new Vector3(box.Max.X, box.Min.Y, box.Max.Z); boxCorners[3] = new Vector3(box.Min.X, box.Min.Y, box.Max.Z); boxCorners[4] = new Vector3(box.Min.X, box.Max.Y, box.Min.Z); boxCorners[5] = new Vector3(box.Max.X, box.Max.Y, box.Min.Z); boxCorners[6] = new Vector3(box.Max.X, box.Min.Y, box.Min.Z); boxCorners[7] = new Vector3(box.Min.X, box.Min.Y, box.Min.Z); // minimum //Color[] colors = { Color.Cyan, Color.White, Color.Magenta, Color.Blue, // Color.Green, Color.Yellow, Color.Red, Color.Black };XZ spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); int visible = 0; foreach (MeshInstance meshInstance in instancedGroup.visibleInstances) { if (meshInstance == null) { continue; } // If we have exceeded the visible count, we have already rendered // all visible instances if (visible >= instancedGroup.totalVisible) { break; } Matrix modelTransform = meshInstance.Transform; Vector2 rectMin = new Vector2(v.Width, v.Height); Vector2 rectMax = Vector2.Zero; float minDistance = camera.farPlaneDistance; for (int i = 0; i < boxCorners.Length; i++) { model.boxVertices[i].Position = Vector3.Transform(boxCorners[i], modelTransform); model.boxVertices[i].Color = Color.Cyan; // Determin the closest distance point in the bounding box float camDistance = Vector3.Distance(model.boxVertices[i].Position, camera.position); minDistance = Math.Min(camDistance, minDistance); // Project the corners of the bounding box onto screen space Vector4 position = new Vector4(model.boxVertices[i].Position, 1); Vector4.Transform(ref position, ref worldViewProjection, out position); position /= position.W; Vector2 clientResult = Vector2.Transform(new Vector2(position.X, position.Y), invClient); rectMin.X = (int)Math.Min((float)clientResult.X, (float)rectMin.X); rectMin.Y = (int)Math.Min((float)clientResult.Y, (float)rectMin.Y); rectMax.X = (int)Math.Max((float)clientResult.X, (float)rectMax.X); rectMax.Y = (int)Math.Max((float)clientResult.Y, (float)rectMax.Y); } Vector3 topLeft = v.Unproject(new Vector3(rectMin, minDistance), camera.projection, camera.view, camera.worldMatrix); Vector3 bottomRight = v.Unproject(new Vector3(rectMax, minDistance), camera.projection, camera.view, camera.worldMatrix); // Transform the temporary bounding boxes with the model instance's world matrix // TODO: Update these boxes only when intances are updated // Render the bounding box for this instance if (camera.frustum.Contains(meshInstance.boundingSphere) != ContainmentType.Disjoint) { // Add a bounding sphere to the list of shapes to draw //ShapeRenderer.AddBoundingSphere(meshInstance.BSphere, Color.Red); for (int i = 0; i < basicEffect.CurrentTechnique.Passes.Count; i++) { basicEffect.CurrentTechnique.Passes[i].Apply(); graphicsDevice.DrawUserIndexedPrimitives <VertexPositionColor>( PrimitiveType.LineList, model.boxVertices, 0, 8, Meteor.Resources.Model.bBoxIndices, 0, 12); } } // Render our shapes now //ShapeRenderer.Draw(camera.View, camera.Projection); // Add to the total visible visible++; } spriteBatch.End(); meshIndex++; } // End box rendering }
private void DrawSonar(SpriteBatch spriteBatch, Rectangle rect) { displayBorderSize = 0.2f; center = new Vector2(rect.X + rect.Width * 0.5f, rect.Center.Y); displayRadius = (rect.Width / 2.0f) * (1.0f - displayBorderSize); displayScale = displayRadius / range * zoom; if (screenBackground != null) { screenBackground.Draw(spriteBatch, center, 0.0f, rect.Width / screenBackground.size.X); } if (IsActive) { if (isLastPingDirectional && directionalPingCircle != null) { directionalPingCircle.Draw(spriteBatch, center, Color.White * (1.0f - pingState), rotate: MathUtils.VectorToAngle(lastPingDirection), scale: (displayRadius / directionalPingCircle.size.X) * pingState); } else { pingCircle.Draw(spriteBatch, center, Color.White * (1.0f - pingState), 0.0f, (displayRadius * 2 / pingCircle.size.X) * pingState); } } float signalStrength = 1.0f; if (UseTransducers) { signalStrength = 0.0f; foreach (ConnectedTransducer connectedTransducer in connectedTransducers) { signalStrength = Math.Max(signalStrength, connectedTransducer.SignalStrength); } } Vector2 transducerCenter = UseTransducers && connectedTransducers.Count > 0 ? GetTransducerCenter() : item.WorldPosition; if (item.Submarine != null && !DetectSubmarineWalls) { float simScale = displayScale * Physics.DisplayToSimRation * zoom; foreach (Submarine submarine in Submarine.Loaded) { if (UseTransducers ? !connectedTransducers.Any(t => submarine == t.Transducer.Item.Submarine || submarine.DockedTo.Contains(t.Transducer.Item.Submarine)) : submarine != item.Submarine && !submarine.DockedTo.Contains(item.Submarine)) { continue; } if (submarine.HullVertices == null) { continue; } Vector2 offset = ConvertUnits.ToSimUnits(submarine.WorldPosition - transducerCenter); for (int i = 0; i < submarine.HullVertices.Count; i++) { Vector2 start = (submarine.HullVertices[i] + offset) * simScale; start.Y = -start.Y; Vector2 end = (submarine.HullVertices[(i + 1) % submarine.HullVertices.Count] + offset) * simScale; end.Y = -end.Y; bool startOutside = start.LengthSquared() > displayRadius * displayRadius; bool endOutside = end.LengthSquared() > displayRadius * displayRadius; if (startOutside && endOutside) { continue; } else if (startOutside) { if (MathUtils.GetLineCircleIntersections(Vector2.Zero, DisplayRadius, end, start, true, out Vector2? intersection1, out Vector2? intersection2) == 1) { GUI.DrawLine(spriteBatch, center + intersection1.Value, center + end, Color.LightBlue * signalStrength, width: 3); } } else if (endOutside) { if (MathUtils.GetLineCircleIntersections(Vector2.Zero, DisplayRadius, start, end, true, out Vector2? intersection1, out Vector2? intersection2) == 1) { GUI.DrawLine(spriteBatch, center + start, center + intersection1.Value, Color.LightBlue * signalStrength, width: 3); } } else { GUI.DrawLine(spriteBatch, center + start, center + end, Color.LightBlue * signalStrength, width: 3); } } } } if (sonarBlips.Count > 0) { spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive); foreach (SonarBlip sonarBlip in sonarBlips) { DrawBlip(spriteBatch, sonarBlip, transducerCenter, center, sonarBlip.FadeTimer / 2.0f * signalStrength); } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); } if (useDirectionalPing && IsActive) { Vector2 sector1 = MathUtils.RotatePointAroundTarget(pingDirection * displayRadius, Vector2.Zero, DirectionalPingSector * 0.5f); Vector2 sector2 = MathUtils.RotatePointAroundTarget(pingDirection * displayRadius, Vector2.Zero, -DirectionalPingSector * 0.5f); GUI.DrawLine(spriteBatch, center, center + sector1, Color.LightCyan * 0.2f, width: 3); GUI.DrawLine(spriteBatch, center, center + sector2, Color.LightCyan * 0.2f, width: 3); } if (GameMain.DebugDraw) { GUI.DrawString(spriteBatch, rect.Location.ToVector2(), sonarBlips.Count.ToString(), Color.White); } if (screenOverlay != null) { screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width / screenOverlay.size.X); } if (signalStrength <= 0.5f) { signalWarningText.Text = TextManager.Get(signalStrength <= 0.0f ? "SonarNoSignal" : "SonarSignalWeak"); signalWarningText.Color = signalStrength <= 0.0f ? Color.Red : Color.Orange; signalWarningText.Visible = true; } else { signalWarningText.Visible = false; } if (GameMain.GameSession == null) { return; } DrawMarker(spriteBatch, GameMain.GameSession.StartLocation.Name, (Level.Loaded.StartPosition - transducerCenter), displayScale, center, (rect.Width * 0.5f)); DrawMarker(spriteBatch, GameMain.GameSession.EndLocation.Name, (Level.Loaded.EndPosition - transducerCenter), displayScale, center, (rect.Width * 0.5f)); foreach (AITarget aiTarget in AITarget.List) { if (!aiTarget.Enabled) { continue; } if (string.IsNullOrEmpty(aiTarget.SonarLabel) || aiTarget.SoundRange <= 0.0f) { continue; } if (Vector2.DistanceSquared(aiTarget.WorldPosition, transducerCenter) < aiTarget.SoundRange * aiTarget.SoundRange) { DrawMarker(spriteBatch, aiTarget.SonarLabel, aiTarget.WorldPosition - transducerCenter, displayScale, center, (rect.Width * 0.47f)); } } if (GameMain.GameSession.Mission != null) { var mission = GameMain.GameSession.Mission; if (!string.IsNullOrWhiteSpace(mission.SonarLabel) && mission.SonarPosition != Vector2.Zero) { DrawMarker(spriteBatch, mission.SonarLabel, mission.SonarPosition - transducerCenter, displayScale, center, (rect.Width * 0.47f)); } } foreach (Submarine sub in Submarine.Loaded) { if (!sub.OnSonar) { continue; } if (UseTransducers ? connectedTransducers.Any(t => sub == t.Transducer.Item.Submarine || sub.DockedTo.Contains(t.Transducer.Item.Submarine)) : sub == item.Submarine && sub.DockedTo.Contains(item.Submarine)) { continue; } if (sub.WorldPosition.Y > Level.Loaded.Size.Y) { continue; } DrawMarker(spriteBatch, sub.Name, sub.WorldPosition - transducerCenter, displayScale, center, (rect.Width * 0.45f)); } if (GameMain.DebugDraw) { var steering = item.GetComponent <Steering>(); steering?.DebugDrawHUD(spriteBatch, transducerCenter, displayScale, displayRadius, center); } }
public void Draw() { _spriteBatch.Begin(); _layerManager.Draw(_spriteBatch); _spriteBatch.End(); }
private void DrawSpriteBatchEntities(Camera camera, byte groupMask, float dt, float betweenFrameAlpha, Camera debugCamera) { Matrix transformMatrix = debugCamera == null?camera.GetInterpolatedTransformMatrix(betweenFrameAlpha) : debugCamera.GetInterpolatedTransformMatrix(betweenFrameAlpha); SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, null, null, null, transformMatrix); foreach (Entity entity in _spriteEntities) { SpriteComponent spriteComp = entity.GetComponent <SpriteComponent>(); if (spriteComp.Hidden || (spriteComp.RenderGroup & groupMask) == 0) { continue; } TransformComponent transformComp = entity.GetComponent <TransformComponent>(); BoundingRect boundRect = spriteComp.GetAABB(transformComp.Scale); boundRect.Min += transformComp.Position; boundRect.Max += transformComp.Position; if (!boundRect.Intersects(camera.BoundingRect) && CVars.Get <bool>("debug_show_render_culling")) { continue; } Vector2 position; float rotation; float transformScale; transformComp.Interpolate(betweenFrameAlpha, out position, out rotation, out transformScale); Vector2 scale = new Vector2(spriteComp.Bounds.X / spriteComp.Texture.Width, spriteComp.Bounds.Y / spriteComp.Texture.Height); Vector2 origin = new Vector2(spriteComp.Texture.Bounds.Width, spriteComp.Texture.Bounds.Height) * HalfHalf; AnimationComponent animationComp = entity.GetComponent <AnimationComponent>(); if (animationComp != null && animationComp.ActiveAnimationIndex > -1) { Rectangle sourceRectangle = animationComp.Animations[animationComp.ActiveAnimationIndex].TextureRegion.Bounds; scale = new Vector2(spriteComp.Bounds.X / sourceRectangle.Width, spriteComp.Bounds.Y / sourceRectangle.Height); origin = new Vector2(sourceRectangle.Width, sourceRectangle.Height) * HalfHalf; SpriteBatch.Draw(animationComp.Animations[animationComp.ActiveAnimationIndex].TextureRegion.Texture, position * FlipY, sourceRectangle, spriteComp.Color * spriteComp.Alpha, -rotation, origin, scale * transformScale, SpriteEffects.None, 0); } else { SpriteBatch.Draw(spriteComp.Texture, position * FlipY, spriteComp.Color * spriteComp.Alpha, -rotation, origin, scale * transformScale, SpriteEffects.None, 0); } } foreach (Entity entity in _fontEntities) { BitmapFontComponent fontComp = entity.GetComponent <BitmapFontComponent>(); if (fontComp.Hidden || (fontComp.RenderGroup & groupMask) == 0) { continue; } TransformComponent transformComp = entity.GetComponent <TransformComponent>(); BoundingRect boundRect = new BoundingRect(transformComp.Position.X - (fontComp.Font.MeasureString(fontComp.Content).Width *transformComp.Scale / 2), transformComp.Position.Y - (fontComp.Font.MeasureString(fontComp.Content).Height *transformComp.Scale / 2), fontComp.Font.MeasureString(fontComp.Content).Width *transformComp.Scale, fontComp.Font.MeasureString(fontComp.Content).Height *transformComp.Scale); if (!boundRect.Intersects(camera.BoundingRect) && CVars.Get <bool>("debug_show_render_culling")) { continue; } Vector2 position; float rotation; float transformScale; transformComp.Interpolate(betweenFrameAlpha, out position, out rotation, out transformScale); Vector2 origin = fontComp.Font.MeasureString(fontComp.Content) / 2; SpriteBatch.DrawString(fontComp.Font, fontComp.Content, position * FlipY, fontComp.Color, -rotation, origin, transformScale, SpriteEffects.None, 0); } SpriteBatch.End(); }
public void Draw(SpriteBatch spriteBatch) { spriteBatch.Begin(); spriteBatch.Draw(_bulletText, _bulletPos, null, Microsoft.Xna.Framework.Color.White, _bulletRot, new Vector2(_bulletText.Width, _bulletText.Height), scale, SpriteEffects.None, 0); spriteBatch.End(); }
public override void Draw(GameTime gameTime) { spriteBatch.Begin(); spriteBatch.DrawString(Art.Font, "Testing screen remove me later", new Vector2(100, 100), Color.Red); spriteBatch.End(); }
protected override void OnDraw(SpriteBatch sb) { Color c = new Color(color.R,color.G,color.B,(byte)(alpha*255)); float size = (float)(this.size+(maxSinSize*this.size*Math.Sin(sinSize*Math.PI/180))); if (chaos) { sb.End(); sb.Begin(SpriteSortMode.Immediate,bsSubtract); c = new Color(255,255,255); if (addLight) size *= 3f; sb.Draw(ptSquare,pos-Main.screenPosition,GetRectSquare(),new Color(c.R,c.G,c.B,(byte)(c.A/2f)),(float)(rot1*Math.PI/180f),GetCenterSquare(),GetScaleSquare(size),SpriteEffects.None,0f); sb.Draw(ptSquare,pos-Main.screenPosition,GetRectSquare(),c,(float)(rot2*Math.PI/180f),GetCenterSquare(),GetScaleSquare(size/2f),SpriteEffects.None,0f); if (addLight) size /= 3f; sb.End(); sb.Begin(SpriteSortMode.Immediate,BlendState.Additive); if (addLight) Lighting.addLight((int)Math.Round(pos.X/16f),(int)Math.Round(pos.Y/16f),c.R/255f*size/32f*c.A/255f/3f,c.G/255f*size/32f*c.A/255f/3f,c.B/255f*size/32f*c.A/255f/3f); } else { sb.Draw(ptSquare,pos-Main.screenPosition,GetRectSquare(),new Color(c.R,c.G,c.B,(byte)(c.A/2f)),(float)(rot1*Math.PI/180f),GetCenterSquare(),GetScaleSquare(size),SpriteEffects.None,0f); sb.Draw(ptSquare,pos-Main.screenPosition,GetRectSquare(),c,(float)(rot2*Math.PI/180f),GetCenterSquare(),GetScaleSquare(size/2f),SpriteEffects.None,0f); if (addLight) Lighting.addLight((int)Math.Round(pos.X/16f),(int)Math.Round(pos.Y/16f),c.R/255f*size/32f*c.A/255f,c.G/255f*size/32f*c.A/255f,c.B/255f*size/32f*c.A/255f); } }
public void Draw() { int namePlateDistance = Main.teamNamePlateDistance; if (namePlateDistance <= 0) { return; } this._playerOnScreenCache.Clear(); this._playerOffScreenCache.Clear(); SpriteBatch spriteBatch = Main.spriteBatch; PlayerInput.SetZoom_World(); int screenWidth = Main.screenWidth; int screenHeight = Main.screenHeight; Vector2 screenPosition1 = Main.screenPosition; PlayerInput.SetZoom_UI(); int num1 = namePlateDistance * 8; Player[] player1 = Main.player; int player2 = Main.myPlayer; byte mouseTextColor = Main.mouseTextColor; Color[] teamColor = Main.teamColor; Vector2 screenPosition2 = Main.screenPosition; Player localPlayer = player1[player2]; float num2 = (float)mouseTextColor / (float)byte.MaxValue; if (localPlayer.team == 0) { return; } DynamicSpriteFont font = FontAssets.MouseText.Value; for (int index = 0; index < (int)byte.MaxValue; ++index) { if (index != player2) { Player player3 = player1[index]; if (player3.active && !player3.dead && player3.team == localPlayer.team) { string name = player3.name; Vector2 namePlatePos; float namePlateDist; Vector2 measurement; NewMultiplayerClosePlayersOverlay.GetDistance(screenWidth, screenHeight, screenPosition1, localPlayer, font, player3, name, out namePlatePos, out namePlateDist, out measurement); Color color = new Color((int)(byte)((double)teamColor[player3.team].R * (double)num2), (int)(byte)((double)teamColor[player3.team].G * (double)num2), (int)(byte)((double)teamColor[player3.team].B * (double)num2), (int)mouseTextColor); if ((double)namePlateDist > 0.0) { float num3 = player3.Distance(localPlayer.Center); if ((double)num3 <= (double)num1) { float num4 = 20f; float num5 = -27f - (float)(((double)measurement.X - 85.0) / 2.0); string textValue = Language.GetTextValue("GameUI.PlayerDistance", (object)(int)((double)num3 / 16.0 * 2.0)); Vector2 npDistPos = font.MeasureString(textValue); npDistPos.X = namePlatePos.X - num5; npDistPos.Y = (float)((double)namePlatePos.Y + (double)measurement.Y / 2.0 - (double)npDistPos.Y / 2.0) - num4; this._playerOffScreenCache.Add(new NewMultiplayerClosePlayersOverlay.PlayerOffScreenCache(name, namePlatePos, color, npDistPos, textValue, player3, measurement)); } } else { this._playerOnScreenCache.Add(new NewMultiplayerClosePlayersOverlay.PlayerOnScreenCache(name, namePlatePos, color)); } } } } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, (BlendState)null, (SamplerState)null, (DepthStencilState)null, (RasterizerState)null, (Effect)null, Main.UIScaleMatrix); for (int index = 0; index < this._playerOnScreenCache.Count; ++index) { this._playerOnScreenCache[index].DrawPlayerName_WhenPlayerIsOnScreen(spriteBatch); } NewMultiplayerClosePlayersOverlay.PlayerOffScreenCache playerOffScreenCache; for (int index = 0; index < this._playerOffScreenCache.Count; ++index) { playerOffScreenCache = this._playerOffScreenCache[index]; playerOffScreenCache.DrawPlayerName(spriteBatch); } for (int index = 0; index < this._playerOffScreenCache.Count; ++index) { playerOffScreenCache = this._playerOffScreenCache[index]; playerOffScreenCache.DrawPlayerDistance(spriteBatch); } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, (BlendState)null, (SamplerState)null, (DepthStencilState)null, (RasterizerState)null, (Effect)null, Main.UIScaleMatrix); for (int index = 0; index < this._playerOffScreenCache.Count; ++index) { playerOffScreenCache = this._playerOffScreenCache[index]; playerOffScreenCache.DrawLifeBar(); } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, (BlendState)null, (SamplerState)null, (DepthStencilState)null, (RasterizerState)null, (Effect)null, Main.UIScaleMatrix); for (int index = 0; index < this._playerOffScreenCache.Count; ++index) { playerOffScreenCache = this._playerOffScreenCache[index]; playerOffScreenCache.DrawPlayerHead(); } }
/// <summary> /// Draw the door with a scissor test /// </summary> /// <param name="batch">Spritebatch to use</param> /// <param name="tileset">Tileset to use</param> /// <param name="id">ID of the tile</param> /// <param name="location">Location of the tile on the screen</param> /// <param name="scissor">Scissor zone</param> /// <param name="scale">Scaling factor</param> /// <param name="color">Color</param> void InternalDraw(SpriteBatch batch, TileSet tileset, int id, Point location, Rectangle scissor, Vector2 scale, Color color) { if (batch == null) return; batch.End(); Display.PushScissor(scissor); batch.Begin(); batch.DrawTile(TileSet, id, location, color, 0.0f, scale, SpriteEffects.None, 0.0f); batch.End(); Display.PopScissor(); batch.Begin(); }
public void Draw(SpriteBatch spriteBatch) { if (Observed != null) { spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); var pointer = Game.Input.GetPointerInput(0); var l = Observed.GetComponent <CharacterComponent>(); if (l != null) { var hpRect = new Rectangle(10, 10, 192, 16); spriteBatch.DrawRectangle(hpRect, Color.DarkRed, 0f); spriteBatch.DrawRectangle(new Rectangle(hpRect.X, hpRect.Y, (int)(hpRect.Width * (l.HP / (float)l.MaxHP)), hpRect.Height), Color.Red, 0.1f); if (hpRect.Contains(pointer.Position.ToPoint())) { var text = l.HP + "/" + l.MaxHP; spriteBatch.DrawString(Font, text, new Vector2(hpRect.X + hpRect.Width / 2, hpRect.Y + hpRect.Height / 2), Color.White, 0, Font.MeasureString(text) / 2, hpRect.Height / Font.MeasureString(text).Y, SpriteEffects.None, 1f); } var stamRect = new Rectangle(hpRect.X + hpRect.Width, hpRect.Y, 64, hpRect.Height); //spriteBatch.DrawRectangle(stamRect, Color.Lerp(Color.Black, Color.Yellow, 0.8f), 0f); spriteBatch.DrawRectangle(new Rectangle(stamRect.X, stamRect.Y, (int)(stamRect.Width * (l.Stamina / l.MaxStamina)), stamRect.Height), Color.Yellow, 0.1f); if (stamRect.Contains(pointer.Position.ToPoint())) { var text = l.Stamina + "/" + l.MaxStamina; var size = Font.MeasureString(text); spriteBatch.DrawRectangle(new Rectangle(stamRect.X + stamRect.Width / 2 - (int)size.X / 2, stamRect.Y + stamRect.Height / 2 - (int)size.Y / 2, (int)size.X, (int)size.Y), Color.Lerp(Color.White, Color.Transparent, 0.6f), 0f); spriteBatch.DrawString(Font, text, new Vector2(stamRect.X + stamRect.Width / 2, stamRect.Y + stamRect.Height / 2), Color.Gray, 0, size / 2, stamRect.Height / size.Y, SpriteEffects.None, 1f); } } spriteBatch.End(); Observed = null; } // Chat if (ChatLines.Count > 0) { float offset = 0; spriteBatch.Begin(); for (int i = 0; i < ChatLines.Count; ++i) { var line = ChatLines[ChatLines.Count - 1 - i]; var text = line.Text; Vector2 size = Font.MeasureString(line.Text); offset += ((int)size.X - 1) / CHAT_WIDTH + 1;; int localCounter = 1; for (int s = 0; s < text.Length; ++s) { if (Font.MeasureString(text.Substring(0, s)).X > CHAT_WIDTH) { spriteBatch.DrawString(Font, text.Substring(0, s - 1), new Vector2(8, Game.Resolution.Y - 8 - (offset - localCounter) * Font.LineSpacing), Color.Lerp(Color.Transparent, line.Color, Math.Min(1, 5f - (_currentTime - line.TimeAdded))), 0, new Vector2(0, Font.LineSpacing), 1, SpriteEffects.None, 1f); localCounter++; text = text.Substring(s - 1); s = 1; } else if (s == text.Length - 1) { spriteBatch.DrawString(Font, text, new Vector2(8, Game.Resolution.Y - 8 - (offset - localCounter) * Font.LineSpacing), Color.Lerp(Color.Transparent, line.Color, Math.Min(1, 5f - (_currentTime - line.TimeAdded))), 0, new Vector2(0, Font.LineSpacing), 1, SpriteEffects.None, 1f); break; } } if (offset >= 16) { break; } } spriteBatch.End(); } }
/// <summary> /// Draw a tiled texture. /// </summary> /// <param name="texture">Texture to draw.</param> /// <param name="position">Position.</param> /// <param name="sourceRect">Source rectangle in texture (also affect drawing size).</param> public static void DrawTiledTexture(Texture2D texture, Vector2 position, Rectangle sourceRect) { _spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null); _spriteBatch.Draw(texture, position, sourceRect, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0); _spriteBatch.End(); }
public void AddCrater(Vector2 position) { // set up rendering to the active render target GraphicsDevice.SetRenderTarget(activeRenderTarget); // clear the render target to opaque black, // and initialize the stencil buffer with all zeroes GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.Stencil, new Color(0, 0, 0, 1), 0, 0); // draw the new craters into the stencil buffer // stencilAlways makes sure we'll always write a 1 // to the stencil buffer wherever we draw the alphaTestEffect // is set up to only write a pixel if the alpha value // of the source texture is zero spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, null, stencilAlways, null, alphaTestEffect); Vector2 origin = new Vector2(craterTexture.Width * 0.5f, craterTexture.Height * 0.5f); float rotation = (float)random.NextDouble() * MathHelper.TwoPi; Rectangle r = new Rectangle((int)position.X, (int)position.Y, 50, 50); spriteBatch.Draw(craterTexture, r, null, Color.White, rotation, origin, SpriteEffects.None, 0); spriteBatch.End(); // now draw the latest planet texture, excluding the stencil // buffer, resulting in the new craters being excluded from // the drawing the first time through we don't have a latest // planet texture, so draw from the original texture spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, null, stencilKeepIfZero, null, null); if (firstTime) { spriteBatch.Draw(planetTexture, Vector2.Zero, Color.White); firstTime = false; } else { spriteBatch.Draw(textureRenderTarget, Vector2.Zero, Color.White); } spriteBatch.End(); // restore main render target - this lets us get at the render target we just drew and use it as a texture GraphicsDevice.SetRenderTarget(null); //// save image for testing //using (FileStream f = new FileStream("planet.png", FileMode.Create)) //{ // activeRenderTarget.SaveAsPng(f, 256, 256); //} // swap render targets, so the next time our source texture is the render target we just drew, // and the one we'll be drawing on is the one we just used as our source texture this time RenderTarget2D t = activeRenderTarget; activeRenderTarget = textureRenderTarget; textureRenderTarget = t; drawingTexture = textureRenderTarget; }
private void OnEditViewportDrawSprites(Device device, SpriteBatch spriteBatch, Rectangle cliprectangle) { UiEncodingWindowSource current = _currentSource; if (current == null) return; try { spriteBatch.Begin(); current.Texture.Draw(device, spriteBatch, Vector2.Zero, new Rectangle(0, 0, current.Texture.Descriptor2D.Width, current.Texture.Descriptor2D.Height), 0, cliprectangle); spriteBatch.End(); } catch (Exception ex) { Log.Error(ex); } }
/// <summary> /// This is called when the game should draw itself. /// </summary> public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { //cam.UpdateTransform(); graphics.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform); Submarine.Draw(spriteBatch, true); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform); //if (EntityPrefab.Selected != null) EntityPrefab.Selected.UpdatePlacing(spriteBatch, cam); //Entity.DrawSelecting(spriteBatch, cam); if (editingCharacter != null) { editingCharacter.Draw(spriteBatch); } spriteBatch.End(); //-------------------- HUD ----------------------------- spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); GUIpanel.Draw(spriteBatch); EditLimb(spriteBatch); int y = 0; for (int i = 0; i < textures.Count; i++) { int x = GameMain.GraphicsWidth - textures[i].Width; spriteBatch.Draw(textures[i], new Vector2(x, y), Color.White); foreach (Limb limb in editingCharacter.AnimController.Limbs) { if (limb.sprite == null || limb.sprite.FilePath != texturePaths[i]) { continue; } Rectangle rect = limb.sprite.SourceRect; rect.X += x; rect.Y += y; GUI.DrawRectangle(spriteBatch, rect, Color.Red); Vector2 limbBodyPos = new Vector2( rect.X + limb.sprite.Origin.X, rect.Y + limb.sprite.Origin.Y); DrawJoints(spriteBatch, limb, limbBodyPos); //if (limb.BodyShapeTexture == null) continue; //spriteBatch.Draw(limb.BodyShapeTexture, limbBodyPos, // null, Color.White, 0.0f, // new Vector2(limb.BodyShapeTexture.Width, limb.BodyShapeTexture.Height) / 2, // 1.0f, SpriteEffects.None, 0.0f); GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitY * 5.0f, limbBodyPos - Vector2.UnitY * 5.0f, Color.White); GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitX * 5.0f, limbBodyPos - Vector2.UnitX * 5.0f, Color.White); if (Vector2.Distance(PlayerInput.MousePosition, limbBodyPos) < 5.0f && PlayerInput.LeftButtonHeld()) { limb.sprite.Origin += PlayerInput.MouseSpeed; } } y += textures[i].Height; } GUI.Draw((float)deltaTime, spriteBatch, cam); //EntityPrefab.DrawList(spriteBatch, new Vector2(20,50)); //Entity.Edit(spriteBatch, cam); spriteBatch.End(); }
public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphics, float deltaTime) { if (GameMain.Config.EnableSplashScreen) { try { DrawSplashScreen(spriteBatch, graphics); if (currSplashScreen != null || PendingSplashScreens.Count > 0) { return; } } catch (Exception e) { DebugConsole.ThrowError("Playing splash screen video failed", e); GameMain.Config.EnableSplashScreen = false; } } var titleStyle = GUI.Style?.GetComponentStyle("TitleText"); Sprite titleSprite = null; if (!WaitForLanguageSelection && titleStyle != null && titleStyle.Sprites.ContainsKey(GUIComponent.ComponentState.None)) { titleSprite = titleStyle.Sprites[GUIComponent.ComponentState.None].First()?.Sprite; } drawn = true; graphics.SetRenderTarget(renderTarget); float backgroundScale = GameMain.GraphicsHeight / 1500.0f; float titleScale = MathHelper.SmoothStep(0.8f, 1.0f, state / 10.0f) * GameMain.GraphicsHeight / 1000.0f; state += deltaTime; if (DrawLoadingText) { BackgroundPosition = new Vector2(GameMain.GraphicsWidth * 0.3f, GameMain.GraphicsHeight * 0.45f); TitlePosition = new Vector2(GameMain.GraphicsWidth * 0.5f, GameMain.GraphicsHeight * 0.45f); } spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, samplerState: GUI.SamplerState); graphics.Clear(Color.Black); spriteBatch.Draw(backgroundTexture, BackgroundPosition, null, Color.White * Math.Min(state / 5.0f, 1.0f), 0.0f, new Vector2(backgroundTexture.Width / 2.0f, backgroundTexture.Height / 2.0f), backgroundScale * 1.5f, SpriteEffects.None, 0.2f); titleSprite?.Draw(spriteBatch, TitlePosition, Color.White * Math.Min((state - 1.0f) / 5.0f, 1.0f), scale: titleScale); spriteBatch.End(); graphics.SetRenderTarget(null); if (WaterRenderer.Instance != null) { WaterRenderer.Instance.ScrollWater(Vector2.One * 10.0f, deltaTime); WaterRenderer.Instance.RenderWater(spriteBatch, renderTarget, null); } spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, samplerState: GUI.SamplerState); titleSprite?.Draw(spriteBatch, TitlePosition, Color.White * Math.Min((state - 1.0f) / 5.0f, 1.0f), scale: titleScale); if (WaitForLanguageSelection) { DrawLanguageSelectionPrompt(spriteBatch, graphics); } else if (DrawLoadingText) { if (TextManager.Initialized) { string loadText; if (LoadState == 100.0f) { loadText = TextManager.Get("PressAnyKey"); } else { loadText = TextManager.Get("Loading"); if (LoadState != null) { loadText += " " + (int)LoadState + " %"; } } if (GUI.LargeFont != null) { GUI.LargeFont.DrawString(spriteBatch, loadText.ToUpper(), new Vector2(GameMain.GraphicsWidth / 2.0f - GUI.LargeFont.MeasureString(loadText).X / 2.0f, GameMain.GraphicsHeight * 0.7f), Color.White); } } if (GUI.Font != null && selectedTip != null) { string wrappedTip = ToolBox.WrapText(selectedTip, GameMain.GraphicsWidth * 0.5f, GUI.Font); string[] lines = wrappedTip.Split('\n'); float lineHeight = GUI.Font.MeasureString(selectedTip).Y; for (int i = 0; i < lines.Length; i++) { GUI.Font.DrawString(spriteBatch, lines[i], new Vector2((int)(GameMain.GraphicsWidth / 2.0f - GUI.Font.MeasureString(lines[i]).X / 2.0f), (int)(GameMain.GraphicsHeight * 0.78f + i * lineHeight)), Color.White); } } } spriteBatch.End(); }
public static void Draw(SpriteBatch sb) { if (!visible) return; if (Config.tileInterface != null || Config.npcInterface != null || Main.npcShop != 0 || Main.signBubble || (Main.npcChatText != null && Main.npcChatText != "")) { Toggle(); return; } sb.End(); int guiX = 80, guiY = 120, guiW = Main.screenWidth-guiX*2, guiH = Main.screenHeight-guiY*2-40; sb.Begin(SpriteSortMode.Immediate,BlendState.AlphaBlend,null,null,_rasterizerState); sb.GraphicsDevice.ScissorRectangle = new Rectangle(guiX,guiY,guiW+1,guiH); int yStart = guiY-scroll, yy = yStart; for (int i = 0; i < categories.Count; i++) categories[i].Draw(sb,guiX,ref yy,guiW-32); for (int i = 0; i < achievements.Count; i++) achievements[i].Draw(sb,guiX,ref yy,guiW-32); sb.End(); sb.Begin(SpriteSortMode.Immediate,BlendState.NonPremultiplied); int hMax = yy-yStart, scrollMax = hMax-guiH; if (scrollMax < 0) scrollMax = 0; if (scroll < 0) scroll = 0; if (scroll > scrollMax) scroll = scrollMax; float sliderY = scrollMax == 0 ? 0f : 1f*scroll/scrollMax, sliderH = scrollMax == 0 ? 1f : 1f*guiH/hMax; Rectangle rectBlack = new Rectangle(guiX+guiW-24,guiY,24,guiH); sb.Draw(whiteTex,rectBlack,new Color(1f,1f,1f,.75f)); Rectangle rectWhite = new Rectangle(guiX+guiW-22,(int)(guiY+2+(guiH-4-(guiH-4)*sliderH)*sliderY),20,(int)((guiH-4)*sliderH)); sb.Draw(whiteTex,rectWhite,new Color(0f,0f,0f,.75f)); if (scrollDragY == -1) { if (Main.mouseLeft && Main.mouseLeftRelease) { if (MouseIn(rectBlack)) { if (MouseIn(rectWhite)) scrollDragY = Main.mouseY-rectWhite.Y; else { scrollDragY = rectWhite.Height/2; scroll = (int)(1f*(Main.mouseY-scrollDragY-(guiY+2))/(guiH-4)*hMax); } } } } else { scroll = (int)(1f*(Main.mouseY-scrollDragY-(guiY+2))/(guiH-4)*hMax); if (!Main.mouseLeft) scrollDragY = -1; } if (setScroll >= 0) { scroll = setScroll; setScroll = -1; } stateOld = state; state = Microsoft.Xna.Framework.Input.Mouse.GetState(); if (stateOld.HasValue && state.HasValue) { int mouseScrollDiff = (state.Value.ScrollWheelValue-stateOld.Value.ScrollWheelValue)/120; scroll -= mouseScrollDiff*56; Main.player[Main.myPlayer].selectedItem += mouseScrollDiff; while (Main.player[Main.myPlayer].selectedItem < 0) Main.player[Main.myPlayer].selectedItem += 10; while (Main.player[Main.myPlayer].selectedItem > 9) Main.player[Main.myPlayer].selectedItem -= 10; } if (scroll < 0) scroll = 0; if (scroll > scrollMax) scroll = scrollMax; int acAchieved = 0, acTotal = 0, acHidden = 0, acLocked = 0, acPoints = 0, acPointsTotal = 0; UpdateCounters(ref acAchieved,ref acTotal,ref acHidden,ref acLocked,ref acPoints,ref acPointsTotal); ModWorld.DrawStringShadowed(sb,Main.fontMouseText,"Achieved: "+acAchieved+"/"+acTotal+(acHidden+acLocked != 0 ? " ("+(acHidden > 0 ? "+"+acHidden+" hidden" : "")+(acLocked > 0 ? (acHidden > 0 ? ", " : "")+"+"+acLocked+" locked" : "")+")" : ""),new Vector2(guiX,guiY+guiH+10),Color.White,Color.Black); ModWorld.DrawStringShadowed(sb,Main.fontMouseText,"Total points: "+acPoints+"/"+acPointsTotal,new Vector2(guiX+guiW-Main.fontMouseText.MeasureString("Total points: "+acPoints+"/"+acPointsTotal).X,guiY+guiH+10),Color.White,Color.Black); }
public override void Draw(GameTime gameTime) { if (!Visible) { return; } #if SILVERLIGHT var oldRenderTarget = GraphicsDevice.GetRenderTarget(0) as RenderTarget2D; this.GraphicsDevice.SetRenderTarget(0, _renderTarget); // Fix para GraphicsDevice.Clear que não limpa com Transparent Array.Clear(_renderTarget.GetTexture().ImageSource.Pixels, 0, _renderTarget.GetTexture().ImageSource.Pixels.Length); #else RenderTarget2D oldRenderTarget = null; if (GraphicsDevice.GetRenderTargets().Count() > 0) { oldRenderTarget = GraphicsDevice.GetRenderTargets()[0].RenderTarget as RenderTarget2D; } GraphicsDevice.SetRenderTarget(_renderTarget); #endif GraphicsDevice.Clear(BackgroundColor); #if SILVERLIGHT SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None, MatrixInternal); #else SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, MatrixInternal); #endif int size = Math.Min(_contentSize, Horizontal ? _Width : _Height); if (_scrollable != null) { _scrollable.Alpha = Alpha; _scrollable.Position = Horizontal ? new Vector2(-PosDif, 0) : new Vector2(0, -PosDif); var scrollableCullable = _scrollable as IScrollableCullable; if (Culling && scrollableCullable != null) { scrollableCullable.DrawLimited(gameTime, PosDif, size); } else { _scrollable.Draw(gameTime); } } SpriteBatch.End(); #if SILVERLIGHT GraphicsDevice.SetRenderTarget(0, oldRenderTarget); SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None, Matrix); var color = new Color(Color, MathHelper.Clamp((float)Alpha, 0, 1)); Texture2D tex = _renderTarget.GetTexture(); #else GraphicsDevice.SetRenderTarget(oldRenderTarget); SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix); var color = Color * (float)Alpha; Texture2D tex = _renderTarget; #endif if (Horizontal) { _rectDraw.Width = size; _rectDraw.Height = _Height; } else { _rectDraw.Width = _Width; _rectDraw.Height = size; } SpriteBatch.Draw(tex, Position, _rectDraw, color); if (_scroll != null) { _scroll.Alpha = Alpha; _scroll.Draw(gameTime); } SpriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// Draw the maze /// </summary> /// <param name="batch">SpriteBatch to use</param> /// <param name="location">Location to display from</param> /// <see cref="http://eob.wikispaces.com/eob.vmp"/> public void Draw(SpriteBatch batch, DungeonLocation location) { if (WallTileset == null) return; // Clear the spritebatch batch.End(); Display.PushScissor(new Rectangle(0, 0, 352, 240)); batch.Begin(); // // // ViewField pov = new ViewField(this, location); // TODO Backdrop // The background is assumed to be x-flipped when party.x & party.y & party.direction = 1. // I.e. all kind of moves and rotations from the current position will result in the background being x-flipped. bool flipbackdrop = ((location.Coordinate.X + location.Coordinate.Y + (int)location.Direction) & 1) == 0; SpriteEffects effect = flipbackdrop ? SpriteEffects.FlipHorizontally : SpriteEffects.None; batch.DrawTile(WallTileset, 0, Point.Empty, Color.White, 0.0f, effect, 0.0f); // maze block draw order // A E B D C // F J G I H // K M L // N ^ O #region row -3 DrawSquare(batch, pov, ViewFieldPosition.A, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.E, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.B, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.D, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.C, location.Direction); #endregion #region row -2 DrawSquare(batch, pov, ViewFieldPosition.F, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.J, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.G, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.I, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.H, location.Direction); #endregion #region row -1 DrawSquare(batch, pov, ViewFieldPosition.K, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.M, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.L, location.Direction); #endregion #region row 0 DrawSquare(batch, pov, ViewFieldPosition.N, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.Team, location.Direction); DrawSquare(batch, pov, ViewFieldPosition.O, location.Direction); #endregion // Clear the spritebatch batch.End(); Display.PopScissor(); batch.Begin(); }
public void Draw(SpriteBatch sp) { sp.Begin(); sp.Draw(TextureManager.allTextures[textureAndSound.Key], pos, Color.White); sp.End(); }
public override void Draw(SpriteBatch batch, GameTime time) { batch.Begin(); // Draw wood background for (var x = 0; x < 11; x++) { for (var y = 0; y < 8; y++) { var tileX = x * ChainReactGame.WabeSize; var tileY = y * ChainReactGame.WabeSize; batch.DrawTexture(_background, new Rectangle(tileX, tileY, ChainReactGame.WabeSize, ChainReactGame.WabeSize)); } } // Draw gray game field for (var x = 1; x < 7; x++) { for (var y = 1; y < 7; y++) { var tileX = x * ChainReactGame.WabeSize; var tileY = y * ChainReactGame.WabeSize; batch.DrawTexture(_gameAreaTexture, new Rectangle(tileX, tileY, ChainReactGame.WabeSize, ChainReactGame.WabeSize)); } } // Draw wabes const float cut = (ChainReactGame.WabeSize / 3); var fullWabeSizeX = ChainReactGame.WabeSize * _game.GameMap.Wabes.GetLength(0); var fullWabeSizeY = ChainReactGame.WabeSize * _game.GameMap.Wabes.GetLength(1); foreach (var wabe in _game.GameMap.Wabes) { var wabeX = (wabe.X + 1) * ChainReactGame.WabeSize; var wabeY = (wabe.Y + 1) * ChainReactGame.WabeSize; for (var x = 0; x <= 2; x++) { for (var y = 0; y <= 2; y++) { var field = wabe.ConvertVector2ToWabeField(new Vector2(x, y)); var texture = SelectTextureFromField(field); var mutltiplicatorX = cut * x; var mutltiplicatorY = cut * y; if (field.Type == WabeFieldType.Center) { var color = wabe.Owner?.Color ?? Color.White; color.A = (wabe.Owner != null) ? (byte)205 : (byte)255; batch.DrawTexture(texture, new Rectangle((wabeX) + mutltiplicatorX, (wabeY) + mutltiplicatorY, cut, cut), color); } else if (field.Type == WabeFieldType.Unused) { var color = wabe.Owner?.Color ?? Color.LightGray; color.A = 128; batch.DrawTexture(texture, new Rectangle((wabeX) + mutltiplicatorX, (wabeY) + mutltiplicatorY, cut, cut), color); } else { batch.DrawTexture(texture, new Rectangle((wabeX) + mutltiplicatorX, (wabeY) + mutltiplicatorY, cut, cut)); } var posX = mutltiplicatorX + wabeX; var posY = mutltiplicatorY + wabeY; // Draw field border if (GameSettings.Instance.FieldLines) batch.DrawTexture(_fieldBorder, new Rectangle(posX, posY, cut, cut)); } } // Draw wabe border if (GameSettings.Instance.WabeLines) batch.DrawTexture(_wabeBorder, new Rectangle(wabeX, wabeY, ChainReactGame.WabeSize, ChainReactGame.WabeSize)); } // Draw game border if (GameSettings.Instance.BorderLines) batch.DrawTexture(_gameBorder, new Rectangle(ChainReactGame.WabeSize, ChainReactGame.WabeSize, fullWabeSizeX, fullWabeSizeY)); // Draw messages if (!string.IsNullOrEmpty(_lastMessage)) { batch.DrawString(!string.IsNullOrEmpty(_game.Message) ? _game.Message : _lastMessage, _font, new Vector2(96, 680), Color.Black); } else { if (!string.IsNullOrEmpty(_game.Message)) { batch.DrawString(_game.Message, _font, new Vector2(96, 680), Color.Black); } } if (!string.IsNullOrEmpty(ResourceManager.LastSoundError)) { batch.DrawString("Failed to play a sound: " + ResourceManager.LastSoundError, _font, new Vector2(96, 720), Color.Red); } if (_game?.CurrentPlayer != null) { batch.DrawString(_game.CurrentPlayer.Name + $"'s turn ({_game.CurrentPlayer.GetColorString()}) ({_game.CurrentPlayer.Wins} Wins)", _font, new Vector2(96, 60), Color.Black); } foreach (var wabe in _game.GameMap.Wabes.Cast<Wabe>().ToList().Where(x => x.AnimationManager.IsRunning).Select(x => x.AnimationManager)) { wabe.Draw(batch, time); } if (_game.GameOver && _game.Winner != null) { var winFont = ResourceManager.GetResource<SpriteFont>("WinnerFont"); var midX = _clientSize.X / 2; var midY = _clientSize.Y / 2; var msg1 = _game.Winner.Name + " has won the game!"; var msg2 = "Press R to restart the game!"; var sizeMsg1 = winFont.MeasureString(msg1); var sizeMsg2 = winFont.MeasureString(msg2); var pos1 = new Vector2(midX - (sizeMsg1.X / 2), midY - (sizeMsg1.Y / 2) - 50); var pos2 = new Vector2(midX - (sizeMsg2.X / 2), midY - (sizeMsg2.Y / 2) + 20); batch.DrawString(msg1, winFont, pos1, Color.Crimson); batch.DrawString(msg2, winFont, pos2, Color.Crimson); } batch.End(); base.Draw(batch, time); }
public override void Draw(GameTime time) { sb.Begin(); switch (end) { case Ending.Airlock: sb.Draw(space, space.Bounds, Color.White); sb.Draw(airlockEnd, airlockEnd.Bounds, Color.White); break; case Ending.Banjo: sb.Draw(space, space.Bounds, Color.White); sb.Draw(banjoEnd, banjoEnd.Bounds, Color.White); break; case Ending.Bathroom: sb.Draw(space, space.Bounds, Color.White); sb.Draw(blackhole, blackhole.Bounds, Color.White); break; case Ending.Thrusters: sb.Draw(space, space.Bounds, Color.White); sb.Draw(thrusters, thrusters.Bounds, Color.White); break; case Ending.Help: tut = true; if (first2) { sec2 = time.TotalGameTime.TotalMilliseconds; first2 = false; } sb.Draw(space, space.Bounds, Color.White); if ((Mouse.GetState().LeftButton == ButtonState.Pressed || Mouse.GetState().RightButton == ButtonState.Pressed || Mouse.GetState().MiddleButton == ButtonState.Pressed || Keyboard.GetState().GetPressedKeys().Length > 0) && (time.TotalGameTime.TotalMilliseconds > sec2 + 250 || here)) { sb.Draw(help, tutorial.Bounds, Color.White); here = true; tut = false; } else { if (here) { sb.Draw(help, tutorial.Bounds, Color.White); } else { sb.Draw(tutorial, help.Bounds, Color.White); } } break; case Ending.Inaction: sb.Draw(space, space.Bounds, Color.White); sb.Draw(inactive, inactive.Bounds, Color.White); break; case Ending.Reverse: sb.Draw(space, space.Bounds, Color.White); sb.Draw(breaks, breaks.Bounds, Color.White); break; case Ending.Dubstep: sb.Draw(space, space.Bounds, Color.White); sb.Draw(dub, dub.Bounds, Color.White); break; } sb.End(); }
public void DrawTarget() { spriteBatch.Begin(); spriteBatch.DrawCircle(Target, 5F, 12, Color.Red, 2F); spriteBatch.End(); }
public override void Draw(SpriteBatch spriteBatch) { spriteBatch.Begin(); spriteBatch.Draw(background, new Rectangle(0, 0, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height), Color.White); spriteBatch.End(); }
private void OnPreviewViewportDraw(Device device, SpriteBatch spriteBatch, Rectangle cliprectangle) { UiEncodingWindowSource source = _currentSource; if (source == null) return; spriteBatch.Begin(SpriteSortMode.Deferred, null, _previewViewport.DxControl.RenderContainer.GraphicsDevice.SamplerStates.PointClamp, null, null, null, SharpDX.Matrix.Scaling(_scale)); float x = 0, maxX = 0; float y = source.Info.Header.LineSpacing; int squareSize = source.Info.Header.SquareSize; int lineSpacing = source.Info.Header.LineHeight + source.Info.Header.LineSpacing; foreach (char ch in _previewText) { if (ch == '\r') continue; if (ch == '\n') { x = 0; y += lineSpacing; continue; } short index; if (source.Codes.TryGetValue(ch, out index)) { int ox, oy; int h, w; if (index < 256) { byte before, width, after; source.Info.GetSizes(index, out before, out width, out after); w = width; h = source.Info.Header.LineHeight; if (before > 0x7F) x = Math.Max(x - (0xFF - before), 0); else x += before; source.Info.GetOffsets(index, out ox, out oy); source.Texture.Draw(device, spriteBatch, new Vector2(x, y), new Rectangle(ox, oy, w, h), 0, cliprectangle); if (after > 0x7F) x = Math.Max(x - (0xFF - after), 0); else x += after; } else { index -= 256; w = h = squareSize; int value = source.Info.AdditionalTable[index]; ox = (value & 0xFF) * squareSize; oy = (value >> 8) * squareSize; source.Texture.Draw(device, spriteBatch, new Vector2(x, y), new Rectangle(ox, oy, w, h), 0, cliprectangle); } x += w; maxX = Math.Max(x, maxX); } } spriteBatch.End(); double desiredWidth, desiredHeight; _previewViewport.GetDesiredSize(out desiredWidth, out desiredHeight); double newDesiredWidth = x * _scale; double newDesiredHeight = (y + lineSpacing) * _scale; if (Math.Abs(newDesiredWidth - desiredWidth) > 1 || Math.Abs(newDesiredHeight - newDesiredHeight) > 1) _previewViewport.SetDesiredSize(newDesiredWidth, newDesiredHeight); }
private void _drawAchievements(SpriteBatch spriteBatch, SpriteFont[] fonts) { int y = 0; spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); try { if (AppMain.dm_xbox_show_progress != 100) { spriteBatch.Draw(LiveFeature.a_bg, new Rectangle(10, 55, 230, (int)(170.0 * (double)((float)AppMain.dm_xbox_show_progress / 100f))), new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0.0f); spriteBatch.Draw(LiveFeature.a_bg, new Rectangle(240, 55, 230, (int)(170.0 * (double)((float)AppMain.dm_xbox_show_progress / 100f))), new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0f); } else { spriteBatch.Draw(LiveFeature.a_bg, new Rectangle(10, 55, 230, 170), new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0.0f); spriteBatch.Draw(LiveFeature.a_bg, new Rectangle(240, 55, 230, 170), new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0f); } spriteBatch.Draw(LiveFeature.titleImg, new Rectangle(15, 22, 128, 16), Color.White); if (AppMain.dm_xbox_show_progress == 100) { string text = LiveFeature.achievements_current.ToString() + AppMain.AMD_FS_PATH_CHAR + (object)LiveFeature.achievements_total + " G"; Vector2 vector2 = fonts[1].MeasureString(text); spriteBatch.DrawString(fonts[0], text, new Vector2((float)(240 - ((int)vector2.X >> 1)), 60f), Color.White); } } finally { spriteBatch.End(); } if (AppMain.dm_xbox_show_progress == 100) { LiveFeature.GAME.GraphicsDevice.ScissorRectangle = new Rectangle(15, 80, 450, 140); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, (SamplerState)null, (DepthStencilState)null, LiveFeature.GAME.scissorState); try { y = this.offsetY + 80; Rectangle destinationRectangle = new Rectangle(30, y, 35, 35); for (int index = 0; index < AppMain.achievements.Length; ++index) { bool flag = AppMain.gs_trophy_acquisition_tbl[index] == 2; spriteBatch.Draw(LiveFeature.a_images[index], destinationRectangle, flag ? Color.White : LiveFeature.transparent_achiev); if (!flag) { Color gray = Color.Gray; } else { Color white = Color.White; } string text = AppMain.achievements[index].name + " (" + (object)AppMain.achievements[index].cost + " G)"; Vector2 vector2 = fonts[1].MeasureString(text); if (y > 0 && y < 220) { spriteBatch.DrawString(fonts[1], text, new Vector2(70f, (float)y), Color.White); } y += (int)vector2.Y; if (y > 0 && y < 220 || LiveFeature.achievementTextArray[index].verticalSize == -1) { if (LiveFeature.achievementTextArray[index].text == null) { LiveFeature.achievementTextArray[index].text = LiveFeature._wrapString(AppMain.achievements[index].description, 380, fonts[0]); } LiveFeature.achievementTextArray[index].verticalSize = LiveFeature._drawWrapText(LiveFeature.achievementTextArray[index].text, 70, y, 380, Color.White, false, fonts[0], spriteBatch); } y += LiveFeature.achievementTextArray[index].verticalSize; destinationRectangle.Y = y; } if (y < 220) { this.offsetY -= y - 220; } } finally { spriteBatch.End(); LiveFeature.GAME.GraphicsDevice.ScissorRectangle = new Rectangle(0, 0, 480, 288); } } if (AppMain.dm_xbox_show_progress != 100) { return; } LiveFeature.arrow_offset += 2; if (LiveFeature.arrow_offset > 16) { LiveFeature.arrow_offset = -16; } spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); try { if (this.offsetY != 0) { Rectangle arrow2Up = LiveFeature.arrow2_Up; arrow2Up.Y -= Math.Abs(LiveFeature.arrow_offset); spriteBatch.Draw(LiveFeature.arrowImg2, arrow2Up, Color.White); } if (y <= 220) { return; } Rectangle arrow2Down = LiveFeature.arrow2_Down; arrow2Down.Y += Math.Abs(LiveFeature.arrow_offset); spriteBatch.Draw(LiveFeature.arrowImg2, arrow2Down, new Rectangle?(), Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipVertically, 0.0f); } finally { spriteBatch.End(); } }