night commit NumMber One!

This commit is contained in:
SergoDobro 2023-08-15 02:21:25 +03:00
parent 4b855c2036
commit f298d83793
10 changed files with 85 additions and 20 deletions

View file

@ -13,3 +13,15 @@
#---------------------------------- Content ---------------------------------#
#begin wall.jpg
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:wall.jpg

BIN
DangerousD/Content/wall.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 KiB

View file

@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using DangerousD.GameCore.Managers;
using Microsoft.Xna.Framework;
using MonogameLibrary.UI.Elements;
namespace DangerousD.GameCore.GUI;
@ -8,5 +9,13 @@ internal class MenuGUI : AbstractGui
protected override void CreateUI()
{
Elements.Add(new CheckBox(Manager) { rectangle = new Rectangle(10, 10, 50, 50) });
var but = new Button(Manager) { rectangle = new Rectangle(100, 10, 80, 50) };
Elements.Add(but);
but.LeftButtonPressed += () =>
{
AppManager.AppManagerInstance.ChangeGameState(GameState.Game);
GameManager.mapManager.LoadLevel("");
};
}
}

View file

@ -24,6 +24,7 @@ namespace DangerousD.GameCore.GameObjects
dir.Normalize();
Pos += dir * speed;
}
base.Update(gameTime);
}
}
}

View file

@ -20,8 +20,8 @@ namespace DangerousD.GameCore
public GameObject(Vector2 pos)
{
Pos = pos;
Width = 500;
Height = 100;
Width = 128;
Height = 128;
//Animator = new GraphicsComponent(new() { "playerIdle" });
GameManager.Register(this);
}
@ -34,10 +34,10 @@ namespace DangerousD.GameCore
public virtual void LoadContent(ContentManager content)
{
graphicsComponent.LoadContent(content);
graphicsComponent.LoadContent();
}
public abstract void Update(GameTime gameTime);
public virtual void Update(GameTime gameTime) { graphicsComponent.Update(); }
public virtual void Draw(SpriteBatch spriteBatch)
{

View file

@ -13,20 +13,22 @@ namespace DangerousD.GameCore.GameObjects.MapObjects
{
public GrassBlock(Vector2 position) : base(position)
{
Width = 32;
Height = 32;
}
public override void Initialize(GraphicsDevice graphicsDevice)
{
}
public override void LoadContent(ContentManager content)
{
// graphicsComponent = new Graphics.GraphicsComponent();
graphicsComponent = new Graphics.GraphicsComponent(content.Load<Texture2D>("wall"));
base.LoadContent(content);
}
public override void Update(GameTime gameTime)
{
public override void Draw(SpriteBatch spriteBatch)
{
base.Draw(spriteBatch);
}
}
}

View file

@ -22,6 +22,11 @@ namespace DangerousD.GameCore.Graphics
private int interval;
private int lastInterval;
private Rectangle sourceRectangle;
public static ContentManager contentManager;
public static void LoadGraphicsComponent(ContentManager _contentManager)
{
contentManager = _contentManager;
}
public GraphicsComponent(List<string> animationsId, string neitralAnimationId)
{
//this._spriteBatch = _spriteBatch;
@ -34,6 +39,8 @@ namespace DangerousD.GameCore.Graphics
}
public GraphicsComponent(Texture2D texture)
{
animations = new List<AnimationContainer>();
textures = new List<Texture2D>();
textures.Add(texture);
AnimationContainer animationContainer = new AnimationContainer();
animationContainer.StartSpriteRectangle = new Rectangle(0, 0, texture.Width, texture.Height);
@ -43,6 +50,9 @@ namespace DangerousD.GameCore.Graphics
animationContainer.FramesCount = 1;
animationContainer.FrameTime = new List<Tuple<int, int>>() { new Tuple<int, int>(0, 10) };
animationContainer.Id = texture.Name;
currentAnimation= animationContainer;
neitralAnimation = animationContainer;
animations.Add(animationContainer);
}
private void LoadAnimations(List<string> animationsId, string neitralAnimationId)
{
@ -56,7 +66,7 @@ namespace DangerousD.GameCore.Graphics
}
}
}
public void LoadContent(ContentManager content)
public void LoadContent()
{
textures = new List<Texture2D>();
texturesNames = new List<string>();
@ -66,7 +76,7 @@ namespace DangerousD.GameCore.Graphics
if (!texturesNames.Contains(animation.TextureName))
{
texturesNames.Add(animation.TextureName);
textures.Add(content.Load<Texture2D>(animation.TextureName));
textures.Add(contentManager.Load<Texture2D>(animation.TextureName));
}
}

