I am very new to MonoGame and C# and I am really struggling to get my main code to interact with the class I’ve created.
The core idea is that I want a bar to slowly decrease as time passes.
I have tried so many things and now it’s all a big mess now.
If anyone has any advice or solutions I would really like to hear them.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
namespace Vpet_001
{
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private Texture2D _texture;
private Vector2 _position;
private Rectangle _barState;
private int _spriteX;
private int _spriteY;
private int _spriteWidth;
private int _spriteHeight;
public BarClock hunger;
public SpriteFont gameFont;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
gameFont = Content.Load<SpriteFont>("galleryFont");
_spriteBatch = new SpriteBatch(GraphicsDevice);
_texture = Content.Load<Texture2D>("Bar-Sheet");
_position = new Vector2(10, 10);
_barState = new Rectangle(_spriteX, _spriteY, _spriteWidth, _spriteHeight);
hunger = new BarClock();
hunger.aBarMax = 6;
hunger.aBarCurrent = 6;
}
protected override void Update(GameTime gameTime)
{
hunger.BarState();
if (hunger.barState == 6)
{
_spriteX = 0;
_spriteY = 0;
_spriteWidth = 100;
_spriteHeight = 22;
_barState.X = _spriteX;
_barState.Y = _spriteY;
_barState.Width = _spriteWidth;
_barState.Height = _spriteHeight;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
_spriteBatch.Begin();
_spriteBatch.Draw(_texture, _position, _barState, Color.White);
//_spriteBatch.DrawString(gameFont, hunger.barState, new Vector2(500, 10), Color.White);
//_spriteBatch.DrawString(gameFont, gameDay.ToString(), new Vector2(500, 40), Color.White);
_spriteBatch.End();
base.Draw(gameTime);
}
}
}
This is the class im trying to use
`using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vpet_001
{
public class BarClock
{
private int gameTime = 0; //counting up every frame of the program
public static int gameDayLength = 30; //How many frames it takes to equal 1 Day
private int gameDay = 0; //represents the current day number
private int barDurration; //how many days it takes for I segment of the bar to be depleted
public int barMax; //the maximum number of segments in the bar
private static int barMin = 0; //the minimum number of segments in a bar
public int barCurrent; //the current amount of segments in the bar
public int barState;
public int aBarCurrent;
public int aBarMax;
public void BarState()
{
barCurrent = aBarCurrent;
barMax = aBarMax;
while (barCurrent > barMin && barCurrent <= barMax)
{
gameTime++;
if (gameTime == gameDayLength)
{
gameDay++;
barCurrent--;
gameTime = 0;
}
}
barState = barCurrent;
}
}
}````