Made lucas the Main character and also added collision

This commit is contained in:
2020-06-25 00:45:34 -06:00
parent 86cc05f0d7
commit 944f0ff712
12 changed files with 167 additions and 136 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

@@ -19,8 +19,8 @@ namespace Collector
private Player _player; private Player _player;
private PlayerMouse _playerMouse; private PlayerMouse _playerMouse;
private static OrthographicCamera _cam; private static OrthographicCamera _cam;
public static int VirtualWidth; private static int _virtualWidth;
public static int VirtualHeight; private static int _virtualHeight;
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>();
@@ -29,8 +29,10 @@ namespace Collector
{ {
_graphics = new GraphicsDeviceManager(this); _graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
IsMouseVisible = true; IsMouseVisible = true;
IsFixedTimeStep = true; IsFixedTimeStep = true;
_graphics.PreferMultiSampling = true;
} }
protected override void Initialize() protected override void Initialize()
@@ -43,18 +45,18 @@ namespace Collector
Materials.Add(name,Content.Load<Texture2D>(name.ToString())); Materials.Add(name,Content.Load<Texture2D>(name.ToString()));
} }
VirtualWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; _virtualWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
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);
_player = new Player(0, 0); _player = new Player(0, 0);
_cam = new OrthographicCamera(viewportAdapter); _cam = new OrthographicCamera(viewportAdapter);
_cam.LookAt(new Vector2(Player.X+IRestrictions.TileSize/2, Player.Y+IRestrictions.TileSize/2)); _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(_playerMouse, _cam, _spriteBatch, Content); _inputController = new InputController(_cam, _spriteBatch, Content);
WorldRenderer = new WorldRenderer(_playerMouse, _inputController, _spriteBatch, this); WorldRenderer = new WorldRenderer(_playerMouse, _inputController, _spriteBatch, this);
} }
@@ -71,7 +73,8 @@ namespace Collector
var transformMatrix = _cam.GetViewMatrix(); var transformMatrix = _cam.GetViewMatrix();
base.Draw(gameTime); base.Draw(gameTime);
GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.Clear(Color.CornflowerBlue);
_spriteBatch.Begin(transformMatrix: transformMatrix); //Turn on Anti-aliasing by changing SamplerState.PointClamp
_spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, transformMatrix: transformMatrix);
_playerMouse.Draw(); _playerMouse.Draw();
WorldRenderer.Draw(gameTime); WorldRenderer.Draw(gameTime);
_spriteBatch.End(); _spriteBatch.End();

View File

@@ -8,18 +8,19 @@ namespace Collector
{ {
public interface IRestrictions public interface IRestrictions
{ {
public const int Seed = 1; public const int Seed = 3;
public const int TileSize = 1; public const int TileSize = 1;
public const float ViewportHeight = 9f; public const float ViewportHeight = 9f;
public const float ViewportWidth = 16f; public const float ViewportWidth = 16f;
public const int MovementSpeed = 1; public const float MovementSpeed = 4/32f;
public const int KeyDelay = 20; public const int KeyDelay = 20;
public const int ChunkSize = 8; public const int ChunkSize = 8;
public const int SuperChunkSize = 1; public const int SuperChunkSize = 1;
public const int ChunkShift = 3; public const int ChunkShift = 3;
public const int RenderDistance = 5; public const int RenderDistance = 5;
public const float RenderTime = 1/60f; public const float RenderTime = 1/60f;
public const float Zoom = 30; public const float Zoom = 69;
public const float Scale = ViewportWidth/ViewportHeight; public const float Scale = ViewportWidth/ViewportHeight;
public const float AnimationDuration = 0.3f;
} }
} }

View File

@@ -0,0 +1,17 @@
using Humper.Base;
namespace Collector.Character
{
public class Collision
{
private readonly int _tileWidth;
public RectangleF Rectangle { get; private set; }
public Collision(int x, int y,int tileWidth)
{
_tileWidth = tileWidth;
Rectangle = new RectangleF(x,y,tileWidth,tileWidth);
}
}
}

