42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using MLEM.Extensions;
|
|
using MLEM.Startup;
|
|
using MLEM.Textures;
|
|
using RectangleF = MonoGame.Extended.RectangleF;
|
|
|
|
namespace GreatSpringGameJam {
|
|
public class Entity {
|
|
|
|
public static readonly UniformTextureAtlas StuffTexture = new(MlemGame.LoadContent<Texture2D>("Textures/Stuff"), 8, 8);
|
|
protected static readonly Random Random = new();
|
|
|
|
public readonly Map Map;
|
|
public Vector2 Position;
|
|
|
|
public Entity(Map map, Vector2 position) {
|
|
this.Map = map;
|
|
this.Position = position;
|
|
}
|
|
|
|
public virtual void Update(GameTime time) {
|
|
}
|
|
|
|
public virtual void Draw(GameTime time, SpriteBatch batch) {
|
|
}
|
|
|
|
protected void Collide(Func<RectangleF> getArea, ref Vector2 velocity, out bool onGround) {
|
|
onGround = false;
|
|
foreach (var (normal, penetration) in this.Map.Collisions.GetPenetrations(getArea)) {
|
|
if (penetration.Equals(0, 0.015F))
|
|
continue;
|
|
this.Position -= normal * penetration;
|
|
velocity *= new Vector2(Math.Abs(normal.Y), Math.Abs(normal.X));
|
|
if (normal.Y > 0)
|
|
onGround = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |