Terrain now only consists of blocks
This commit is contained in:
@ -28,6 +28,9 @@ namespace FluckyGame.Client.Entities
|
|||||||
AnimationLooping = true;
|
AnimationLooping = true;
|
||||||
|
|
||||||
cameraDistance = 200;
|
cameraDistance = 200;
|
||||||
|
|
||||||
|
UpdateY();
|
||||||
|
UpdateWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime gameTime, KeyboardState keyboardState, MouseState mouseState)
|
public override void Update(GameTime gameTime, KeyboardState keyboardState, MouseState mouseState)
|
||||||
@ -98,6 +101,7 @@ namespace FluckyGame.Client.Entities
|
|||||||
AnimationPlaying = false;
|
AnimationPlaying = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateY();
|
||||||
UpdateWorld();
|
UpdateWorld();
|
||||||
|
|
||||||
var test = new Vector3(0, 50, 0);
|
var test = new Vector3(0, 50, 0);
|
||||||
@ -113,5 +117,18 @@ namespace FluckyGame.Client.Entities
|
|||||||
}
|
}
|
||||||
Game1.currentInstance.terrain.View = view;
|
Game1.currentInstance.terrain.View = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateY()
|
||||||
|
{
|
||||||
|
var x = (int)Math.Round(Position.X / 10);
|
||||||
|
var z = (int)Math.Round(Position.Z / 10);
|
||||||
|
|
||||||
|
if (x < 0 || z < 0 || x >= Game1.currentInstance.world.GetLength(0) || z >= Game1.currentInstance.world.GetLength(1))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var y = Game1.currentInstance.world[x, z];
|
||||||
|
|
||||||
|
Position.Y = y - 25;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ namespace FluckyGame.Client.Entities
|
|||||||
|
|
||||||
public Matrix View { set { effect.View = value; } }
|
public Matrix View { set { effect.View = value; } }
|
||||||
|
|
||||||
public TerrainEntity(int width, int height, GraphicsDevice graphicsDevice, Matrix projection) :
|
public TerrainEntity(int[,] world, GraphicsDevice graphicsDevice, Matrix projection) :
|
||||||
base()
|
base()
|
||||||
{
|
{
|
||||||
this.graphicsDevice = graphicsDevice;
|
this.graphicsDevice = graphicsDevice;
|
||||||
@ -21,30 +22,82 @@ namespace FluckyGame.Client.Entities
|
|||||||
effect.Projection = projection;
|
effect.Projection = projection;
|
||||||
effect.VertexColorEnabled = true;
|
effect.VertexColorEnabled = true;
|
||||||
|
|
||||||
vertices = new VertexPositionColor[width * height];
|
const int size = 10;
|
||||||
indices = new short[(width - 1) * (height - 1) * 6];
|
|
||||||
int currentIndex = 0;
|
var verticesList = new List<VertexPositionColor>();
|
||||||
for (int x = 0; x < width; x++)
|
var indicesList = new List<short>();
|
||||||
for(int z = 0; z < height; z++)
|
|
||||||
|
for (int z = 0; z < 100; z++)
|
||||||
|
for (int x = 0; x < 100; x++)
|
||||||
{
|
{
|
||||||
vertices[x + z * width].Position = new Vector3(-8000 + (16000 / width * x), (float)Game1.random.NextDouble() * 50 - 50, -8000 + (16000 / height * z));
|
float y = world[x, z] - 25;
|
||||||
vertices[x + z * width].Color = new Color(Game1.random.Next(0, 255), Game1.random.Next(0, 255), Game1.random.Next(0, 255));
|
|
||||||
|
|
||||||
if(x < width - 1 && z < height - 1)
|
short index00 = (short)verticesList.Count;
|
||||||
{
|
verticesList.Add(new VertexPositionColor(new Vector3(x * size, y, z * size), Color.Red));
|
||||||
short downLeft = (short)(x + z * width);
|
short index10 = (short)verticesList.Count;
|
||||||
short downRight = (short)((x + 1) + z * width);
|
verticesList.Add(new VertexPositionColor(new Vector3((x + 1) * size, y, z * size), Color.Green));
|
||||||
short upLeft = (short)(x + (z + 1) * width);
|
short index01 = (short)verticesList.Count;
|
||||||
short upRight = (short)((x + 1) + (z + 1) * width);
|
verticesList.Add(new VertexPositionColor(new Vector3(x * size, y, (z + 1) * size), Color.Blue));
|
||||||
|
short index11 = (short)verticesList.Count;
|
||||||
|
verticesList.Add(new VertexPositionColor(new Vector3((x + 1) * size, y, (z + 1) * size), Color.Red));
|
||||||
|
|
||||||
indices[currentIndex++] = downRight;
|
short indexBottom00 = (short)verticesList.Count;
|
||||||
indices[currentIndex++] = upLeft;
|
verticesList.Add(new VertexPositionColor(new Vector3(x * size, -100, z * size), Color.Red));
|
||||||
indices[currentIndex++] = downLeft;
|
short indexBottom10 = (short)verticesList.Count;
|
||||||
indices[currentIndex++] = upRight;
|
verticesList.Add(new VertexPositionColor(new Vector3((x + 1) * size, -100, z * size), Color.Green));
|
||||||
indices[currentIndex++] = upLeft;
|
short indexBottom01 = (short)verticesList.Count;
|
||||||
indices[currentIndex++] = downRight;
|
verticesList.Add(new VertexPositionColor(new Vector3(x * size, -100, (z + 1) * size), Color.Blue));
|
||||||
}
|
short indexBottom11 = (short)verticesList.Count;
|
||||||
|
verticesList.Add(new VertexPositionColor(new Vector3((x + 1) * size, -100, (z + 1) * size), Color.Red));
|
||||||
|
|
||||||
|
//Top
|
||||||
|
indicesList.Add(index11);
|
||||||
|
indicesList.Add(index01);
|
||||||
|
indicesList.Add(index00);
|
||||||
|
|
||||||
|
indicesList.Add(index10);
|
||||||
|
indicesList.Add(index11);
|
||||||
|
indicesList.Add(index00);
|
||||||
|
|
||||||
|
//North
|
||||||
|
indicesList.Add(index00);
|
||||||
|
indicesList.Add(index01);
|
||||||
|
indicesList.Add(indexBottom01);
|
||||||
|
|
||||||
|
indicesList.Add(index00);
|
||||||
|
indicesList.Add(indexBottom01);
|
||||||
|
indicesList.Add(indexBottom00);
|
||||||
|
|
||||||
|
//West
|
||||||
|
indicesList.Add(index10);
|
||||||
|
indicesList.Add(index00);
|
||||||
|
indicesList.Add(indexBottom00);
|
||||||
|
|
||||||
|
indicesList.Add(index10);
|
||||||
|
indicesList.Add(indexBottom00);
|
||||||
|
indicesList.Add(indexBottom10);
|
||||||
|
|
||||||
|
//South
|
||||||
|
indicesList.Add(index11);
|
||||||
|
indicesList.Add(index10);
|
||||||
|
indicesList.Add(indexBottom10);
|
||||||
|
|
||||||
|
indicesList.Add(index11);
|
||||||
|
indicesList.Add(indexBottom10);
|
||||||
|
indicesList.Add(indexBottom11);
|
||||||
|
|
||||||
|
//East
|
||||||
|
indicesList.Add(index01);
|
||||||
|
indicesList.Add(index11);
|
||||||
|
indicesList.Add(indexBottom11);
|
||||||
|
|
||||||
|
indicesList.Add(index01);
|
||||||
|
indicesList.Add(indexBottom11);
|
||||||
|
indicesList.Add(indexBottom01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vertices = verticesList.ToArray();
|
||||||
|
indices = indicesList.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(GameTime gameTime)
|
public override void Draw(GameTime gameTime)
|
||||||
|
@ -42,6 +42,8 @@ namespace FluckyGame.Client
|
|||||||
private Queue<Packet> queue;
|
private Queue<Packet> queue;
|
||||||
private bool exiting;
|
private bool exiting;
|
||||||
|
|
||||||
|
public int[,] world;
|
||||||
|
|
||||||
static Game1()
|
static Game1()
|
||||||
{
|
{
|
||||||
random = new Random();
|
random = new Random();
|
||||||
@ -120,10 +122,15 @@ namespace FluckyGame.Client
|
|||||||
effect.TextureEnabled = true;
|
effect.TextureEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
world = new int[200, 200];
|
||||||
|
for (int y = 0; y < world.GetLength(1); y++)
|
||||||
|
for (int x = 0; x < world.GetLength(0); x++)
|
||||||
|
world[x, y] = 25 + (int)((float)Math.Sin((double)x / 10) * (float)Math.Sin((double)y / 10) * 25f);
|
||||||
|
|
||||||
entities = new List<Entity>()
|
entities = new List<Entity>()
|
||||||
{
|
{
|
||||||
(player = new PlayerEntity()),
|
(player = new PlayerEntity()),
|
||||||
(terrain = new TerrainEntity(200, 200, GraphicsDevice, projection))
|
(terrain = new TerrainEntity(world, GraphicsDevice, projection))
|
||||||
};
|
};
|
||||||
|
|
||||||
entitiesById = new Dictionary<string, ModelEntity>();
|
entitiesById = new Dictionary<string, ModelEntity>();
|
||||||
|
Reference in New Issue
Block a user