Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PropertyUpdater
- {
- static Random rand = new Random(); //Random to set random initial value.
- public Property property; //The property
- float wiggleAmount; //The amount of wiggle.
- float value; //The value of the property.
- bool growing; //Checking if the particle is growing (by wiggling).
- public PropertyUpdater(Property property, bool randomWiggle)
- {
- this.property = property;
- value = (float)rand.NextDouble() * (property.max - property.min) + property.min;
- if (randomWiggle)
- {
- growing = rand.Next(2) == 0;
- wiggleAmount = (float)rand.NextDouble() * (growing ? 1 : -1);
- }
- else
- {
- growing = false;
- wiggleAmount = 0;
- }
- }
- //Update property
- public void Update(GameTime gameTime)
- {
- value += property.increase * (float)gameTime.ElapsedGameTime.TotalSeconds;
- if (growing)
- {
- wiggleAmount += (float)gameTime.ElapsedGameTime.TotalSeconds;
- if (wiggleAmount >= 1)
- {
- wiggleAmount = 1;
- growing = false;
- }
- }
- else
- {
- wiggleAmount -= (float)gameTime.ElapsedGameTime.TotalSeconds;
- if (wiggleAmount <= -1)
- {
- wiggleAmount = -1;
- growing = true;
- }
- }
- }
- //Return the value of the property.
- public float GetValue()
- {
- return value + wiggleAmount * property.wiggle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment