TouchyTickets/TouchyTickets/RainingTicket.cs

35 lines
No EOL
1.2 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Misc;
using MLEM.Textures;
namespace TouchyTickets {
public class RainingTicket {
private static readonly Random Random = new Random();
private readonly Vector2 speed;
private readonly float rotationSpeed;
private float rotation;
private Vector2 position;
public RainingTicket() {
this.position = new Vector2((float) Random.NextDouble(), -0.15F);
this.speed = new Vector2((float) Random.NextDouble() * 0.0005F - 0.00025F, 0.005F + (float) Random.NextDouble() * 0.01F);
this.rotationSpeed = MathHelper.ToRadians((float) Random.NextDouble() * 5);
}
public bool Update() {
this.rotation += this.rotationSpeed;
this.position += this.speed;
return this.position.Y >= 1.15F;
}
public void Draw(SpriteBatch batch, Vector2 viewport, float scale, Color color) {
var tex = Assets.UiTexture[2, 0];
batch.Draw(tex, this.position * viewport, color, this.rotation, tex.Size.ToVector2() / 2, scale, SpriteEffects.None, 0);
}
}
}