DangerousD/DangerousD/GameCore/GameObjects/GameObject.cs
2023-08-18 00:31:46 +03:00

68 lines
No EOL
1.9 KiB
C#

using DangerousD.GameCore.Graphics;
using System;
using System.Collections.Generic;
using System.Text;
using DangerousD.GameCore.GUI;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using DangerousD.GameCore.GameObjects.LivingEntities;
namespace DangerousD.GameCore
{
public abstract class GameObject : IDrawableObject
{
protected Vector2 _pos;
public Vector2 Pos => _pos;
public int Width { get; set; }
public int Height { get; set; }
public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height);
public Vector2 velocity;
public Vector2 acceleration;
protected abstract GraphicsComponent GraphicsComponent { get; }
public GameObject(Vector2 pos)
{
Initialize();
_pos = pos;
Width = 500;
Height = 101;
//Animator = new GraphicsComponent(new() { "playerIdle" });
LoadContent();
AppManager.Instance.GameManager.Register(this);
}
public virtual void OnCollision(GameObject gameObject)
{
}
protected int obsticles = 0;
public virtual void OnCollisionWithObsticle(GameObject gameObject)
{
obsticles++;//SD
}
public virtual void Initialize()
{
}
public void LoadContent()
{
GraphicsComponent.LoadContent();
}
public virtual void Update(GameTime gameTime)
{
obsticles = 0;
GraphicsComponent.Update();
}
public static Texture2D debugTexture;
public virtual void Draw(SpriteBatch spriteBatch)
{
GraphicsComponent.DrawAnimation(Rectangle, spriteBatch);
//debug
// spriteBatch.Draw(debugTexture, Rectangle, Color.White);
}
}
}