Fix rendering
This commit is contained in:
parent
eeae43ebe0
commit
ced2895873
6 changed files with 18 additions and 9 deletions
|
@ -10,9 +10,11 @@ public abstract class MapObject : GameObject
|
|||
public bool IsColliderOn;
|
||||
private Rectangle _sourceRectangle;
|
||||
protected override GraphicsComponent GraphicsComponent { get; } = new("tiles");
|
||||
public MapObject(Vector2 position, Rectangle sourceRectangle) : base(position)
|
||||
public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle) : base(position)
|
||||
{
|
||||
_sourceRectangle = sourceRectangle;
|
||||
Width = (int)size.X;
|
||||
Height = (int)size.Y;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace DangerousD.GameCore.GameObjects.MapObjects;
|
|||
|
||||
public class Platform : MapObject
|
||||
{
|
||||
public Platform(Vector2 position, Rectangle sourceRectangle) : base(position, sourceRectangle)
|
||||
public Platform(Vector2 position, Vector2 size, Rectangle sourceRectangle) : base(position, size, sourceRectangle)
|
||||
{
|
||||
IsColliderOn = true;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace DangerousD.GameCore.GameObjects.MapObjects;
|
|||
|
||||
public class StopTile : MapObject
|
||||
{
|
||||
public StopTile(Vector2 position, Rectangle sourceRectangle) : base(position, sourceRectangle)
|
||||
public StopTile(Vector2 position, Vector2 size, Rectangle sourceRectangle) : base(position, size, sourceRectangle)
|
||||
{
|
||||
IsColliderOn = true;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace DangerousD.GameCore.GameObjects.MapObjects;
|
|||
|
||||
public class Tile : MapObject
|
||||
{
|
||||
public Tile(Vector2 position, Rectangle sourceRectangle) : base(position, sourceRectangle)
|
||||
public Tile(Vector2 position, Vector2 size, Rectangle sourceRectangle) : base(position, size, sourceRectangle)
|
||||
{
|
||||
IsColliderOn = false;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace DangerousD.GameCore
|
|||
mapObjects = new List<MapObject>();
|
||||
entities = new List<Entity>();
|
||||
players = new List<Player>();
|
||||
mapManager = new MapManager();
|
||||
mapManager = new MapManager(1);
|
||||
physicsManager = new PhysicsManager();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,12 @@ namespace DangerousD.GameCore.Managers
|
|||
public class MapManager
|
||||
{
|
||||
private int _columns;
|
||||
private int _scale;
|
||||
|
||||
public MapManager(int scale)
|
||||
{
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
//Level
|
||||
public void LoadLevel(string level)
|
||||
|
@ -46,18 +52,19 @@ namespace DangerousD.GameCore.Managers
|
|||
|
||||
Vector2 pos = new((chunkX + i % chunkW) * tileSize.X,
|
||||
(chunkY + i / chunkW) * tileSize.Y);
|
||||
Rectangle sourceRect = new(new Point(tiles[i] % _columns, tiles[i] / _columns), tileSize.ToPoint());
|
||||
pos *= _scale;
|
||||
Rectangle sourceRect = new(new Point(tiles[i] % _columns, tiles[i] / _columns ) * tileSize.ToPoint(), tileSize.ToPoint());
|
||||
|
||||
switch (tileType)
|
||||
{
|
||||
case "collidable":
|
||||
new StopTile(pos, sourceRect);
|
||||
new StopTile(pos, tileSize * _scale, sourceRect);
|
||||
break;
|
||||
case "platform":
|
||||
new Platform(pos, sourceRect);
|
||||
new Platform(pos, tileSize * _scale, sourceRect);
|
||||
break;
|
||||
case "non_collidable":
|
||||
new Tile(pos, sourceRect);
|
||||
new Tile(pos, tileSize * _scale, sourceRect);
|
||||
break;
|
||||
}}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue