Added back the map, movement and zooming. Also changed all Textures to 32bit

This commit is contained in:
2020-04-21 13:39:42 -06:00
parent 2892570539
commit 85af72cfa1
56 changed files with 659 additions and 241 deletions

View File

@@ -1,12 +1,8 @@
public class Block {
private string name = null;
public string Name { get; }
public Block(string name) {
this.name = name;
}
public string getName() {
return name;
Name = name;
}
}

View File

@@ -12,7 +12,7 @@ namespace Collector.Dimension
//Private so the singleton can't be instantiated
internal BlockMaterials() {}
public static void LoadContent(ContentManager content){
public static void Initialize(ContentManager content){
Materials.Add("grass",new Block("grass"));
Materials.Add("wood",new Block("wood"));
Materials.Add("water",new Block("water"));
@@ -27,11 +27,11 @@ namespace Collector.Dimension
{
Textures.Add(name,content.Load<Texture2D>(name));
}
}
public static void Draw(string name,SpriteBatch _spriteBatch,int x, int y)
{
_spriteBatch.Draw(Textures[name],new Vector2(x, y),Color.Aqua);
}
}
}

View File

@@ -7,36 +7,38 @@ using Collector.ThirdPartyCode;
namespace Collector.Dimension
{
public class Chunks: IRestrictions {
public static Dictionary<Tuple<int, int, int>, Block> LoadedChunks = new Dictionary<Tuple<int, int, int>, Block>();
public static Dictionary<Tuple<int, int, int>, Block> SavedChunks = new Dictionary<Tuple<int, int, int>, Block>();
public static OpenSimplexNoise Gen1 = new OpenSimplexNoise(IRestrictions.Seed+ 1);
public static OpenSimplexNoise Gen2 = new OpenSimplexNoise(IRestrictions.Seed);
public static Dictionary<Tuple<int, int, int>, Block> LoadedChunks { get; } =
new Dictionary<Tuple<int, int, int>, Block>();
private static readonly Dictionary<Tuple<int, int, int>, Block> SavedChunks = new Dictionary<Tuple<int, int, int>, Block>();
private static readonly OpenSimplexNoise _gen1 = new OpenSimplexNoise(IRestrictions.Seed+ 1);
private static readonly OpenSimplexNoise _gen2 = new OpenSimplexNoise(IRestrictions.Seed);
public static void CreateStructures() {
var i = 10;
const int i = 10;
SetBlock(3 + i, 2,1,"wall");
SetBlock(4 + i, 2,1,"wall");
SetBlock(3 + i, 3,1, "roof");
SetBlock(4 + i, 3,1,"roof");
}
public static void SetBlock(int x, int y,int z, String name) {
public static void SetBlock(int x, int y,int z, string name) {
LoadedChunks.Add(new Tuple<int,int,int>(x, y, z), BlockMaterials.Materials[name]);
SavedChunks.Add(new Tuple<int,int,int>(x, y, z), BlockMaterials.Materials[name]);
}
public static void PlaceBlock(int x, int y, String name){
public static void PlaceBlock(int x, int y, string name){
var triple = new Tuple<int, int, int>(x, y, 1);
if (!Chunks.LoadedChunks[triple].getName().Equals("air")) return;
Chunks.LoadedChunks[triple] = BlockMaterials.Materials[name];
Chunks.SavedChunks[triple] = BlockMaterials.Materials[name];
if (!LoadedChunks[triple].Name.Equals("air")) return;
LoadedChunks[triple] = BlockMaterials.Materials[name];
SavedChunks[triple] = BlockMaterials.Materials[name];
}
public static void RemoveBlock(int x, int y){
var triple = new Tuple<int, int, int>(x, y, 1);
if (Chunks.LoadedChunks[triple].getName().Equals("air")) return;
Chunks.LoadedChunks[triple] = BlockMaterials.Materials["air"];
Chunks.SavedChunks[triple] = BlockMaterials.Materials["air"];
if (LoadedChunks[triple].Name.Equals("air")) return;
LoadedChunks[triple] = BlockMaterials.Materials["air"];
SavedChunks[triple] = BlockMaterials.Materials["air"];
}
public static void UngenerateChunk(int x, int y) {
@@ -70,7 +72,7 @@ namespace Collector.Dimension
for (var i = startX; i != endX; i++) {
for (var j = startY; j != endY; j++) {
var triple = new Tuple<int, int, int>(i, j, 0);
if(SavedChunks[triple] != null){
if(SavedChunks.ContainsKey(triple)){
LoadedChunks.Add(triple,SavedChunks[triple]);
}
else {
@@ -84,8 +86,8 @@ namespace Collector.Dimension
for (var i = startX; i != endX; i++){
for (var j = startY; j != endY; j++) {
var triple = new Tuple<int, int, int>(i, j,1);
LoadedChunks.Add(triple, GetBlocks(i,j,1));
SavedChunks.Add(triple, GetBlocks(i,j,1));
LoadedChunks[triple] = GetBlocks(i,j,1);
SavedChunks[triple] = GetBlocks(i,j,1);
}
}
}
@@ -95,11 +97,11 @@ namespace Collector.Dimension
}
private static 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) {
return Gen2.Evaluate(nx, ny) / 2 + 0.5;
return _gen2.Evaluate(nx, ny) / 2 + 0.5;
}
private static Block GetTerrain(int x, int y) {
@@ -174,7 +176,7 @@ namespace Collector.Dimension
}
public static bool IsEmpty(int x, int y){
return LoadedChunks[new Tuple<int,int,int>(x * 8, y * 8,0)] == null;
return !LoadedChunks.ContainsKey(new Tuple<int,int,int>(x * 8, y * 8,0));
}
}
}

View File

@@ -1,53 +1,56 @@
using Collector;
using Collector.Dimension;
using System;
using Collector.Character;
public class World {
public static void generateWorld(int x, int y) {
if (Chunks.IsEmpty(x, y)) {
Chunks.GenerateChunk(x, y);
namespace Collector.Dimension
{
public static class World {
private static void GenerateWorld(int x, int y) {
if (Chunks.IsEmpty(x, y)) {
Chunks.GenerateChunk(x, y);
}
}
}
public static void ungenerateWorld(int x, int y) {
if (!Chunks.IsEmpty(x, y)) {
Chunks.UngenerateChunk(x, y);
private static void UngenerateWorld(int x, int y) {
if (!Chunks.IsEmpty(x, y)) {
Chunks.UngenerateChunk(x, y);
}
}
}
public static void loadChunks() {
for (var i = -(IRestrictions.RenderDistance); i < IRestrictions.RenderDistance; i++) {
for (var j = -(IRestrictions.RenderDistance); j < IRestrictions.RenderDistance; j++) {
generateWorld(
i + Player.getX() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize),
j + Player.getY() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)
public static 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.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize),
j + Player.Y / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)
);
}
}
}
public static void UnloadChunks() {
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
);
//Up
UngenerateWorld(
Player.X / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i-1,
(Player.Y / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))-4
);
//Right
UngenerateWorld(
Player.X / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-4,
(Player.Y / (IRestrictions.TileSize * 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
);
}
}
}
public static void unloadChunks() {
for (var i = -IRestrictions.RenderDistance; i < IRestrictions.RenderDistance+1; i++) {
//Down
ungenerateWorld(
Player.getX() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i,
(Player.getY() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+3
);
//Up
ungenerateWorld(
Player.getX() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+i-1,
(Player.getY() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))-4
);
//Right
ungenerateWorld(
Player.getX() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)-4,
(Player.getY() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+i
);
//Left
ungenerateWorld(
Player.getX() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize)+3,
(Player.getY() / (IRestrictions.TileSize * IRestrictions.SuperChunkSize * IRestrictions.ChunkSize))+i
);
}
}
}

View File

@@ -1,51 +1,66 @@
using System.Linq;
using Collector.Character;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended;
namespace Collector.Dimension
{
public class WorldRenderer : IRestrictions {
//private Mouse mouse;
//private InputController inputController;
//private Player _player;
public class WorldRenderer : IRestrictions
{
private Mouse _mouse;
private InputController _inputController;
private Player _player;
private SpriteBatch _spriteBatch;
private Main _main;
private OrthographicCamera _orthographicCamera;
/*
public WorldRenderer(InputController inputController, Mouse mouse, Player player) {
this.inputController = inputController;
this.mouse = mouse;
this.player = player;
}
*/
public void DrawWorld(SpriteBatch batch, int layer)
public WorldRenderer(Mouse mouse, InputController inputController, Player player, SpriteBatch spriteBatch, Main main, OrthographicCamera orthographicCamera)
{
/*
foreach (var chunkpair in Chunks.LoadedChunks.Keys.Where(chunkpair => chunkpair.Item3 == layer))
_mouse = mouse;
_inputController = inputController;
_player = player;
_spriteBatch = spriteBatch;
_main = main;
_orthographicCamera = orthographicCamera;
}
private static void DrawWorld(SpriteBatch batch, int layer)
{
batch.draw(
//BlockMaterials.Textures[Chunks.LoadedChunks[chunkpair].getName()],
chunkpair.Item1 << IRestrictions.TileShift,
chunkpair.Item2 << IRestrictions.TileShift
);
foreach (var chunkpair in Chunks.LoadedChunks.Keys.Where(chunkpair => chunkpair.Item3 == layer))
{
batch.Draw(
BlockMaterials.Textures[Chunks.LoadedChunks[chunkpair].Name],
new Rectangle(
chunkpair.Item1 << IRestrictions.TileShift,
chunkpair.Item2 << IRestrictions.TileShift,
IRestrictions.TileSize, IRestrictions.TileSize
),
Color.White
);
}
}
/*
private void mouseCrosshair(SpriteBatch batch)
{
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
Main.cam.unproject(mousePos);
int x = mouse.getSelectedX(mousePos);
int y = mouse.getSelectedY(mousePos);
batch.draw(mouse.getCrosshair(), x, y);
}
*/
public void Draw()
{
//Higher means draws in a lower layer
DrawWorld(_spriteBatch, 0);
_inputController.Draw();
DrawWorld(_spriteBatch, 1);
//mouseCrosshair(batch);
_inputController.PlayerInput(_main,_spriteBatch);
}
/*
private void mouseCrosshair(SpriteBatch batch) {
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
Main.cam.unproject(mousePos);
int x = mouse.getSelectedX(mousePos);
int y = mouse.getSelectedY(mousePos);
batch.draw(mouse.getCrosshair(), x, y);
}
public void render(SpriteBatch batch, float timeSinceLastUpdate) {
//Higher means draws in a lower layer
drawWorld(batch,0);
batch.draw(player.getAnimation().getKeyFrame(timeSinceLastUpdate, true), Player.x, Player.y,TILE_SIZE,TILE_SIZE);
drawWorld(batch,1);
mouseCrosshair(batch);
inputController.handleInput();
batch.setProjectionMatrix(Main.cam.combined);
}
*/
}
}
}