Fix Entity spawn position
This commit is contained in:
parent
0614b8348a
commit
2de1a409fb
4 changed files with 14 additions and 6 deletions
|
@ -9,6 +9,7 @@ namespace DangerousD.GameCore.GameObjects
|
||||||
public abstract class Entity : GameObject
|
public abstract class Entity : GameObject
|
||||||
{
|
{
|
||||||
public Entity(Vector2 position) : base(position) {}
|
public Entity(Vector2 position) : base(position) {}
|
||||||
|
public virtual void SetPosition(Vector2 position) { _pos = position; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,11 @@ public abstract class LivingEntity : Entity
|
||||||
{
|
{
|
||||||
acceleration = new Vector2(0, 30);
|
acceleration = new Vector2(0, 30);
|
||||||
}
|
}
|
||||||
public void SetPosition(Vector2 position) { targetPosition = position; _pos = position; } //TODO befrend targetpos and physics engine
|
public override void SetPosition(Vector2 position)
|
||||||
|
{
|
||||||
|
targetPosition = position; _pos = position;
|
||||||
|
|
||||||
|
} //TODO befrend targetpos and physics engine
|
||||||
|
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace DangerousD.GameCore
|
||||||
mapObjects = new List<MapObject>();
|
mapObjects = new List<MapObject>();
|
||||||
entities = new List<Entity>();
|
entities = new List<Entity>();
|
||||||
players = new List<Player>();
|
players = new List<Player>();
|
||||||
mapManager = new MapManager(1);
|
mapManager = new MapManager(2);
|
||||||
physicsManager = new PhysicsManager();
|
physicsManager = new PhysicsManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,8 +63,8 @@ namespace DangerousD.GameCore.Managers
|
||||||
{
|
{
|
||||||
if (tiles[i] != 0)
|
if (tiles[i] != 0)
|
||||||
{
|
{
|
||||||
Vector2 pos = new((chunkX+ i % chunkW) * tileSize.X * _scale + offsetX,
|
Vector2 pos = new(((chunkX+ i % chunkW) * tileSize.X + offsetX) * _scale,
|
||||||
(chunkY + i / chunkW) * tileSize.Y * _scale + offsetY);
|
((chunkY + i / chunkW) * tileSize.Y + offsetY) * _scale);
|
||||||
//pos *= _scale;
|
//pos *= _scale;
|
||||||
Rectangle sourceRect = new(new Point((tiles[i] -1) % _columns, (tiles[i] -1) / _columns) * tileSize.ToPoint(), tileSize.ToPoint());
|
Rectangle sourceRect = new(new Point((tiles[i] -1) % _columns, (tiles[i] -1) / _columns) * tileSize.ToPoint(), tileSize.ToPoint());
|
||||||
Type type = Type.GetType($"DangerousD.GameCore.GameObjects.MapObjects.{tileType}");
|
Type type = Type.GetType($"DangerousD.GameCore.GameObjects.MapObjects.{tileType}");
|
||||||
|
@ -100,10 +100,13 @@ namespace DangerousD.GameCore.Managers
|
||||||
private void InstantiateEntities(XmlNode group)
|
private void InstantiateEntities(XmlNode group)
|
||||||
{
|
{
|
||||||
string entityType = group.Attributes["class"].Value;
|
string entityType = group.Attributes["class"].Value;
|
||||||
|
float offsetX = group.Attributes["offsetx"] is not null ? float.Parse(group.Attributes["offsetx"].Value) : 0;
|
||||||
|
float offsetY = group.Attributes["offsety"] is not null ? float.Parse(group.Attributes["offsety"].Value) : 0;
|
||||||
foreach (XmlNode entity in group.ChildNodes)
|
foreach (XmlNode entity in group.ChildNodes)
|
||||||
{
|
{
|
||||||
Type type = Type.GetType($"DangerousD.GameCore.GameObjects.{entityType}");
|
Type type = Type.GetType($"DangerousD.GameCore.GameObjects.{entityType}");
|
||||||
Activator.CreateInstance(type, new Vector2(float.Parse(entity.Attributes["x"].Value), float.Parse(entity.Attributes["y"].Value)));
|
Entity inst = (Entity)Activator.CreateInstance(type, new Vector2(float.Parse(entity.Attributes["x"].Value) + offsetX, float.Parse(entity.Attributes["y"].Value) + offsetY) * _scale);
|
||||||
|
inst.SetPosition(new Vector2(inst.Pos.X, inst.Pos.Y - inst.Height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue