Fixed the discrepancy between the screen coords and the game coords and also fixed mouse problem when zoomed out too far.
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Collector.ThirdPartyCode;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Humper;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Collector.Dimension
|
||||
{
|
||||
@@ -11,7 +12,10 @@ namespace Collector.Dimension
|
||||
{
|
||||
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>, Collision> savedCollisions = new Dictionary<Tuple<int, int>, Collision>();
|
||||
public static readonly Dictionary<Tuple<int,int>, Collision> loadedCollisions = new Dictionary<Tuple<int, int>, Collision>();
|
||||
|
||||
|
||||
private static readonly OpenSimplexNoise Gen1 = new OpenSimplexNoise(IRestrictions.Seed+ 1);
|
||||
private static readonly OpenSimplexNoise Gen2 = new OpenSimplexNoise(IRestrictions.Seed);
|
||||
|
||||
@@ -25,28 +29,37 @@ namespace Collector.Dimension
|
||||
|
||||
private static void SetBlock(int x, int y, int z, Blocks name)
|
||||
{
|
||||
LoadedChunks[new Tuple<int, int, int>(x, y, z)] = name;
|
||||
SavedChunks[new Tuple<int,int,int>(x, y, z)] = name;
|
||||
var tuple = new Tuple<int, int, int>(x, y, z);
|
||||
var pair = new Tuple<int, int>(x, y);
|
||||
|
||||
loadedCollisions[pair] = new Collision(x,y,IRestrictions.TileSize,false);
|
||||
savedCollisions[pair] = new Collision(x,y,IRestrictions.TileSize,false);
|
||||
LoadedChunks[tuple] = name;
|
||||
SavedChunks[tuple] = name;
|
||||
}
|
||||
|
||||
public static void PlaceBlock(int x, int y, Blocks name)
|
||||
{
|
||||
var triple = new Tuple<int, int, int>(x, y, 1);
|
||||
if (!LoadedChunks.ContainsKey(triple)) return;
|
||||
if (LoadedChunks[triple].Equals(Blocks.BlockAir))
|
||||
var tuple = new Tuple<int, int, int>(x, y, 1);
|
||||
if (!LoadedChunks.ContainsKey(tuple)) return;
|
||||
if (LoadedChunks[tuple].Equals(Blocks.BlockAir))
|
||||
{
|
||||
SetBlock(x, y, 1, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveBlock(int x, int y){
|
||||
var triple = 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);
|
||||
|
||||
if (!LoadedChunks.ContainsKey(triple)) return;
|
||||
if (LoadedChunks[triple].Equals(Blocks.BlockAir)) return;
|
||||
if (!LoadedChunks.ContainsKey(tuple)) return;
|
||||
if (LoadedChunks[tuple].Equals(Blocks.BlockAir)) return;
|
||||
|
||||
LoadedChunks[triple] = Blocks.BlockAir;
|
||||
SavedChunks[triple] = Blocks.BlockAir;
|
||||
loadedCollisions[pair] = null;
|
||||
savedCollisions[pair] = null;
|
||||
|
||||
LoadedChunks[tuple] = Blocks.BlockAir;
|
||||
SavedChunks[tuple] = Blocks.BlockAir;
|
||||
}
|
||||
|
||||
public static void UngenerateChunk(int x, int y) {
|
||||
|
||||
18
Collector/src/Dimension/Collision.cs
Normal file
18
Collector/src/Dimension/Collision.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ using Collector.Character;
|
||||
namespace Collector.Dimension
|
||||
{
|
||||
public static class World {
|
||||
private static void GenerateWorld(int x, int y) {
|
||||
private static void GenerateWorld(int x, int y)
|
||||
{
|
||||
if (Chunks.IsEmpty(x, y)) {
|
||||
Chunks.GenerateChunk(x, y);
|
||||
}
|
||||
@@ -21,8 +22,8 @@ namespace Collector.Dimension
|
||||
for (var i = -(IRestrictions.RenderDistance); i < IRestrictions.RenderDistance; i++) {
|
||||
for (var j = -(IRestrictions.RenderDistance); j < IRestrictions.RenderDistance; j++) {
|
||||
GenerateWorld(
|
||||
i + Player.X / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize),
|
||||
j + Player.Y / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)
|
||||
i + Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize),
|
||||
j + Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -32,23 +33,23 @@ namespace Collector.Dimension
|
||||
for (var i = -IRestrictions.RenderDistance; i < IRestrictions.RenderDistance+1; i++) {
|
||||
//Down
|
||||
UngenerateWorld(
|
||||
Player.X / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
|
||||
(Player.Y / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+3
|
||||
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
|
||||
(Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+IRestrictions.RenderDistance
|
||||
);
|
||||
//Up
|
||||
UngenerateWorld(
|
||||
Player.X / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i-1,
|
||||
(Player.Y / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))-4
|
||||
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
|
||||
(Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))-IRestrictions.RenderDistance
|
||||
);
|
||||
//Right
|
||||
UngenerateWorld(
|
||||
Player.X / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-4,
|
||||
(Player.Y / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+i
|
||||
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-IRestrictions.RenderDistance,
|
||||
(Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+i
|
||||
);
|
||||
//Left
|
||||
UngenerateWorld(
|
||||
Player.X / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+3,
|
||||
(Player.Y / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+i
|
||||
Player.X / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+IRestrictions.RenderDistance,
|
||||
(Player.Y / (IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+i
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace Collector.Dimension
|
||||
batch.Draw(
|
||||
Main.Materials[Chunks.LoadedChunks[chunkpair]],
|
||||
new Rectangle(
|
||||
chunkpair.Item1 << IRestrictions.TileShift,
|
||||
chunkpair.Item2 << IRestrictions.TileShift,
|
||||
chunkpair.Item1,
|
||||
chunkpair.Item2,
|
||||
IRestrictions.TileSize, IRestrictions.TileSize
|
||||
),
|
||||
Color.White
|
||||
|
||||
Reference in New Issue
Block a user