Got rid of a large amount of static variables
This commit is contained in:
@@ -25,7 +25,7 @@ namespace Collector
|
|||||||
private int _virtualHeight;
|
private int _virtualHeight;
|
||||||
private readonly Desktop _desktop;
|
private readonly Desktop _desktop;
|
||||||
private Gui _gui;
|
private Gui _gui;
|
||||||
private World _world;
|
private Chunks _chunks;
|
||||||
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>();
|
||||||
|
|
||||||
@@ -57,16 +57,16 @@ 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();
|
_chunks = new Chunks();
|
||||||
Player1 = new Player(0, 0);
|
Player1 = new Player(0, 0, _chunks);
|
||||||
_cam = new OrthographicCamera(viewportAdapter);
|
_cam = new OrthographicCamera(viewportAdapter);
|
||||||
_cam.LookAt(new Vector2(Player.X, Player.Y));
|
_cam.LookAt(new Vector2(Player.X, Player.Y));
|
||||||
_cam.Zoom = IRestrictions.Zoom;
|
_cam.Zoom = IRestrictions.Zoom;
|
||||||
|
|
||||||
_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, this);
|
_inputController = new InputController(_cam, _spriteBatch, Content, this,_chunks,Player1);
|
||||||
WorldRenderer = new WorldRenderer(_playerMouse, _inputController, _spriteBatch, this);
|
WorldRenderer = new WorldRenderer(_playerMouse, _inputController, _spriteBatch, this,_chunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadContent()
|
protected override void LoadContent()
|
||||||
@@ -82,8 +82,8 @@ namespace Collector
|
|||||||
{
|
{
|
||||||
// TODO: Add your update logic here/*
|
// TODO: Add your update logic here/*
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
_world.LoadChunks();
|
_chunks.LoadChunks();
|
||||||
_world.UnloadChunks();
|
_chunks.UnloadChunks();
|
||||||
_gui.Update();
|
_gui.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,15 +17,20 @@ 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;
|
private readonly Main _main;
|
||||||
|
private readonly Chunks _chunks;
|
||||||
|
private readonly Player _player;
|
||||||
|
|
||||||
|
|
||||||
public InputController(OrthographicCamera cam, SpriteBatch spriteBatch, ContentManager contentManager, Main main)
|
|
||||||
|
public InputController(OrthographicCamera cam, SpriteBatch spriteBatch, ContentManager contentManager, Main main, Chunks chunks, Player player)
|
||||||
{
|
{
|
||||||
Input = "Down";
|
Input = "Down";
|
||||||
_cam = cam;
|
_cam = cam;
|
||||||
_spriteBatch = spriteBatch;
|
_spriteBatch = spriteBatch;
|
||||||
_main = main;
|
_main = main;
|
||||||
|
_chunks = chunks;
|
||||||
|
_player = player;
|
||||||
_frameNumber = 0;
|
_frameNumber = 0;
|
||||||
_texture = contentManager.Load<Texture2D>("man");
|
_texture = contentManager.Load<Texture2D>("man");
|
||||||
const int tileSize = 32;
|
const int tileSize = 32;
|
||||||
@@ -97,7 +102,7 @@ namespace Collector.Character
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayerInput(Main main, GameTime gameTime)
|
public void PlayerInput(GameTime gameTime)
|
||||||
{
|
{
|
||||||
const float movementSpeed = IRestrictions.MovementSpeed;
|
const float movementSpeed = IRestrictions.MovementSpeed;
|
||||||
var keyboardState = Keyboard.GetState();
|
var keyboardState = Keyboard.GetState();
|
||||||
@@ -117,42 +122,42 @@ namespace Collector.Character
|
|||||||
if (keyboardState.IsKeyDown(Keys.W) && keyboardState.IsKeyDown(Keys.D))
|
if (keyboardState.IsKeyDown(Keys.W) && keyboardState.IsKeyDown(Keys.D))
|
||||||
{
|
{
|
||||||
Input = "UpRight";
|
Input = "UpRight";
|
||||||
Player.Move(_cam,movementSpeed*diagonalMovement,-movementSpeed*diagonalMovement);
|
_player.Move(_cam,movementSpeed*diagonalMovement,-movementSpeed*diagonalMovement);
|
||||||
}
|
}
|
||||||
else if (keyboardState.IsKeyDown(Keys.W) && keyboardState.IsKeyDown(Keys.A))
|
else if (keyboardState.IsKeyDown(Keys.W) && keyboardState.IsKeyDown(Keys.A))
|
||||||
{
|
{
|
||||||
Player.Move(_cam,-movementSpeed*diagonalMovement,-movementSpeed*diagonalMovement);
|
_player.Move(_cam,-movementSpeed*diagonalMovement,-movementSpeed*diagonalMovement);
|
||||||
Input = "UpLeft";
|
Input = "UpLeft";
|
||||||
}
|
}
|
||||||
else if (keyboardState.IsKeyDown(Keys.S) && keyboardState.IsKeyDown(Keys.D))
|
else if (keyboardState.IsKeyDown(Keys.S) && keyboardState.IsKeyDown(Keys.D))
|
||||||
{
|
{
|
||||||
Input = "DownRight";
|
Input = "DownRight";
|
||||||
Player.Move(_cam,movementSpeed*diagonalMovement,movementSpeed*diagonalMovement);
|
_player.Move(_cam,movementSpeed*diagonalMovement,movementSpeed*diagonalMovement);
|
||||||
}
|
}
|
||||||
else if (keyboardState.IsKeyDown(Keys.S) && keyboardState.IsKeyDown(Keys.A))
|
else if (keyboardState.IsKeyDown(Keys.S) && keyboardState.IsKeyDown(Keys.A))
|
||||||
{
|
{
|
||||||
Input = "DownLeft";
|
Input = "DownLeft";
|
||||||
Player.Move(_cam,-movementSpeed*diagonalMovement,movementSpeed*diagonalMovement);
|
_player.Move(_cam,-movementSpeed*diagonalMovement,movementSpeed*diagonalMovement);
|
||||||
}
|
}
|
||||||
else if (keyboardState.IsKeyDown(Keys.W))
|
else if (keyboardState.IsKeyDown(Keys.W))
|
||||||
{
|
{
|
||||||
Input = "Up";
|
Input = "Up";
|
||||||
Player.Move(_cam,0,-movementSpeed);
|
_player.Move(_cam,0,-movementSpeed);
|
||||||
}
|
}
|
||||||
else if (keyboardState.IsKeyDown(Keys.A))
|
else if (keyboardState.IsKeyDown(Keys.A))
|
||||||
{
|
{
|
||||||
Input = "Left";
|
Input = "Left";
|
||||||
Player.Move(_cam,-movementSpeed,0);
|
_player.Move(_cam,-movementSpeed,0);
|
||||||
}
|
}
|
||||||
else if (keyboardState.IsKeyDown(Keys.S))
|
else if (keyboardState.IsKeyDown(Keys.S))
|
||||||
{
|
{
|
||||||
Input = "Down";
|
Input = "Down";
|
||||||
Player.Move(_cam,0,movementSpeed);
|
_player.Move(_cam,0,movementSpeed);
|
||||||
}
|
}
|
||||||
else if (keyboardState.IsKeyDown(Keys.D))
|
else if (keyboardState.IsKeyDown(Keys.D))
|
||||||
{
|
{
|
||||||
Input = "Right";
|
Input = "Right";
|
||||||
Player.Move(_cam,movementSpeed,0);
|
_player.Move(_cam,movementSpeed,0);
|
||||||
}
|
}
|
||||||
if (keyboardState.IsKeyDown(Keys.Q))
|
if (keyboardState.IsKeyDown(Keys.Q))
|
||||||
{
|
{
|
||||||
@@ -164,7 +169,7 @@ namespace Collector.Character
|
|||||||
}
|
}
|
||||||
if (mouseState.LeftButton == ButtonState.Pressed)
|
if (mouseState.LeftButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
Chunks.RemoveBlock(PlayerMouse.GetSelectedX(),PlayerMouse.GetSelectedY());
|
_chunks.RemoveBlock(PlayerMouse.GetSelectedX(),PlayerMouse.GetSelectedY());
|
||||||
}
|
}
|
||||||
if (mouseState.RightButton == ButtonState.Pressed)
|
if (mouseState.RightButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
@@ -174,7 +179,7 @@ namespace Collector.Character
|
|||||||
|
|
||||||
private void PlaceSelectedBlock(Blocks selectedItem)
|
private void PlaceSelectedBlock(Blocks selectedItem)
|
||||||
{
|
{
|
||||||
Chunks.PlaceBlock(PlayerMouse.GetSelectedX(), PlayerMouse.GetSelectedY(), selectedItem);
|
_chunks.PlaceBlock(PlayerMouse.GetSelectedX(), PlayerMouse.GetSelectedY(), selectedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAnimationFrame(GameTime gameTime)
|
private void UpdateAnimationFrame(GameTime gameTime)
|
||||||
|
|||||||
@@ -10,37 +10,38 @@ namespace Collector.Character
|
|||||||
{
|
{
|
||||||
public static float X { get; private set; }
|
public static float X { get; private set; }
|
||||||
public static float Y { get; private set; }
|
public static float Y { get; private set; }
|
||||||
|
private RectangleF _playerBounds;
|
||||||
|
private Chunks _chunks { get; }
|
||||||
|
|
||||||
public static RectangleF PlayerBounds;
|
public Player(int x, int y, Chunks chunks)
|
||||||
|
|
||||||
public Player(int x, int y)
|
|
||||||
{
|
{
|
||||||
X = x;
|
X = x;
|
||||||
Y = y;
|
Y = y;
|
||||||
PlayerBounds = new RectangleF(x, y, IRestrictions.TileSize * 0.5f, IRestrictions.TileSize * 0.35f);
|
_chunks = chunks;
|
||||||
|
_playerBounds = new RectangleF(x, y, IRestrictions.TileSize * 0.5f, IRestrictions.TileSize * 0.35f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Move(OrthographicCamera cam, float x, float y)
|
public void Move(OrthographicCamera cam, float x, float y)
|
||||||
{
|
{
|
||||||
Teleport(cam, x, 0);
|
Teleport(cam, x, 0);
|
||||||
if (Chunks.LoadedCollisions.Values.Any(collisionsValue => collisionsValue.Rectangle.Intersects(PlayerBounds)))
|
if (_chunks.LoadedCollisions.Values.Any(collisionsValue => collisionsValue.Rectangle.Intersects(_playerBounds)))
|
||||||
{
|
{
|
||||||
Teleport(cam, -x, 0);
|
Teleport(cam, -x, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Teleport(cam, 0, y);
|
Teleport(cam, 0, y);
|
||||||
if (Chunks.LoadedCollisions.Values.Any(collisionsValue => collisionsValue.Rectangle.Intersects(PlayerBounds)))
|
if (_chunks.LoadedCollisions.Values.Any(collisionsValue => collisionsValue.Rectangle.Intersects(_playerBounds)))
|
||||||
{
|
{
|
||||||
Teleport(cam, 0, -y);
|
Teleport(cam, 0, -y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Teleport(OrthographicCamera cam, float x, float y)
|
private void Teleport(OrthographicCamera cam, float x, float y)
|
||||||
{
|
{
|
||||||
X += x;
|
X += x;
|
||||||
Y += y;
|
Y += y;
|
||||||
PlayerBounds.X = X + 0.2f;
|
_playerBounds.X = X + 0.2f;
|
||||||
PlayerBounds.Y = Y + 1.5f;
|
_playerBounds.Y = Y + 1.5f;
|
||||||
cam.Move(new Vector2(x, y));
|
cam.Move(new Vector2(x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Collector.Character
|
namespace Collector.Dimension
|
||||||
{
|
{
|
||||||
public class Autotiling
|
public class Autotiling
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,24 +2,71 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Collector.Character;
|
||||||
using Collector.ThirdPartyCode;
|
using Collector.ThirdPartyCode;
|
||||||
using Collision = Collector.Character.Collision;
|
|
||||||
|
|
||||||
namespace Collector.Dimension
|
namespace Collector.Dimension
|
||||||
{
|
{
|
||||||
public static class Chunks
|
public class Chunks
|
||||||
{
|
{
|
||||||
public static Dictionary<Tuple<int, int, int>, Blocks> LoadedChunks { get; } = new Dictionary<Tuple<int, int, int>, Blocks>();
|
public Dictionary<Tuple<int, int, int>, Blocks> LoadedChunks { get; } = new Dictionary<Tuple<int, int, int>, Blocks>();
|
||||||
private static readonly Dictionary<Tuple<int, int, int>, Blocks> SavedChunks = new Dictionary<Tuple<int, int, int>, Blocks>();
|
private readonly Dictionary<Tuple<int, int, int>, Blocks> _savedChunks = new Dictionary<Tuple<int, int, int>, Blocks>();
|
||||||
public static readonly Dictionary<Tuple<int, int>, Collision> LoadedCollisions = new Dictionary<Tuple<int, int>, Collision>();
|
public readonly Dictionary<Tuple<int, int>, Collision> LoadedCollisions = new Dictionary<Tuple<int, int>, Collision>();
|
||||||
public static readonly Dictionary<Tuple<int, int>, Collision> SavedCollisions = new Dictionary<Tuple<int, int>, Collision>();
|
private readonly Dictionary<Tuple<int, int>, Collision> _savedCollisions = new Dictionary<Tuple<int, int>, Collision>();
|
||||||
public static readonly List<Blocks> Impassable = new List<Blocks>();
|
public readonly List<Blocks> Impassable = new List<Blocks>();
|
||||||
|
private readonly OpenSimplexNoise _gen1 = new OpenSimplexNoise(IRestrictions.Seed+ 1);
|
||||||
|
private readonly OpenSimplexNoise _gen2 = new OpenSimplexNoise(IRestrictions.Seed);
|
||||||
|
|
||||||
|
private void GenerateWorld(float x, float y)
|
||||||
|
{
|
||||||
|
if (IsEmpty(x, y)) {
|
||||||
|
GenerateChunk(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UngenerateWorld(float x, float y) {
|
||||||
|
if (!IsEmpty(x, y)) {
|
||||||
|
UngenerateChunk(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly OpenSimplexNoise Gen1 = new OpenSimplexNoise(IRestrictions.Seed+ 1);
|
public void LoadChunks()
|
||||||
private static readonly OpenSimplexNoise Gen2 = new OpenSimplexNoise(IRestrictions.Seed);
|
{
|
||||||
|
for (var i = -(IRestrictions.RenderDistance); i < IRestrictions.RenderDistance; i++) {
|
||||||
|
for (var j = -(IRestrictions.RenderDistance); j < IRestrictions.RenderDistance; j++) {
|
||||||
|
GenerateWorld(
|
||||||
|
i + Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize),
|
||||||
|
j + Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void CreateStructures() {
|
public void UnloadChunks() {
|
||||||
|
for (var i = -IRestrictions.RenderDistance; i < IRestrictions.RenderDistance+1; i++) {
|
||||||
|
//Down
|
||||||
|
UngenerateWorld(
|
||||||
|
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
|
||||||
|
Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+IRestrictions.RenderDistance
|
||||||
|
);
|
||||||
|
//Up
|
||||||
|
UngenerateWorld(
|
||||||
|
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
|
||||||
|
Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-IRestrictions.RenderDistance
|
||||||
|
);
|
||||||
|
//Right
|
||||||
|
UngenerateWorld(
|
||||||
|
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-IRestrictions.RenderDistance,
|
||||||
|
Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i
|
||||||
|
);
|
||||||
|
//Left
|
||||||
|
UngenerateWorld(
|
||||||
|
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+IRestrictions.RenderDistance,
|
||||||
|
Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void CreateStructures() {
|
||||||
const int i = 10;
|
const int i = 10;
|
||||||
SetBlock(3 + i, 2,1,Blocks.BlockWall);
|
SetBlock(3 + i, 2,1,Blocks.BlockWall);
|
||||||
SetBlock(4 + i, 2,1,Blocks.BlockWall);
|
SetBlock(4 + i, 2,1,Blocks.BlockWall);
|
||||||
@@ -27,18 +74,18 @@ namespace Collector.Dimension
|
|||||||
SetBlock(4 + i, 3,1,Blocks.BlockRoof);
|
SetBlock(4 + i, 3,1,Blocks.BlockRoof);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetBlock(int x, int y, int z, Blocks name)
|
private void SetBlock(int x, int y, int z, Blocks name)
|
||||||
{
|
{
|
||||||
var tuple = new Tuple<int, int, int>(x, y, z);
|
var tuple = new Tuple<int, int, int>(x, y, z);
|
||||||
var pair = new Tuple<int, int>(x, y);
|
var pair = new Tuple<int, int>(x, y);
|
||||||
|
|
||||||
LoadedCollisions[pair] = new Collision(x,y);
|
LoadedCollisions[pair] = new Collision(x,y);
|
||||||
SavedCollisions[pair] = new Collision(x,y);
|
_savedCollisions[pair] = new Collision(x,y);
|
||||||
LoadedChunks[tuple] = name;
|
LoadedChunks[tuple] = name;
|
||||||
SavedChunks[tuple] = name;
|
_savedChunks[tuple] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PlaceBlock(int x, int y, Blocks name)
|
public void PlaceBlock(int x, int y, Blocks name)
|
||||||
{
|
{
|
||||||
var tuple = new Tuple<int, int, int>(x, y, 1);
|
var tuple = new Tuple<int, int, int>(x, y, 1);
|
||||||
if (!LoadedChunks.ContainsKey(tuple)) return;
|
if (!LoadedChunks.ContainsKey(tuple)) return;
|
||||||
@@ -48,7 +95,7 @@ namespace Collector.Dimension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveBlock(int x, int y){
|
public void RemoveBlock(int x, int y){
|
||||||
var tuple = new Tuple<int, int, int>(x, y, 1);
|
var tuple = new Tuple<int, int, int>(x, y, 1);
|
||||||
var pair = new Tuple<int,int>(x,y);
|
var pair = new Tuple<int,int>(x,y);
|
||||||
|
|
||||||
@@ -56,13 +103,13 @@ namespace Collector.Dimension
|
|||||||
if (LoadedChunks[tuple].Equals(Blocks.BlockAir)) return;
|
if (LoadedChunks[tuple].Equals(Blocks.BlockAir)) return;
|
||||||
|
|
||||||
LoadedCollisions.Remove(pair);
|
LoadedCollisions.Remove(pair);
|
||||||
SavedCollisions.Remove(pair);
|
_savedCollisions.Remove(pair);
|
||||||
|
|
||||||
LoadedChunks[tuple] = Blocks.BlockAir;
|
LoadedChunks[tuple] = Blocks.BlockAir;
|
||||||
SavedChunks[tuple] = Blocks.BlockAir;
|
_savedChunks[tuple] = Blocks.BlockAir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UngenerateChunk(float x, float y) {
|
public void UngenerateChunk(float x, float y) {
|
||||||
var startX = (int)x << IRestrictions.ChunkShift;
|
var startX = (int)x << IRestrictions.ChunkShift;
|
||||||
var startY = (int)y << IRestrictions.ChunkShift;
|
var startY = (int)y << IRestrictions.ChunkShift;
|
||||||
var endX = startX + IRestrictions.ChunkSize;
|
var endX = startX + IRestrictions.ChunkSize;
|
||||||
@@ -78,7 +125,7 @@ namespace Collector.Dimension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GenerateChunk(float x, float y) {
|
public void GenerateChunk(float x, float y) {
|
||||||
var startX = (int)x << IRestrictions.ChunkShift;
|
var startX = (int)x << IRestrictions.ChunkShift;
|
||||||
var startY = (int)y << IRestrictions.ChunkShift;
|
var startY = (int)y << IRestrictions.ChunkShift;
|
||||||
var endX = startX + IRestrictions.ChunkSize;
|
var endX = startX + IRestrictions.ChunkSize;
|
||||||
@@ -89,13 +136,13 @@ namespace Collector.Dimension
|
|||||||
for (var j = startY; j != endY; j++) {
|
for (var j = startY; j != endY; j++) {
|
||||||
var triple = new Tuple<int, int, int>(i, j, 0);
|
var triple = new Tuple<int, int, int>(i, j, 0);
|
||||||
var pair = new Tuple<int, int>(i,j);
|
var pair = new Tuple<int, int>(i,j);
|
||||||
if (SavedCollisions.ContainsKey(pair))
|
if (_savedCollisions.ContainsKey(pair))
|
||||||
{
|
{
|
||||||
LoadedCollisions.Add(pair, SavedCollisions[pair]);
|
LoadedCollisions.Add(pair, _savedCollisions[pair]);
|
||||||
|
|
||||||
}
|
}
|
||||||
if(SavedChunks.ContainsKey(triple)){
|
if(_savedChunks.ContainsKey(triple)){
|
||||||
LoadedChunks.Add(triple,SavedChunks[triple]);
|
LoadedChunks.Add(triple,_savedChunks[triple]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var terrain = GetTerrain(i, j);
|
var terrain = GetTerrain(i, j);
|
||||||
@@ -103,11 +150,11 @@ namespace Collector.Dimension
|
|||||||
{
|
{
|
||||||
var collision = new Collision(i,j);
|
var collision = new Collision(i,j);
|
||||||
LoadedCollisions[pair] = collision;
|
LoadedCollisions[pair] = collision;
|
||||||
SavedCollisions[pair] = collision;
|
_savedCollisions[pair] = collision;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadedChunks.Add(triple, terrain);
|
LoadedChunks.Add(triple, terrain);
|
||||||
SavedChunks.Add(triple, terrain);
|
_savedChunks.Add(triple, terrain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,24 +164,24 @@ namespace Collector.Dimension
|
|||||||
for (var j = startY; j != endY; j++) {
|
for (var j = startY; j != endY; j++) {
|
||||||
var triple = new Tuple<int, int, int>(i, j,1);
|
var triple = new Tuple<int, int, int>(i, j,1);
|
||||||
LoadedChunks[triple] = GetBlocks(i,j,1);
|
LoadedChunks[triple] = GetBlocks(i,j,1);
|
||||||
SavedChunks[triple] = GetBlocks(i,j,1);
|
_savedChunks[triple] = GetBlocks(i,j,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Blocks GetBlocks(int x, int y, int z) {
|
private Blocks GetBlocks(int x, int y, int z) {
|
||||||
return SavedChunks.GetValueOrDefault(new Tuple<int, int, int>(x, y, z), Blocks.BlockAir);
|
return _savedChunks.GetValueOrDefault(new Tuple<int, int, int>(x, y, z), Blocks.BlockAir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double Noise1(double nx, double ny) {
|
private double Noise1(double nx, double ny) {
|
||||||
return Gen1.Evaluate(nx, ny) / 2 + 0.5;
|
return _gen1.Evaluate(nx, ny) / 2 + 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double Noise2(double nx, double ny) {
|
private double Noise2(double nx, double ny) {
|
||||||
return Gen2.Evaluate(nx, ny) / 2 + 0.5;
|
return _gen2.Evaluate(nx, ny) / 2 + 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Blocks GetTerrain(int x, int y) {
|
private Blocks GetTerrain(int x, int y) {
|
||||||
const double scale = 0.01;
|
const double scale = 0.01;
|
||||||
var nx = x * scale;
|
var nx = x * scale;
|
||||||
var ny = y * scale;
|
var ny = y * scale;
|
||||||
@@ -157,7 +204,7 @@ namespace Collector.Dimension
|
|||||||
return GetBiomeBlock(moisture, elevation);
|
return GetBiomeBlock(moisture, elevation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Blocks GetBiomeBlock(double moisture, double elevation) {
|
private Blocks GetBiomeBlock(double moisture, double elevation) {
|
||||||
var biome = GetBiome(moisture, elevation);
|
var biome = GetBiome(moisture, elevation);
|
||||||
if (biome.Equals("Tundra")) return Blocks.BlockSnow;
|
if (biome.Equals("Tundra")) return Blocks.BlockSnow;
|
||||||
if (biome.Equals("Taiga")) return Blocks.BlockSnow;
|
if (biome.Equals("Taiga")) return Blocks.BlockSnow;
|
||||||
@@ -179,7 +226,7 @@ namespace Collector.Dimension
|
|||||||
return biome.Equals("SubtropicalDesert") ? Blocks.BlockSand : Blocks.BlockWater;
|
return biome.Equals("SubtropicalDesert") ? Blocks.BlockSand : Blocks.BlockWater;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetBiome(double moisture, double elevation) {
|
private string GetBiome(double moisture, double elevation) {
|
||||||
if (elevation < 0.1) return "Ocean";
|
if (elevation < 0.1) return "Ocean";
|
||||||
if (elevation < 0.12) return "Beach";
|
if (elevation < 0.12) return "Beach";
|
||||||
|
|
||||||
@@ -205,7 +252,7 @@ namespace Collector.Dimension
|
|||||||
return moisture < 0.66 ? "TropicalSeasonalForest" : "TropicalRainForest";
|
return moisture < 0.66 ? "TropicalSeasonalForest" : "TropicalRainForest";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsEmpty(float x, float y){
|
public bool IsEmpty(float x, float y){
|
||||||
return !LoadedChunks.ContainsKey(new Tuple<int,int,int>((int)x * 8, (int)y * 8,0));
|
return !LoadedChunks.ContainsKey(new Tuple<int,int,int>((int)x * 8, (int)y * 8,0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Collector.Character;
|
|
||||||
|
|
||||||
namespace Collector.Dimension
|
|
||||||
{
|
|
||||||
public class World {
|
|
||||||
private void GenerateWorld(float x, float y)
|
|
||||||
{
|
|
||||||
if (Chunks.IsEmpty(x, y)) {
|
|
||||||
Chunks.GenerateChunk(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UngenerateWorld(float x, float y) {
|
|
||||||
if (!Chunks.IsEmpty(x, y)) {
|
|
||||||
Chunks.UngenerateChunk(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadChunks()
|
|
||||||
{
|
|
||||||
for (var i = -(IRestrictions.RenderDistance); i < IRestrictions.RenderDistance; i++) {
|
|
||||||
for (var j = -(IRestrictions.RenderDistance); j < IRestrictions.RenderDistance; j++) {
|
|
||||||
GenerateWorld(
|
|
||||||
i + Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize),
|
|
||||||
j + Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnloadChunks() {
|
|
||||||
for (var i = -IRestrictions.RenderDistance; i < IRestrictions.RenderDistance+1; i++) {
|
|
||||||
//Down
|
|
||||||
UngenerateWorld(
|
|
||||||
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
|
|
||||||
Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+IRestrictions.RenderDistance
|
|
||||||
);
|
|
||||||
//Up
|
|
||||||
UngenerateWorld(
|
|
||||||
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
|
|
||||||
Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-IRestrictions.RenderDistance
|
|
||||||
);
|
|
||||||
//Right
|
|
||||||
UngenerateWorld(
|
|
||||||
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-IRestrictions.RenderDistance,
|
|
||||||
Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i
|
|
||||||
);
|
|
||||||
//Left
|
|
||||||
UngenerateWorld(
|
|
||||||
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+IRestrictions.RenderDistance,
|
|
||||||
Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,24 +11,26 @@ namespace Collector.Dimension
|
|||||||
private readonly InputController _inputController;
|
private readonly InputController _inputController;
|
||||||
private readonly SpriteBatch _spriteBatch;
|
private readonly SpriteBatch _spriteBatch;
|
||||||
private readonly Main _main;
|
private readonly Main _main;
|
||||||
|
private readonly Chunks _chunks;
|
||||||
|
|
||||||
public WorldRenderer(PlayerMouse playerMouse, InputController inputController, SpriteBatch spriteBatch, Main main)
|
public WorldRenderer(PlayerMouse playerMouse, InputController inputController, SpriteBatch spriteBatch, Main main, Chunks chunks)
|
||||||
{
|
{
|
||||||
_playerMouse = playerMouse;
|
_playerMouse = playerMouse;
|
||||||
_inputController = inputController;
|
_inputController = inputController;
|
||||||
_spriteBatch = spriteBatch;
|
_spriteBatch = spriteBatch;
|
||||||
_main = main;
|
_main = main;
|
||||||
Chunks.Impassable.Add(Blocks.BlockWater);
|
_chunks = chunks;
|
||||||
Chunks.Impassable.Add(Blocks.BlockRoof);
|
_chunks.Impassable.Add(Blocks.BlockWater);
|
||||||
Chunks.Impassable.Add(Blocks.BlockWall);
|
_chunks.Impassable.Add(Blocks.BlockRoof);
|
||||||
|
_chunks.Impassable.Add(Blocks.BlockWall);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DrawWorld(SpriteBatch batch, int layer)
|
private void DrawWorld(SpriteBatch batch, int layer)
|
||||||
{
|
{
|
||||||
foreach (var chunkpair in Chunks.LoadedChunks.Keys.Where(chunkpair => layer==chunkpair.Item3))
|
foreach (var chunkpair in _chunks.LoadedChunks.Keys.Where(chunkpair => layer==chunkpair.Item3))
|
||||||
{
|
{
|
||||||
batch.Draw(
|
batch.Draw(
|
||||||
Main.Materials[Chunks.LoadedChunks[chunkpair]],
|
Main.Materials[_chunks.LoadedChunks[chunkpair]],
|
||||||
new Rectangle(
|
new Rectangle(
|
||||||
chunkpair.Item1,
|
chunkpair.Item1,
|
||||||
chunkpair.Item2,
|
chunkpair.Item2,
|
||||||
@@ -46,7 +48,7 @@ namespace Collector.Dimension
|
|||||||
_playerMouse.Draw();
|
_playerMouse.Draw();
|
||||||
DrawWorld(_spriteBatch,1);
|
DrawWorld(_spriteBatch,1);
|
||||||
_inputController.Draw();
|
_inputController.Draw();
|
||||||
_inputController.PlayerInput(_main,gameTime);
|
_inputController.PlayerInput(gameTime);
|
||||||
//DrawWorld(_spriteBatch,2);
|
//DrawWorld(_spriteBatch,2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ namespace Collector.UI
|
|||||||
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
||||||
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
||||||
|
|
||||||
|
|
||||||
//Position
|
//Position
|
||||||
_combo = new ComboBox
|
_combo = new ComboBox
|
||||||
{
|
{
|
||||||
GridColumn = 0,
|
GridColumn = 0,
|
||||||
GridRow = 0
|
GridRow = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
_button = new TextButton
|
_button = new TextButton
|
||||||
{
|
{
|
||||||
GridColumn = 1,
|
GridColumn = 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user