Fixed graphics partially

This commit is contained in:
SergoDobro 2024-08-18 13:02:33 +03:00
parent 600411cd55
commit b9c015455d
4 changed files with 12 additions and 24 deletions

View file

@ -16,7 +16,8 @@ namespace ZoFo.GameCore.GameObjects.MapObjects
{ {
public virtual bool IsColliderOn { get; protected set; } = true;//Who added that? public virtual bool IsColliderOn { get; protected set; } = true;//Who added that?
public Rectangle sourceRectangle; public Rectangle sourceRectangle;
public override StaticGraphicsComponent graphicsComponent { get; } = new StaticGraphicsComponent(); public override GraphicsComponent graphicsComponent { get; }
= new StaticGraphicsComponent();
/// <summary> /// <summary>
/// Создается простой объект на карте - no animations, только где, насколько крупно рисовать, по какой сорс ректанглу рисовать и из какой текстуры /// Создается простой объект на карте - no animations, только где, насколько крупно рисовать, по какой сорс ректанглу рисовать и из какой текстуры
@ -27,10 +28,11 @@ namespace ZoFo.GameCore.GameObjects.MapObjects
/// <param name="textureName"></param> /// <param name="textureName"></param>
public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName) : base(position) public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName) : base(position)
{ {
graphicsComponent._textureName = textureName; (graphicsComponent as StaticGraphicsComponent)._textureName = textureName;
graphicsComponent.BuildComponent(textureName); (graphicsComponent as StaticGraphicsComponent).BuildComponent(textureName);
graphicsComponent.ObjectDrawRectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y); (graphicsComponent as StaticGraphicsComponent).ObjectDrawRectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
graphicsComponent.LoadContent(); (graphicsComponent as StaticGraphicsComponent).LoadContent();
this.sourceRectangle = sourceRectangle;
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)

View file

@ -16,8 +16,7 @@ namespace ZoFo.GameCore.Graphics
public List<AnimationContainer> animations; public List<AnimationContainer> animations;
private List<Texture2D> textures; private List<Texture2D> textures;
private List<string> texturesNames; private List<string> texturesNames;
private AnimationContainer currentAnimation; private AnimationContainer currentAnimation;
static public int scaling = 6;
static public int Camera_XW=800; static public int Camera_XW=800;
static public int Camera_YH = 400; static public int Camera_YH = 400;
static public Vector2 CameraSize = new Vector2(1800, 960); static public Vector2 CameraSize = new Vector2(1800, 960);
@ -215,15 +214,7 @@ namespace ZoFo.GameCore.Graphics
destinationRectangle = Scaling(destinationRectangle); destinationRectangle = Scaling(destinationRectangle);
_spriteBatch.Draw(texture, _spriteBatch.Draw(texture,
destinationRectangle, sourceRectangle, Color.White); destinationRectangle, sourceRectangle, Color.White);
} }
private Rectangle Scaling(Rectangle destinationRectangle)
{
destinationRectangle.X *= scaling;
destinationRectangle.Y *= scaling;
destinationRectangle.Width *= scaling;
destinationRectangle.Height *= scaling;
return destinationRectangle;
}
private void buildSourceRectangle() private void buildSourceRectangle()
{ {
sourceRectangle = new Rectangle(); sourceRectangle = new Rectangle();

View file

@ -1,6 +0,0 @@
namespace ZoFo.GameCore.Graphics;
public class AnimationComponent
{
}

View file

@ -20,6 +20,7 @@ using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
using ZoFo.GameCore.GameObjects.MapObjects; using ZoFo.GameCore.GameObjects.MapObjects;
using ZoFo.GameCore.GameObjects.MapObjects.StopObjects; using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
using ZoFo.GameCore.Graphics;
namespace ZoFo.GameCore namespace ZoFo.GameCore
{ {
@ -174,7 +175,7 @@ namespace ZoFo.GameCore
sourceRectangle = (gameObject as StopObject).sourceRectangle, sourceRectangle = (gameObject as StopObject).sourceRectangle,
Size = (gameObject as StopObject).graphicsComponent.ObjectDrawRectangle.Size, Size = (gameObject as StopObject).graphicsComponent.ObjectDrawRectangle.Size,
collisions = (gameObject as StopObject).collisionComponents.Select(x=>x.stopRectangle).ToArray(), collisions = (gameObject as StopObject).collisionComponents.Select(x=>x.stopRectangle).ToArray(),
tileSetName = (gameObject as StopObject).graphicsComponent.mainTextureName tileSetName = ((gameObject as StopObject).graphicsComponent as StaticGraphicsComponent)._textureName
});//TODO });//TODO
foreach (var item in (gameObject as StopObject).collisionComponents) foreach (var item in (gameObject as StopObject).collisionComponents)
{ {
@ -190,7 +191,7 @@ namespace ZoFo.GameCore
Position = (gameObject as MapObject).position, Position = (gameObject as MapObject).position,
sourceRectangle = (gameObject as MapObject).sourceRectangle, sourceRectangle = (gameObject as MapObject).sourceRectangle,
Size = (gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size, Size = (gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size,
tileSetName = (gameObject as MapObject).graphicsComponent.mainTextureName tileSetName = ((gameObject as MapObject).graphicsComponent as StaticGraphicsComponent)._textureName
});//TODO });//TODO
return; return;
} }