View file

@ -6,12 +6,14 @@ using System.Collections.Generic;
using System.Text;
using DangerousD.GameCore.GUI;
using Microsoft.Xna.Framework.Input;
using DangerousD.GameCore.Graphics;
namespace DangerousD.GameCore
{
public enum GameState { Menu, Options, Lobby, Game }
public class AppManager : Game
{
public static AppManager AppManagerInstance { get; private set; }
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
GameState gameState;
@ -20,6 +22,7 @@ namespace DangerousD.GameCore
IDrawableObject LobbyGUI;
public AppManager()
{
AppManagerInstance = this;
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
@ -31,12 +34,14 @@ namespace DangerousD.GameCore
protected override void Initialize()
{
GameManager.Init();
MenuGUI.Initialize(GraphicsDevice);
base.Initialize();
}
protected override void LoadContent()
{
GraphicsComponent.LoadGraphicsComponent(Content);
_spriteBatch = new SpriteBatch(GraphicsDevice);
MenuGUI.LoadContent(Content);
}
@ -83,7 +88,9 @@ namespace DangerousD.GameCore
LobbyGUI.Draw(_spriteBatch);
break;
case GameState.Game:
_spriteBatch.Begin();
GameManager.Draw(_spriteBatch);
_spriteBatch.End();
break;
default:
break;

View file

@ -1,5 +1,6 @@
using DangerousD.GameCore.GameObjects;
using DangerousD.GameCore.Graphics;
using DangerousD.GameCore.Managers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@ -11,27 +12,46 @@ namespace DangerousD.GameCore
static class GameManager
{
static List<LivingEntity> livingEntities;
static List<MapObject> MapObjects;
static List<Entity> entities;
static List<MapObject> mapObjects;
public static AnimationBuilder builder;
public static MapManager mapManager;
internal static void Register(GameObject gameObject)
{
if (gameObject is LivingEntity)
livingEntities.Add(gameObject as LivingEntity);
if (gameObject is Entity)
entities.Add(gameObject as Entity);
if (gameObject is MapObject)
MapObjects.Add(gameObject as MapObject);
mapObjects.Add(gameObject as MapObject);
}
public static void Start()
public static void Init()
{
livingEntities = new List<LivingEntity>();
MapObjects = new List<MapObject>();
mapObjects = new List<MapObject>();
entities = new List<Entity>();
mapManager =new MapManager();
mapManager.Init();
}
public static void Draw(SpriteBatch _spriteBatch)
{
foreach (var item in mapObjects)
item.Draw(_spriteBatch);
foreach (var item in entities)
item.Draw(_spriteBatch);
foreach (var item in livingEntities)
item.Draw(_spriteBatch);
}
public static void Update(GameTime gameTime)
{
foreach (var item in mapObjects)
item.Update(gameTime);
foreach (var item in entities)
item.Update(gameTime);
foreach (var item in livingEntities)
item.Update(gameTime);
}
}

View file

@ -1,4 +1,6 @@
using DangerousD.GameCore.GameObjects;
using DangerousD.GameCore.GameObjects.MapObjects;
using DangerousD.GameCore.Graphics;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
@ -17,19 +19,21 @@ namespace DangerousD.GameCore.Managers
{
public void InitLevel()
{
//new MapObject(new Vector2(0,128));
var Трава = new GrassBlock(new Vector2(0,128));
Трава.LoadContent(GraphicsComponent.contentManager);
}
}
public class MapManager
{
ILevel Level;
public void Init()
{
Level = new Level1();
}
//Level
public void LoadLevel(string level)
{
Level.InitLevel();
}
}
}