GameObject structure
This commit is contained in:
parent
67a450527c
commit
d0bf698c5d
9 changed files with 40 additions and 72 deletions
|
@ -6,7 +6,7 @@ using MonogameLibrary.UI.Base;
|
|||
|
||||
namespace DangerousD.GameCore.GUI;
|
||||
|
||||
public abstract class AbstractGui : IGameObject
|
||||
public abstract class AbstractGui : IDrawableObject
|
||||
{
|
||||
protected UIManager Manager = new();
|
||||
protected List<DrawableUIElement> Elements = new();
|
||||
|
|
|
@ -11,19 +11,18 @@ namespace DangerousD.GameCore.GameObjects
|
|||
private Vector2 targetPosition;
|
||||
public float speed;
|
||||
|
||||
public Entity(Texture2D texture, Vector2 position) : base(texture, position) {}
|
||||
public Entity(Texture2D texture, Vector2 position, GraphicsComponent animator) : base(texture, position, animator) {}
|
||||
public Entity(Vector2 position) : base(position) {}
|
||||
|
||||
|
||||
public void SetPosition(Vector2 position) { targetPosition = position; }
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
if (Vector2.Distance(Position, targetPosition) > 0.5f)
|
||||
if (Vector2.Distance(Pos, targetPosition) > 0.5f)
|
||||
{
|
||||
Vector2 dir = targetPosition - Position;
|
||||
Vector2 dir = targetPosition - Pos;
|
||||
dir.Normalize();
|
||||
Position += dir * speed;
|
||||
Pos += dir * speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,29 +2,27 @@
|
|||
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;
|
||||
|
||||
namespace DangerousD.GameCore
|
||||
{
|
||||
public abstract class GameObject
|
||||
public abstract class GameObject : IDrawableObject
|
||||
{
|
||||
protected Texture2D Texture;
|
||||
public Vector2 Position;
|
||||
public Vector2 Pos { get; protected set; }
|
||||
public int Width { get; protected set; }
|
||||
public int Height { get; protected set; }
|
||||
public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height);
|
||||
protected GraphicsComponent Animator;
|
||||
|
||||
public GameObject(Texture2D texture, Vector2 position)
|
||||
public GameObject(Vector2 pos)
|
||||
{
|
||||
Texture = texture;
|
||||
Position = position;
|
||||
GameManager.Register(this);
|
||||
}
|
||||
|
||||
public GameObject(Texture2D texture, Vector2 position, GraphicsComponent animator)
|
||||
{
|
||||
Texture = texture;
|
||||
Position = position;
|
||||
Animator = animator;
|
||||
Pos = pos;
|
||||
Width = 500;
|
||||
Height = 100;
|
||||
Animator = new GraphicsComponent(new() { "playerIdle" });
|
||||
GameManager.Register(this);
|
||||
}
|
||||
|
||||
|
@ -32,14 +30,15 @@ namespace DangerousD.GameCore
|
|||
{
|
||||
}
|
||||
|
||||
public abstract void Initialize(GraphicsDevice graphicsDevice);
|
||||
|
||||
public abstract void LoadContent(ContentManager content);
|
||||
|
||||
public abstract void Update(GameTime gameTime);
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Update(GameTime gameTime)
|
||||
{
|
||||
|
||||
Animator.DrawAnimation(Rectangle, "playerIdle", spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||
|
||||
namespace DangerousD.GameCore.GUI
|
||||
{
|
||||
interface IGameObject
|
||||
interface IDrawableObject
|
||||
{
|
||||
void Initialize(GraphicsDevice graphicsDevice);
|
||||
void LoadContent(ContentManager content);
|
|
@ -1,24 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace DangerousD.GameCore.GameObjects
|
||||
namespace DangerousD.GameCore.GameObjects;
|
||||
|
||||
internal abstract class LivingEntity : Entity
|
||||
{
|
||||
abstract class LivingEntity : Entity
|
||||
public LivingEntity(Vector2 position) : base(position)
|
||||
{
|
||||
public LivingEntity(Texture2D texture, Vector2 position) : base(texture, position)
|
||||
{
|
||||
}
|
||||
|
||||
public LivingEntity(Texture2D texture, Vector2 position, GraphicsComponent animator) : base(texture, position, animator)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,10 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DangerousD.GameCore.GameObjects
|
||||
namespace DangerousD.GameCore.GameObjects;
|
||||
|
||||
internal abstract class MapObject : GameObject
|
||||
{
|
||||
class MapObject : GameObject
|
||||
public MapObject(Vector2 position) : base(position)
|
||||
{
|
||||
public MapObject(Texture2D texture, Vector2 position) : base(texture, position)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ using System.Text;
|
|||
|
||||
namespace DangerousD.GameCore.Graphics
|
||||
{
|
||||
class GraphicsComponent
|
||||
public class GraphicsComponent
|
||||
{
|
||||
private List<AnimationContainer> animations;
|
||||
private List<Texture2D> textures;
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
using Microsoft.Xna.Framework.Content;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DangerousD.GameCore
|
||||
{
|
||||
public class GraphicsComponent
|
||||
{
|
||||
}
|
||||
}
|
|
@ -15,9 +15,9 @@ namespace DangerousD.GameCore
|
|||
private GraphicsDeviceManager _graphics;
|
||||
private SpriteBatch _spriteBatch;
|
||||
GameState gameState;
|
||||
IGameObject MenuGUI;
|
||||
IGameObject OptionsGUI;
|
||||
IGameObject LobbyGUI;
|
||||
IDrawableObject MenuGUI;
|
||||
IDrawableObject OptionsGUI;
|
||||
IDrawableObject LobbyGUI;
|
||||
public AppManager()
|
||||
{
|
||||
_graphics = new GraphicsDeviceManager(this);
|
||||
|
|
Loading…
Add table
Reference in a new issue