/// <summary> /// draws the bullet or its explosion animation /// </summary> /// <param name="spriteBatch">The sprite batch.</param> public virtual void Draw(SpriteBatch spriteBatch) { //if bullet is not dead draw it, if it is draw its explosion if (!IsDead) { //draw bullet box = new Rectangle((int)Position.X, (int)Position.Y, (int)(Img.Width * scaleFactor), (int)(Img.Height * scaleFactor)); spriteBatch.Draw(Img, box, null, Color.White, -MathHelper.ToRadians(rotation) + MathHelper.PiOver2, new Vector2((float)(Img.Width / 2.0), (float)(Img.Height / 2.0)), SpriteEffects.None, 1f); } else { //draw the explosion animation ExAnim.Draw(spriteBatch, Color.White, SpriteEffects.None); } }
/// <summary> /// Updates the core state of the bullet. /// </summary> /// <returns><c>true</c> if the bullet should be removed from the game scene, <c>false</c> otherwise.</returns> public virtual bool Update() { //move bullet if it is not dead update the explosion animation otherwise if (!IsDead) { //calculate the bullet x and y move amount and add them onto the bullet position Position += new Vector2((float)Math.Cos(MathHelper.ToRadians(rotation)), (float)-Math.Sin(MathHelper.ToRadians(rotation))) * DEF_VELOCITY; } else { //update the explosion animation ExAnim.Update(Tools.GameTime); } //return true if the bullet is dead and done exploding or has left the screen, false otherwise return(IsDead && !ExAnim.isAnimating || !Tools.IsBetween(Tools.ArenaBounds.Left, Position.X, Tools.ArenaBounds.Right + Img.Width) || !Tools.IsBetween(Tools.ArenaBounds.Bottom - Img.Height, Position.Y, Tools.ArenaBounds.Top)); }