using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using MLEM.Extended.Tiled; using MLEM.Textures; using MonoGame.Extended; namespace GreatSpringGameJam { public class WaterDrop : Entity { private readonly bool growsPlants; private Vector2 velocity; private TimeSpan timeToLive; public WaterDrop(Map map, Vector2 position, Vector2 velocity) : base(map, position) { this.velocity = velocity; this.timeToLive = TimeSpan.FromSeconds(0.5F); this.growsPlants = Random.NextSingle() <= 0.25F; } public override void Update(GameTime time) { base.Update(time); this.Position += this.velocity; this.Collide(() => new RectangleF(this.Position - new Vector2(1 / 16F), new Vector2(2 / 16F)), ref this.velocity, out var onGround); if (onGround) this.velocity = Vector2.Zero; this.velocity.Y += 0.008F; this.timeToLive -= time.ElapsedGameTime; if (this.timeToLive <= TimeSpan.Zero) { if (this.growsPlants) { var (x, y) = this.Position.ToPoint(); var tile = this.Map.GetTile("Ground", x, y); if (!tile.IsBlank) { var tilesetTile = this.Map.GetTilesetTile(tile); var grown = tilesetTile.Properties.GetInt("GrownVersion"); if (grown != 0) this.Map.SetTile("Ground", x, y, grown + 1); } } this.Map.RemoveEntity(this); } } public override void Draw(GameTime time, SpriteBatch batch) { base.Draw(time, batch); var tex = StuffTexture[3, 0]; batch.Draw(tex, this.Position * this.Map.TileSize - tex.Size.ToVector2() / 2, Color.White); } } }