View File

@@ -10,20 +10,18 @@ namespace Collector.Character
{ {
public class InputController : IRestrictions public class InputController : IRestrictions
{ {
private readonly PlayerMouse _playerMouse;
private readonly OrthographicCamera _cam; private readonly OrthographicCamera _cam;
private readonly Dictionary<string, Rectangle[]> _animations; private readonly Dictionary<string, Rectangle[]> _animations;
private readonly Texture2D _texture; private readonly Texture2D _texture;
private readonly SpriteBatch _spriteBatch; private readonly SpriteBatch _spriteBatch;
private string Input { get; set; } private string Input { get; set; }
private int _frameNumber; private int _frameNumber;
private int _timeSinceLastFrame; private float _timeSinceLastFrame;
public InputController(PlayerMouse playerMouse, OrthographicCamera cam, SpriteBatch spriteBatch, ContentManager contentManager) public InputController(OrthographicCamera cam, SpriteBatch spriteBatch, ContentManager contentManager)
{ {
Input = "Down"; Input = "Down";
_playerMouse = playerMouse;
_cam = cam; _cam = cam;
_spriteBatch = spriteBatch; _spriteBatch = spriteBatch;
_frameNumber = 0; _frameNumber = 0;
@@ -31,128 +29,128 @@ namespace Collector.Character
const int tileSize = 32; const int tileSize = 32;
_animations = new Dictionary<string, Rectangle[]> _animations = new Dictionary<string, Rectangle[]>
{ {
["Idle"] = new[]
{
new Rectangle((0 + 4)*tileSize, 0, tileSize, tileSize*2),
new Rectangle((0 + 4)*tileSize, 0, tileSize, tileSize*2),
new Rectangle((0 + 4)*tileSize, 0, tileSize, tileSize*2),
new Rectangle((0 + 4)*tileSize, 0, tileSize, tileSize*2),
},
["Up"] = new[] ["Up"] = new[]
{ {
new Rectangle(0, 0, tileSize, tileSize), new Rectangle(0*tileSize, 0, tileSize, tileSize*2),
new Rectangle(1, 0, tileSize, tileSize), new Rectangle(1*tileSize, 0, tileSize, tileSize*2),
new Rectangle(2, 0, tileSize, tileSize), new Rectangle(2*tileSize, 0, tileSize, tileSize*2),
new Rectangle(3, 0, tileSize, tileSize) new Rectangle(3*tileSize, 0, tileSize, tileSize*2)
}, },
["Right"] = new[] ["Right"] = new[]
{ {
new Rectangle(0 + 4, 1, tileSize, tileSize), new Rectangle((0 + 4)*tileSize, 2*tileSize, tileSize, tileSize*2),
new Rectangle(1 + 4, 1, tileSize, tileSize), new Rectangle((1 + 4)*tileSize, 2*tileSize, tileSize, tileSize*2),
new Rectangle(2 + 4, 1, tileSize, tileSize), new Rectangle((2 + 4)*tileSize, 2*tileSize, tileSize, tileSize*2),
new Rectangle(3 + 4, 1, tileSize, tileSize) new Rectangle((3 + 4)*tileSize, 2*tileSize, tileSize, tileSize*2)
}, },
["UpRight"] = new[] ["UpRight"] = new[]
{ {
new Rectangle(0 + 4, 2, tileSize, tileSize), new Rectangle((0 + 4)*tileSize, 4*tileSize, tileSize, tileSize*2),
new Rectangle(1 + 4, 2, tileSize, tileSize), new Rectangle((1 + 4)*tileSize, 4*tileSize, tileSize, tileSize*2),
new Rectangle(2 + 4, 2, tileSize, tileSize), new Rectangle((2 + 4)*tileSize, 4*tileSize, tileSize, tileSize*2),
new Rectangle(3 + 4, 2, tileSize, tileSize) new Rectangle((3 + 4)*tileSize, 4*tileSize, tileSize, tileSize*2)
}, },
["DownRight"] = new[] ["DownRight"] = new[]
{ {
new Rectangle(0 + 4, 3, tileSize, tileSize), new Rectangle((0 + 4)*tileSize, 6*tileSize, tileSize, tileSize*2),
new Rectangle(1 + 4, 3, tileSize, tileSize), new Rectangle((1 + 4)*tileSize, 6*tileSize, tileSize, tileSize*2),
new Rectangle(2 + 4, 3, tileSize, tileSize), new Rectangle((2 + 4)*tileSize, 6*tileSize, tileSize, tileSize*2),
new Rectangle(3 + 4, 3, tileSize, tileSize) new Rectangle((3 + 4)*tileSize, 6*tileSize, tileSize, tileSize*2)
}, },
["Left"] = new[] ["Left"] = new[]
{ {
new Rectangle(0, 1, tileSize, tileSize), new Rectangle(0*tileSize, 2*tileSize, tileSize, tileSize*2),
new Rectangle(1, 1, tileSize, tileSize), new Rectangle(1*tileSize, 2*tileSize, tileSize, tileSize*2),
new Rectangle(2, 1, tileSize, tileSize), new Rectangle(2*tileSize, 2*tileSize, tileSize, tileSize*2),
new Rectangle(3, 1, tileSize, tileSize) new Rectangle(3*tileSize, 2*tileSize, tileSize, tileSize*2)
}, },
["UpLeft"] = new[] ["UpLeft"] = new[]
{ {
new Rectangle(0, 2, tileSize, tileSize), new Rectangle(0*tileSize, 4*tileSize, tileSize, tileSize*2),
new Rectangle(1, 2, tileSize, tileSize), new Rectangle(1*tileSize, 4*tileSize, tileSize, tileSize*2),
new Rectangle(2, 2, tileSize, tileSize), new Rectangle(2*tileSize, 4*tileSize, tileSize, tileSize*2),
new Rectangle(3, 2, tileSize, tileSize) new Rectangle(3*tileSize, 4*tileSize, tileSize, tileSize*2)
}, },
["DownLeft"] = new[] ["DownLeft"] = new[]
{ {
new Rectangle(0, 1, tileSize, tileSize), new Rectangle(0*tileSize, 6*tileSize, tileSize, tileSize*2),
new Rectangle(1, 1, tileSize, tileSize), new Rectangle(1*tileSize, 6*tileSize, tileSize, tileSize*2),
new Rectangle(2, 1, tileSize, tileSize), new Rectangle(2*tileSize, 6*tileSize, tileSize, tileSize*2),
new Rectangle(3, 1, tileSize, tileSize) new Rectangle(3*tileSize, 6*tileSize, tileSize, tileSize*2)
}, },
["Down"] = new[] ["Down"] = new[]
{ {
new Rectangle(0 + 4, 0, tileSize, tileSize), new Rectangle((0 + 4)*tileSize, 0, tileSize, tileSize*2),
new Rectangle(1 + 4, 0, tileSize, tileSize), new Rectangle((1 + 4)*tileSize, 0, tileSize, tileSize*2),
new Rectangle(2 + 4, 0, tileSize, tileSize), new Rectangle((2 + 4)*tileSize, 0, tileSize, tileSize*2),
new Rectangle(3 + 4, 0, tileSize, tileSize) new Rectangle((3 + 4)*tileSize, 0, tileSize, tileSize*2)
}, },
}; };
} }
public void PlayerInput(Main main, PlayerMouse playerMouse, GameTime gameTime) public void PlayerInput(Main main, GameTime gameTime)
{ {
const int movementSpeed = IRestrictions.MovementSpeed; const float movementSpeed = IRestrictions.MovementSpeed;
var keyboardState = Keyboard.GetState(); var keyboardState = Keyboard.GetState();
var mouseState = Mouse.GetState(); var mouseState = Mouse.GetState();
if (keyboardState.IsKeyDown(Keys.Escape)) if (keyboardState.IsKeyDown(Keys.Escape))
{ {
Quit(main); Quit(main);
} }
if (keyboardState.IsKeyUp(Keys.W) && keyboardState.IsKeyUp(Keys.A) && keyboardState.IsKeyUp(Keys.S) && keyboardState.IsKeyUp(Keys.D))
{
Input = Input.Contains("Right") ? "DownRight" : "DownLeft";
_frameNumber = 0; if (keyboardState.IsKeyUp(Keys.W) && keyboardState.IsKeyUp(Keys.A) && keyboardState.IsKeyUp(Keys.S) &&
_playerMouse.Draw(); keyboardState.IsKeyUp(Keys.D))
{
Input = "Idle";
} }
UpdateAnimationFrame(gameTime);
const float diagonalMovement = 0.707f;
if (keyboardState.IsKeyDown(Keys.W) && keyboardState.IsKeyDown(Keys.D)) if (keyboardState.IsKeyDown(Keys.W) && keyboardState.IsKeyDown(Keys.D))
{ {
UpdateAnimationFrame(gameTime);
Input = "UpRight"; Input = "UpRight";
Player.Move(_cam,movementSpeed,-movementSpeed); 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))
{ {
UpdateAnimationFrame(gameTime); Player.Move(_cam,-movementSpeed*diagonalMovement,-movementSpeed*diagonalMovement);
Input = "UpLeft"; Input = "UpLeft";
Player.Move(_cam,-movementSpeed,-movementSpeed);
} }
else if (keyboardState.IsKeyDown(Keys.S) && keyboardState.IsKeyDown(Keys.D)) else if (keyboardState.IsKeyDown(Keys.S) && keyboardState.IsKeyDown(Keys.D))
{ {
UpdateAnimationFrame(gameTime);
Input = "DownRight"; Input = "DownRight";
Player.Move(_cam,movementSpeed,movementSpeed); 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))
{ {
UpdateAnimationFrame(gameTime);
Input = "DownLeft"; Input = "DownLeft";
Player.Move(_cam,-movementSpeed,movementSpeed); Player.Move(_cam,-movementSpeed*diagonalMovement,movementSpeed*diagonalMovement);
} }
else if (keyboardState.IsKeyDown(Keys.W)) else if (keyboardState.IsKeyDown(Keys.W))
{ {
UpdateAnimationFrame(gameTime);
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))
{ {
UpdateAnimationFrame(gameTime);
Player.Move(_cam,-movementSpeed,0);
Input = "Left"; Input = "Left";
Player.Move(_cam,-movementSpeed,0);
} }
else if (keyboardState.IsKeyDown(Keys.S)) else if (keyboardState.IsKeyDown(Keys.S))
{ {
UpdateAnimationFrame(gameTime);
Player.Move(_cam,0,movementSpeed);
Input = "Down"; Input = "Down";
Player.Move(_cam,0,movementSpeed);
} }
else if (keyboardState.IsKeyDown(Keys.D)) else if (keyboardState.IsKeyDown(Keys.D))
{ {
UpdateAnimationFrame(gameTime);
Player.Move(_cam,movementSpeed,0);
Input = "Right"; Input = "Right";
Player.Move(_cam,movementSpeed,0);
} }
if (keyboardState.IsKeyDown(Keys.Q)) if (keyboardState.IsKeyDown(Keys.Q))
{ {
@@ -162,7 +160,6 @@ namespace Collector.Character
{ {
_cam.ZoomOut(1f); _cam.ZoomOut(1f);
} }
if (mouseState.LeftButton == ButtonState.Pressed) if (mouseState.LeftButton == ButtonState.Pressed)
{ {
Chunks.RemoveBlock(PlayerMouse.GetSelectedX(),PlayerMouse.GetSelectedY()); Chunks.RemoveBlock(PlayerMouse.GetSelectedX(),PlayerMouse.GetSelectedY());
@@ -175,14 +172,11 @@ namespace Collector.Character
private void UpdateAnimationFrame(GameTime gameTime) private void UpdateAnimationFrame(GameTime gameTime)
{ {
_timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; _timeSinceLastFrame += gameTime.GetElapsedSeconds();
if (_timeSinceLastFrame <= 99) return; if (_timeSinceLastFrame <= IRestrictions.AnimationDuration) return;
_frameNumber++; _frameNumber++;
_timeSinceLastFrame = 0; _timeSinceLastFrame = 0;
if (_frameNumber > 3) if (_frameNumber > 3) _frameNumber = 0;
{
_frameNumber = 0;
}
} }
private static void Quit(Game main) private static void Quit(Game main)
@@ -193,11 +187,14 @@ namespace Collector.Character
public void Draw() public void Draw()
{ {
_spriteBatch.Draw( _spriteBatch.Draw(
_texture _texture,
,Player.PlayerBounds new Vector2(Player.X,Player.Y),
,_animations[Input][_frameNumber] _animations[Input][_frameNumber],
,Color.White Color.White, 0f,
); Vector2.One,
1/32f,
SpriteEffects.None,
1f);
} }
} }
} }

View File

@@ -1,35 +1,44 @@
using System; using System;
using System.Collections.Generic; using System.Linq;
using Collector.Dimension; using Collector.Dimension;
using Humper;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended; using MonoGame.Extended;
using MonoGame.Extended.Collections; using RectangleF = Humper.Base.RectangleF;
using Collision = Collector.Dimension.Collision; using Vector2 = Microsoft.Xna.Framework.Vector2;
namespace Collector.Character namespace Collector.Character
{ {
public class Player : IRestrictions public class Player : IRestrictions
{ {
public static int X { get; private set; } public static float X { get; private set; }
public static int Y { get; private set; } public static float Y { get; private set; }
private static Dictionary<string, Rectangle> Animation { get; set; }
public static Rectangle PlayerBounds; public static RectangleF PlayerBounds;
public Player(int x, int y) public Player(int x, int y)
{ {
PlayerBounds = new Rectangle(X,Y,IRestrictions.TileSize,IRestrictions.TileSize);
X = x; X = x;
Y = y; Y = y;
PlayerBounds = new RectangleF(x,y, IRestrictions.TileSize*0.5f, IRestrictions.TileSize*0.35f);
} }
public static void Move(OrthographicCamera cam, int x, int y) public static void Move(OrthographicCamera cam, float x, float y)
{ {
X += x; X += x;
Y += y; Y += y;
cam.Move(new Vector2(x+IRestrictions.TileSize/2, y+IRestrictions.TileSize/2)); PlayerBounds.X = X+0.2f;
PlayerBounds.Location = new Point(X,Y); PlayerBounds.Y = Y+1.5f;
cam.Move(new Vector2(x, y));
if (!Chunks.loadedCollisions.Values.Any(collisionsValue => collisionsValue.Rectangle.Intersects(PlayerBounds))) return;
X -= x;
Y -= y;
cam.Move(new Vector2(-x, -y));
PlayerBounds.X -= X;
PlayerBounds.Y -= Y;
} }
} }
} }

View File

@@ -0,0 +1,7 @@
namespace Collector.Character
{
public class Autotiling
{
}
}

View File

@@ -5,6 +5,8 @@ using System.Collections.Generic;
using Collector.ThirdPartyCode; using Collector.ThirdPartyCode;
using Humper; using Humper;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MonoGame.Extended;
using Collision = Collector.Character.Collision;
namespace Collector.Dimension namespace Collector.Dimension
{ {
@@ -13,7 +15,8 @@ namespace Collector.Dimension
public static Dictionary<Tuple<int, int, int>, Blocks> LoadedChunks { get; } = new Dictionary<Tuple<int, int, int>, Blocks>(); public static 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 static readonly Dictionary<Tuple<int, int, int>, Blocks> SavedChunks = new Dictionary<Tuple<int, int, int>, Blocks>();
private static readonly Dictionary<Tuple<int, int>, Collision> savedCollisions = new Dictionary<Tuple<int, int>, Collision>(); private static readonly Dictionary<Tuple<int, int>, Collision> savedCollisions = new Dictionary<Tuple<int, int>, Collision>();
public static readonly Dictionary<Tuple<int,int>, Collision> loadedCollisions = new Dictionary<Tuple<int, int>, Collision>(); public static readonly Dictionary<Tuple<int, int>, Collision> loadedCollisions = new Dictionary<Tuple<int, int>, Collision>();
public static readonly List<Blocks> Impassable = new List<Blocks>();
private static readonly OpenSimplexNoise Gen1 = new OpenSimplexNoise(IRestrictions.Seed+ 1); private static readonly OpenSimplexNoise Gen1 = new OpenSimplexNoise(IRestrictions.Seed+ 1);
@@ -32,8 +35,8 @@ namespace Collector.Dimension
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,IRestrictions.TileSize,false); loadedCollisions[pair] = new Collision(x,y,IRestrictions.TileSize);
savedCollisions[pair] = new Collision(x,y,IRestrictions.TileSize,false); savedCollisions[pair] = new Collision(x,y,IRestrictions.TileSize);
LoadedChunks[tuple] = name; LoadedChunks[tuple] = name;
SavedChunks[tuple] = name; SavedChunks[tuple] = name;
} }
@@ -55,16 +58,16 @@ namespace Collector.Dimension
if (!LoadedChunks.ContainsKey(tuple)) return; if (!LoadedChunks.ContainsKey(tuple)) return;
if (LoadedChunks[tuple].Equals(Blocks.BlockAir)) return; if (LoadedChunks[tuple].Equals(Blocks.BlockAir)) return;
loadedCollisions[pair] = null; loadedCollisions.Remove(pair);
savedCollisions[pair] = null; savedCollisions.Remove(pair);
LoadedChunks[tuple] = Blocks.BlockAir; LoadedChunks[tuple] = Blocks.BlockAir;
SavedChunks[tuple] = Blocks.BlockAir; SavedChunks[tuple] = Blocks.BlockAir;
} }
public static void UngenerateChunk(int x, int y) { public static void UngenerateChunk(float x, float y) {
var startX = x << IRestrictions.ChunkShift; var startX = (int)x << IRestrictions.ChunkShift;
var startY = y << IRestrictions.ChunkShift; var startY = (int)y << IRestrictions.ChunkShift;
var endX = startX + IRestrictions.ChunkSize; var endX = startX + IRestrictions.ChunkSize;
var endY = startY + IRestrictions.ChunkSize; var endY = startY + IRestrictions.ChunkSize;
@@ -83,9 +86,9 @@ namespace Collector.Dimension
} }
} }
public static void GenerateChunk(int x, int y) { public static void GenerateChunk(float x, float y) {
var startX = x << IRestrictions.ChunkShift; var startX = (int)x << IRestrictions.ChunkShift;
var startY = y << IRestrictions.ChunkShift; var startY = (int)y << IRestrictions.ChunkShift;
var endX = startX + IRestrictions.ChunkSize; var endX = startX + IRestrictions.ChunkSize;
var endY = startY + IRestrictions.ChunkSize; var endY = startY + IRestrictions.ChunkSize;
@@ -97,8 +100,16 @@ namespace Collector.Dimension
LoadedChunks.Add(triple,SavedChunks[triple]); LoadedChunks.Add(triple,SavedChunks[triple]);
} }
else { else {
LoadedChunks.Add(triple, GetTerrain(i, j)); var terrain = GetTerrain(i, j);
SavedChunks.Add(triple, GetTerrain(i,j)); var pair = new Tuple<int, int>(i, j);
if (Impassable.Contains(terrain))
{
loadedCollisions[pair] = new Collision(i,j,IRestrictions.TileSize);
savedCollisions[pair] = new Collision(i,j,IRestrictions.TileSize);
}
LoadedChunks.Add(triple, terrain);
SavedChunks.Add(triple, terrain);
} }
} }
} }
@@ -147,7 +158,7 @@ namespace Collector.Dimension
return GetBiomeBlock(moisture, elevation); return GetBiomeBlock(moisture, elevation);
} }
private static Blocks GetBiomeBlock(double moisture, double elevation) { private static 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;
@@ -196,8 +207,8 @@ namespace Collector.Dimension
return moisture < 0.66 ? "TropicalSeasonalForest" : "TropicalRainForest"; return moisture < 0.66 ? "TropicalSeasonalForest" : "TropicalRainForest";
} }
public static bool IsEmpty(int x, int y){ public static bool IsEmpty(float x, float y){
return !LoadedChunks.ContainsKey(new Tuple<int,int,int>(x * 8, y * 8,0)); return !LoadedChunks.ContainsKey(new Tuple<int,int,int>((int)x * 8, (int)y * 8,0));
} }
} }
} }

