using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework; using Util; namespace FaceOff { class ProgressBar { double myProgress; double newProgress; double maxProgress; Vector2 myPosition; int myLength; Vector2 mScale = new Vector2(1.0f, 1.0f); Vector2 mBarScale = new Vector2(1.0f, 1.0f); double tickrate; double tickamount = 0; double numticks = 0; double numupdate = 0; SoundManager sound; private bool doneUpdating = false; private bool startUpdating = true; bool mVisible = true; ContentManager content; private Texture2D BorderEdge; private Texture2D BorderCenter; private Texture2D Bar; public ProgressBar(ContentManager con, Vector2 newPosition, int StartingProgress, int length, SoundManager s) { sound = s; myProgress = 0; myPosition = newPosition; myProgress = StartingProgress; newProgress = StartingProgress; myLength = length; mScale = new Vector2(myLength / 15, 1.0f); content = con; BorderEdge = content.Load(@"Texture\BorderEdge"); BorderCenter = content.Load(@"Texture\BorderCenter"); Bar = content.Load(@"Texture\Bar"); tickrate = (1.0 / 60.0); maxProgress = 100.0; } public void calcProgress(int numWrong) { double change = 0; switch (numWrong) { case 0: change = GameConfig.NoneWrong; break; case 1: case 2: change = GameConfig.TwoWrong; break; default: change = GameConfig.ThreeWrong; break; } ChangeProgress(change, 2.5); } private void ChangeProgress(double change, double duration) { newProgress += change; if (newProgress > maxProgress) newProgress = maxProgress; numticks += Math.Floor( duration / tickrate ); tickamount = (float)(newProgress - myProgress) / (float)numticks; doneUpdating = false; startUpdating = false; //duration will be how long it takes for the bar to fill the given amount } public double Progress { get { return myProgress; } set { myProgress = value; } } public bool DoneUpdating { get { return doneUpdating; } set { doneUpdating = value; } } public bool StartUpdating { get { return startUpdating; } set { startUpdating = value; } } public void Update() { if (numupdate >= numticks) { numupdate = 0; numticks = 0; myProgress = newProgress; doneUpdating = true; } else { myProgress += tickamount; numupdate++; //SoundManager.SoundManager.PlayEffect("progress"); sound.PlaySound("progress"); } mBarScale = new Vector2((float)(mScale.X * (myProgress / 100)), (float)mBarScale.Y); } public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { if (mVisible && Bar != null) { spriteBatch.Draw(Bar, myPosition, null, new Color(255, 255, 255, 255), 0.0f, Vector2.Zero, mBarScale, SpriteEffects.None, 1.0f); spriteBatch.Draw(BorderCenter, myPosition, null, new Color(255, 0, 255, 255), 0.0f, Vector2.Zero, mScale, SpriteEffects.None, 1.0f); spriteBatch.Draw(BorderEdge, new Vector2(myPosition.X - 5, myPosition.Y), null, new Color(255, 0, 255, 255), 0.0f, Vector2.Zero, 1, SpriteEffects.None, 1.0f); //draws the right edge by flipping the left edge spriteBatch.Draw(BorderEdge, new Vector2(myPosition.X + myLength + 5, myPosition.Y + 15), null, new Color(255, 0, 255, 255), 0.0f, Vector2.Zero, -1, SpriteEffects.None, 1.0f); } } } }