TouchyTickets/ThemeParkClicker/ParkMap.cs

58 lines
2 KiB
C#
Raw Normal View History

2020-05-31 17:24:10 +02:00
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Misc;
using MLEM.Startup;
using MLEM.Textures;
using ThemeParkClicker.Attractions;
namespace ThemeParkClicker {
public class ParkMap {
public readonly int Width;
public readonly int Height;
private readonly Attraction[,] grid;
private readonly Dictionary<Point, Attraction> attractions = new Dictionary<Point, Attraction>();
public ParkMap(int width, int height) {
this.Width = width;
this.Height = height;
this.grid = new Attraction[width, height];
}
public void Update(GameTime time) {
foreach (var attraction in this.attractions.Values)
attraction.GainTickets(time);
}
public void Draw(GameTime time, SpriteBatch batch, Vector2 position, float scale) {
var tileSize = Attraction.TileSize * scale;
// draw ground
batch.Draw(batch.GetBlankTexture(), new RectangleF(position, new Vector2(this.Width, this.Height) * tileSize), ColorExtensions.FromHex(0xff53a662));
// draw attractions
foreach (var kv in this.attractions)
batch.Draw(kv.Value.TextureRegion, position + kv.Key.ToVector2() * tileSize, Color.White);
}
public bool CanPlace(Point position, Attraction attraction) {
for (var x = 0; x < attraction.Width; x++) {
for (var y = 0; y < attraction.Height; y++) {
if (this.grid[position.X + x, position.Y + y] != null)
return false;
}
}
return true;
}
public void Place(Point position, Attraction attraction) {
for (var x = 0; x < attraction.Width; x++) {
for (var y = 0; y < attraction.Height; y++)
this.grid[position.X + x, position.Y + y] = attraction;
}
this.attractions[position] = attraction;
}
}
}