View File

@@ -1,18 +0,0 @@
using Microsoft.Xna.Framework;
namespace Collector.Dimension
{
public class Collision
{
private readonly int _tileWidth;
private bool _entity;
public Rectangle Rectangle { get; private set; }
public Collision(int x, int y,int tileWidth, bool entity)
{
_entity = entity;
_tileWidth = tileWidth;
Rectangle = new Rectangle(x,y,tileWidth,tileWidth);
}
}
}

View File

@@ -4,14 +4,14 @@ using Collector.Character;
namespace Collector.Dimension namespace Collector.Dimension
{ {
public static class World { public static class World {
private static void GenerateWorld(int x, int y) private static 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(int x, int y) { private static void UngenerateWorld(float x, float y) {
if (!Chunks.IsEmpty(x, y)) { if (!Chunks.IsEmpty(x, y)) {
Chunks.UngenerateChunk(x, y); Chunks.UngenerateChunk(x, y);
} }
@@ -34,22 +34,22 @@ namespace Collector.Dimension
//Down //Down
UngenerateWorld( UngenerateWorld(
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i, Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
(Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+IRestrictions.RenderDistance Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+IRestrictions.RenderDistance
); );
//Up //Up
UngenerateWorld( UngenerateWorld(
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i, Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
(Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))-IRestrictions.RenderDistance Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-IRestrictions.RenderDistance
); );
//Right //Right
UngenerateWorld( UngenerateWorld(
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-IRestrictions.RenderDistance, Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-IRestrictions.RenderDistance,
(Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+i Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i
); );
//Left //Left
UngenerateWorld( UngenerateWorld(
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+IRestrictions.RenderDistance, Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+IRestrictions.RenderDistance,
(Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+i Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i
); );
} }
} }

View File

@@ -18,6 +18,9 @@ namespace Collector.Dimension
_inputController = inputController; _inputController = inputController;
_spriteBatch = spriteBatch; _spriteBatch = spriteBatch;
_main = main; _main = main;
Chunks.Impassable.Add(Blocks.BlockWater);
Chunks.Impassable.Add(Blocks.BlockRoof);
Chunks.Impassable.Add(Blocks.BlockWall);
} }
private static void DrawWorld(SpriteBatch batch, int layer) private static void DrawWorld(SpriteBatch batch, int layer)
@@ -40,10 +43,11 @@ namespace Collector.Dimension
{ {
//Higher means draws in a lower layer //Higher means draws in a lower layer
DrawWorld(_spriteBatch,0); DrawWorld(_spriteBatch,0);
_playerMouse.Draw();
DrawWorld(_spriteBatch,1); DrawWorld(_spriteBatch,1);
_inputController.Draw(); _inputController.Draw();
_inputController.PlayerInput(_main,_playerMouse,gameTime); _inputController.PlayerInput(_main,gameTime);
DrawWorld(_spriteBatch,2); //DrawWorld(_spriteBatch,2);
} }
} }
} }