/// <summary> /// Allows the game component to draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.DepthStencilState = fStateDepth; GraphicsDevice.BlendState = fStateBlend; GraphicsDevice.RasterizerState = fStateRasterizer; GraphicsDevice.SamplerStates[0] = fStateSampler; Matrix world = fCamera.Camera.WorldMatrix; Matrix view = fCamera.Camera.ViewMatrix; Matrix projection = fCamera.Camera.ProjectionMatrix; if (!fHalted) { double seconds = gameTime.TotalGameTime.TotalSeconds; float angle = (float)seconds / 3; world = Matrix.CreateRotationY(angle); } foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes) { pass.Apply(); fLines.Render(); } foreach (ModelMesh mesh in fModel1.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.View = view; effect.Projection = projection; effect.World = world; } mesh.Draw(); } foreach (ModelMesh mesh in fModel2.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.View = view; effect.Projection = projection; effect.World = world; } mesh.Draw(); } fBasicEffect.View = view; fBasicEffect.Projection = projection; fBasicEffect.World = world; foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes) { pass.Apply(); fLines.Render(); } base.Draw(gameTime); }
public void DrawExplosion(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { if (explosionTime > 0.3f) { CurrentState = State.DEAD; } float circleRadius; float f = 1f - explosionTime * 3.33f; float k; if (explosionTime < 0.1f) { circleRadius = (sprite.Width / 2f) * 1.3f - explosionTime * explosionTime * 50f + 5 + 50 * explosionTime; k = 1; } else { circleRadius = (sprite.Width / 2f) * 1.3f - explosionTime * explosionTime * 200f; k = f + 0.3f; } // 0.1 = 5 float blastRadius = (sprite.Width / 2f) * 1.3f + 50f * (float)(Math.Sqrt(explosionTime * 4f)); Color blastColor = new Color(Constans.MAIN_EXPLOSION_COLOR.R / 255f * f * 1.5f, Constans.MAIN_EXPLOSION_COLOR.G / 255f * f * 1.5f, Constans.MAIN_EXPLOSION_COLOR.B / 255f * f * 1.5f, f * 1.5f); line.ClearVectors(); line.CreateCircle(blastRadius, 20); Vector2 corner = CalculateScreenPosition(); float blastX = corner.X + sprite.Width / 2f; float blastY = corner.Y + sprite.Height / 2f; line.Colour = blastColor; line.Render(spriteBatch, new Vector2((int)blastX, (int)blastY)); if (circleRadius >= 0) { corner.X += sprite.Width / 2f; corner.Y += sprite.Height / 2f; corner.X -= circleRadius; corner.Y -= circleRadius; Color color = new Color(Constans.MAIN_EXPLOSION_COLOR.R / 255f * k, Constans.MAIN_EXPLOSION_COLOR.G * k / 255f, Constans.MAIN_EXPLOSION_COLOR.B * k / 255f, k); spriteBatch.Draw(circle, new Rectangle((int)corner.X, (int)corner.Y, (int)circleRadius * 2, (int)circleRadius * 2), color); } }
/// <summary> /// Allows the game component to draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { if (fAngleChanged) { fAngleChanged = false; fWorldMatrix = Matrix.CreateRotationZ(fAngle) * Matrix.CreateTranslation( GraphicsDevice.Viewport.Width / 2f, GraphicsDevice.Viewport.Height / 2f, 0); } fBasicEffect.World = fWorldMatrix; fLines.UseVertexBuffer = fUseVertexBuffer; foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes) { pass.Apply(); fLines.Render(); } base.Draw(gameTime); }
public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { if (explosionTime < 0) { return; } if (shouldPlaySound) { SoundPlayer.Instance.PlaySound("explosion1"); shouldPlaySound = false; } if (explosionTime > 0.3f || CurrentState.Equals(State.EXPLODED)) { CurrentState = State.EXPLODED; return; } float circleRadius; float f = 1f - explosionTime * 3.33f; float k; if (explosionTime < 0.1f) { circleRadius = (spriteWidth / 2f) * 1.3f - explosionTime * explosionTime * 50f + 5 + 50 * explosionTime; k = 1; } else { circleRadius = (spriteWidth / 2f) * 1.3f - explosionTime * explosionTime * 200f; k = f + 0.3f; } // 0.1 = 5 float blastRadius = (spriteWidth / 2f) * 1.3f + 50f * (float)(Math.Sqrt(explosionTime * 4f)); Color blastColor = new Color(Constans.MAIN_PLAYER_EXPLOSION_COLOR.R / 255f * f * 1.5f, Constans.MAIN_PLAYER_EXPLOSION_COLOR.G / 255f * f * 1.5f, Constans.MAIN_PLAYER_EXPLOSION_COLOR.B / 255f * f * 1.5f, f * 1.5f); line.ClearVectors(); line.CreateCircle(blastRadius, 100); Vector2 corner = ScreenUtils.TranslateToScreenCoordinates(position); float blastX = corner.X /*- spriteWidth / 2f*/; float blastY = corner.Y /* - spriteWidth / 2f*/; line.Colour = blastColor; line.Render(spriteBatch, new Vector2((int)blastX, (int)blastY)); if (circleRadius >= 0) { corner.X -= circleRadius; corner.Y -= circleRadius; Color color = new Color(Constans.MAIN_PLAYER_EXPLOSION_COLOR.R / 255f * k, Constans.MAIN_PLAYER_EXPLOSION_COLOR.G / 255f * k, Constans.MAIN_PLAYER_EXPLOSION_COLOR.B / 255f * k, k); spriteBatch.Draw(circle, new Rectangle((int)corner.X, (int)corner.Y, (int)circleRadius * 2, (int)circleRadius * 2), color); } }