47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using MLEM.Cameras;
|
|
using MLEM.Extended.Extensions;
|
|
using MLEM.Extended.Tiled;
|
|
using MLEM.Misc;
|
|
using MLEM.Startup;
|
|
using MonoGame.Extended.Tiled;
|
|
|
|
namespace GreatSpringGameJam {
|
|
public class Map {
|
|
|
|
public Point SizeInPixels => new(this.map.WidthInPixels, this.map.HeightInPixels);
|
|
public Vector2 TileSize => this.map.GetTileSize();
|
|
public readonly TiledMapCollisions Collisions;
|
|
|
|
private readonly TiledMap map;
|
|
private readonly IndividualTiledMapRenderer renderer;
|
|
private readonly List<Entity> entities = new();
|
|
|
|
public Map(string name) {
|
|
this.map = MlemGame.LoadContent<TiledMap>($"Maps/{name}");
|
|
this.renderer = new IndividualTiledMapRenderer(this.map);
|
|
this.Collisions = new TiledMapCollisions(this.map);
|
|
}
|
|
|
|
public void AddEntity(Entity entity) {
|
|
this.entities.Add(entity);
|
|
}
|
|
|
|
public void Update(GameTime time) {
|
|
this.renderer.UpdateAnimations(time);
|
|
foreach (var entity in this.entities)
|
|
entity.Update(time);
|
|
}
|
|
|
|
public void Draw(GameTime time, SpriteBatch batch, Camera camera) {
|
|
batch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: camera.ViewMatrix);
|
|
this.renderer.Draw(batch, camera.GetVisibleRectangle().ToExtended());
|
|
foreach (var entity in this.entities)
|
|
entity.Draw(time, batch);
|
|
batch.End();
|
|
}
|
|
|
|
}
|
|
} |