GameProperties, UI structure, Game1 refactoring.

This commit is contained in:
Mootfrost777 2022-07-07 19:15:07 +03:00
parent 11fe1d18e9
commit 6330dcaf84
27 changed files with 163 additions and 8 deletions

Binary file not shown.

Binary file not shown.

View file

@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
namespace Pacman_refactored.Classes
namespace Pacman_refactored.Classes.GameObjects
{
public class Map
{

View file

@ -0,0 +1,44 @@
using Microsoft.Xna.Framework;
namespace Pacman_refactored.Classes
{
/// <summary>
/// Default game properties and textures paths.
/// </summary>
public static class GameProperties
{
public static readonly Vector2 ScreenSize = new Vector2(660, 850);
/// <summary>
/// Default size of one cell in game.
/// </summary>
public const int CellSize = 24;
/// <summary>
/// Default entities moving speed.
/// </summary>
public const float Speed = 1.5f;
#region Textures
// Enviroment
public const string MapSprite = "Enviroment/map";
// Entities
public const string PacmanSprite = "Entities/pacman";
public const string BlinkySprite = "Entities/Ghosts/blinky";
public const string PinkySprite = "Entities/Ghosts/pinky";
public const string InkySprite = "Entities/Ghosts/inky";
public const string ClydeSprite = "Entities/Ghosts/clyde";
// Foods
public const string DotSprite = "Foods/dot";
public const string EnergizerSprite = "Foods/energizer";
public const string StrawberrySprite = "Foods/Fruits/strawberry";
#endregion
}
}

View file

@ -1,10 +1,57 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Pacman_refactored.Enums;
using System;
using System.Collections.Generic;
using System.Text;
using Mootfrost.Monogame.Label;
namespace Pacman_refactored.Classes.UI
{
public class GameOverMenu : Menu
public class MainMenu : Menu
{
public Texture2D Logo { get; set; }
public override SpriteFont SpriteFont { get; set; }
public override Vector2 Position { get; set; }
public override Vector2 ScreenSize { get; set; }
public override string[] MenuItems { get; set; }
public override int SelectedItem { get; set; }
public MainMenu(SpriteFont spriteFont, Vector2 position, Vector2 screenSize)
{
SpriteFont = spriteFont;
Position = position;
ScreenSize = screenSize;
MenuItems = new string[] { "play", "how to play", "quit" };
SelectedItem = 0;
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
// Handle enter button
}
public override void Draw(SpriteBatch spriteBatch)
{
// Draw high score label
Label label = new Label(SpriteFont, $"Hi-score:{1}",
new Vector2(50, 20), ScreenSize, Color.DarkRed);
label.Draw(spriteBatch);
// Draw logo
Rectangle desinationRect = new Rectangle(
new Point((int)ScreenSize.X / 2 - Logo.Width / 2, 100),
new Point(400, 140));
spriteBatch.Draw(Logo, desinationRect, Color.White);
// Draw menu selector
base.Draw(spriteBatch);
}
}
}

View file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Pacman_refactored.Classes.UI
{
public class Hud
{
}
}

View file

@ -4,7 +4,7 @@ using System.Text;
namespace Pacman_refactored.Classes.UI
{
public class MainMenu : Menu
public class GameOverMenu : Menu
{
}
}

View file

@ -18,7 +18,7 @@ namespace Pacman_refactored.Classes.UI
public abstract string[] MenuItems { get; set; }
public abstract int SelectedItem { get; set; }
public abstract Direction PrevDirection { get; set; }
public Direction PrevDirection { get; set; }
public virtual void Update(GameTime gameTime)
{
@ -52,5 +52,12 @@ namespace Pacman_refactored.Classes.UI
label.Draw(spriteBatch);
}
}
public Direction GetDirection()
{
return IControl.GetDirection();
}
}
}

View file

@ -1,8 +1,13 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
using Pacman_refactored.Classes;
using Pacman_refactored.Enums;
using Pacman_refactored.Classes.Entity;
using Pacman_refactored.Classes.UI;
using Pacman_refactored.Classes.Food;
namespace Pacman_refactored
{
@ -11,20 +16,62 @@ namespace Pacman_refactored
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public static Map Map;
// Static fields
public static GameState GameState;
public static Vector2 ScreenSize;
/// <summary>
/// Size of one game cell.
/// </summary>
public static int CellSize;
/// <summary>
/// Default speed of all game objects.
/// </summary>
public static float Speed;
// Static game objects
public Map Map;
// Dynamic game onjects
public Pacman Pacman;
public List<Food> Foods;
public List<Ghost> Ghosts;
// UI
public MainMenu MainMenu;
public GameOverMenu GameOverMenu;
public Hud Hud;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
IsMouseVisible = false;
GameState = GameState.Menu;
ScreenSize = new Vector2(660, 850);
CellSize = 24;
Map = new Map();
Pacman = new Pacman(Speed, CellSize);
Foods = new List<Food>();
Ghosts = new List<Ghost>();
MainMenu = new MainMenu(ScreenSize);
GameOverMenu = new GameOverMenu(ScreenSize);
Hud = new Hud(ScreenSize);
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
// Set screen size.
_graphics.PreferredBackBufferWidth = (int)ScreenSize.X;
_graphics.PreferredBackBufferHeight = (int)ScreenSize.Y;
_graphics.ApplyChanges();
//
Map.Load();
base.Initialize();
}