TouchyTickets/ThemeParkClicker/Attractions/Attraction.cs

45 lines
1.4 KiB
C#
Raw Normal View History

2020-06-01 14:45:20 +02:00
using System;
using System.Collections.Generic;
2020-06-01 14:45:20 +02:00
using System.Runtime.Serialization;
2020-05-31 17:24:10 +02:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
2020-05-31 17:24:10 +02:00
using MLEM.Extensions;
using MLEM.Startup;
using MLEM.Textures;
namespace ThemeParkClicker.Attractions {
2020-06-01 14:45:20 +02:00
[DataContract]
public class Attraction {
public static readonly UniformTextureAtlas Texture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Attractions"), 16, 16);
2020-05-31 17:24:10 +02:00
public static readonly Vector2 TileSize = new Vector2(Texture.RegionWidth, Texture.RegionHeight);
2020-06-01 14:45:20 +02:00
[DataMember]
public readonly AttractionType Type;
[DataMember]
2020-05-31 17:24:10 +02:00
private float ticketPercentage;
2020-06-01 14:45:20 +02:00
public Attraction(AttractionType type) {
this.Type = type;
}
2020-06-01 01:21:54 +02:00
public IEnumerable<Point> GetCoveredTiles() {
2020-06-01 14:45:20 +02:00
for (var x = 0; x < this.Type.Width; x++) {
for (var y = 0; y < this.Type.Height; y++) {
if (this.Type.Area[y, x])
2020-06-01 01:21:54 +02:00
yield return new Point(x, y);
}
}
}
2020-06-01 14:45:20 +02:00
public void Update(GameTime time, TimeSpan passed) {
this.ticketPercentage += this.Type.GenerationPerSecond * (float) passed.TotalSeconds;
2020-05-31 17:24:10 +02:00
var amount = this.ticketPercentage.Floor();
if (amount > 0) {
GameImpl.Instance.Tickets += amount;
this.ticketPercentage -= amount;
}
}
}
}