Removed a large amount of static classes
This commit is contained in:
@@ -26,6 +26,7 @@ namespace Collector
|
|||||||
private static int _virtualHeight;
|
private static int _virtualHeight;
|
||||||
private Desktop _desktop;
|
private Desktop _desktop;
|
||||||
private Gui _gui;
|
private Gui _gui;
|
||||||
|
private World _world;
|
||||||
private WorldRenderer WorldRenderer { get; set; }
|
private WorldRenderer WorldRenderer { get; set; }
|
||||||
public static Dictionary<Blocks, Texture2D> Materials { get; } = new Dictionary<Blocks, Texture2D>();
|
public static Dictionary<Blocks, Texture2D> Materials { get; } = new Dictionary<Blocks, Texture2D>();
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ namespace Collector
|
|||||||
_virtualHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
|
_virtualHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
|
||||||
|
|
||||||
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, _virtualWidth, _virtualHeight);
|
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, _virtualWidth, _virtualHeight);
|
||||||
|
_world = new World();
|
||||||
_player = new Player(0, 0);
|
_player = new Player(0, 0);
|
||||||
_cam = new OrthographicCamera(viewportAdapter);
|
_cam = new OrthographicCamera(viewportAdapter);
|
||||||
_cam.LookAt(new Vector2(Player.X, Player.Y));
|
_cam.LookAt(new Vector2(Player.X, Player.Y));
|
||||||
@@ -63,7 +65,7 @@ namespace Collector
|
|||||||
|
|
||||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
_playerMouse = new PlayerMouse(Content, _spriteBatch, _cam);
|
_playerMouse = new PlayerMouse(Content, _spriteBatch, _cam);
|
||||||
_inputController = new InputController(_cam, _spriteBatch, Content);
|
_inputController = new InputController(_cam, _spriteBatch, Content,this);
|
||||||
WorldRenderer = new WorldRenderer(_playerMouse, _inputController, _spriteBatch, this);
|
WorldRenderer = new WorldRenderer(_playerMouse, _inputController, _spriteBatch, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,11 +82,16 @@ namespace Collector
|
|||||||
{
|
{
|
||||||
// TODO: Add your update logic here/*
|
// TODO: Add your update logic here/*
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
World.LoadChunks();
|
_world.LoadChunks();
|
||||||
World.UnloadChunks();
|
_world.UnloadChunks();
|
||||||
_gui.Update();
|
_gui.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Quit(Game main)
|
||||||
|
{
|
||||||
|
Exit();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Draw(GameTime gameTime)
|
protected override void Draw(GameTime gameTime)
|
||||||
{// TODO: Add your drawing code here
|
{// TODO: Add your drawing code here
|
||||||
var transformMatrix = _cam.GetViewMatrix();
|
var transformMatrix = _cam.GetViewMatrix();
|
||||||
|
|||||||
@@ -17,13 +17,15 @@ namespace Collector.Character
|
|||||||
private string Input { get; set; }
|
private string Input { get; set; }
|
||||||
private int _frameNumber;
|
private int _frameNumber;
|
||||||
private float _timeSinceLastFrame;
|
private float _timeSinceLastFrame;
|
||||||
|
private Main _main;
|
||||||
|
|
||||||
|
|
||||||
public InputController(OrthographicCamera cam, SpriteBatch spriteBatch, ContentManager contentManager)
|
public InputController(OrthographicCamera cam, SpriteBatch spriteBatch, ContentManager contentManager, Main main)
|
||||||
{
|
{
|
||||||
Input = "Down";
|
Input = "Down";
|
||||||
_cam = cam;
|
_cam = cam;
|
||||||
_spriteBatch = spriteBatch;
|
_spriteBatch = spriteBatch;
|
||||||
|
_main = main;
|
||||||
_frameNumber = 0;
|
_frameNumber = 0;
|
||||||
_texture = contentManager.Load<Texture2D>("man");
|
_texture = contentManager.Load<Texture2D>("man");
|
||||||
const int tileSize = 32;
|
const int tileSize = 32;
|
||||||
@@ -102,7 +104,7 @@ namespace Collector.Character
|
|||||||
var mouseState = Mouse.GetState();
|
var mouseState = Mouse.GetState();
|
||||||
if (keyboardState.IsKeyDown(Keys.Escape))
|
if (keyboardState.IsKeyDown(Keys.Escape))
|
||||||
{
|
{
|
||||||
Quit(main);
|
_main.Quit(main);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyboardState.IsKeyUp(Keys.W) && keyboardState.IsKeyUp(Keys.A) && keyboardState.IsKeyUp(Keys.S) &&
|
if (keyboardState.IsKeyUp(Keys.W) && keyboardState.IsKeyUp(Keys.A) && keyboardState.IsKeyUp(Keys.S) &&
|
||||||
@@ -170,7 +172,7 @@ namespace Collector.Character
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PlaceSelectedBlock(Blocks selectedItem)
|
private void PlaceSelectedBlock(Blocks selectedItem)
|
||||||
{
|
{
|
||||||
Chunks.PlaceBlock(PlayerMouse.GetSelectedX(), PlayerMouse.GetSelectedY(), selectedItem);
|
Chunks.PlaceBlock(PlayerMouse.GetSelectedX(), PlayerMouse.GetSelectedY(), selectedItem);
|
||||||
}
|
}
|
||||||
@@ -184,11 +186,6 @@ namespace Collector.Character
|
|||||||
if (_frameNumber > 3) _frameNumber = 0;
|
if (_frameNumber > 3) _frameNumber = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Quit(Game main)
|
|
||||||
{
|
|
||||||
main.Exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
_spriteBatch.Draw(
|
_spriteBatch.Draw(
|
||||||
|
|||||||
@@ -3,21 +3,21 @@ using Collector.Character;
|
|||||||
|
|
||||||
namespace Collector.Dimension
|
namespace Collector.Dimension
|
||||||
{
|
{
|
||||||
public static class World {
|
public class World {
|
||||||
private static void GenerateWorld(float x, float y)
|
private void GenerateWorld(float x, float y)
|
||||||
{
|
{
|
||||||
if (Chunks.IsEmpty(x, y)) {
|
if (Chunks.IsEmpty(x, y)) {
|
||||||
Chunks.GenerateChunk(x, y);
|
Chunks.GenerateChunk(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UngenerateWorld(float x, float y) {
|
private void UngenerateWorld(float x, float y) {
|
||||||
if (!Chunks.IsEmpty(x, y)) {
|
if (!Chunks.IsEmpty(x, y)) {
|
||||||
Chunks.UngenerateChunk(x, y);
|
Chunks.UngenerateChunk(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadChunks()
|
public void LoadChunks()
|
||||||
{
|
{
|
||||||
for (var i = -(IRestrictions.RenderDistance); i < IRestrictions.RenderDistance; i++) {
|
for (var i = -(IRestrictions.RenderDistance); i < IRestrictions.RenderDistance; i++) {
|
||||||
for (var j = -(IRestrictions.RenderDistance); j < IRestrictions.RenderDistance; j++) {
|
for (var j = -(IRestrictions.RenderDistance); j < IRestrictions.RenderDistance; j++) {
|
||||||
@@ -29,7 +29,7 @@ namespace Collector.Dimension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UnloadChunks() {
|
public void UnloadChunks() {
|
||||||
for (var i = -IRestrictions.RenderDistance; i < IRestrictions.RenderDistance+1; i++) {
|
for (var i = -IRestrictions.RenderDistance; i < IRestrictions.RenderDistance+1; i++) {
|
||||||
//Down
|
//Down
|
||||||
UngenerateWorld(
|
UngenerateWorld(
|
||||||
|
|||||||
Reference in New Issue
Block a user