public void AddDrawablePath(List <MovementAlgorithmTile> ListPoint) { for (int P = 1; P < ListPoint.Count; P++) { MovementAlgorithmTile ActivePoint = ListPoint[P]; MovementAlgorithmTile Previous = ListPoint[P - 1]; MovementAlgorithmTile Next = null; if (P + 1 < ListPoint.Count) { Next = ListPoint[P + 1]; } int X = (int)ActivePoint.Position.X; int Y = (int)ActivePoint.Position.Y; float Z = Map.LayerManager.ListLayer[ActivePoint.LayerIndex].ArrayTerrain[X, Y].Position.Z * 32 + (ActivePoint.LayerIndex * 32) + 0.1f; Map2D GroundLayer = Map.LayerManager.ListLayer[ActivePoint.LayerIndex].LayerGrid; DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y); Terrain3D ActiveTerrain3D = ActiveTerrain.Terrain3DInfo; ListDrawableArrowPerColor.Add(ActiveTerrain3D.CreateTile3D(0, GetCursorTextureOffset(Previous, ActivePoint, Next), X * Map.TileSize.X, Y * Map.TileSize.Y, Z, Z + 0.15f, Map.TileSize, new List <Texture2D>() { Map.sprCursorPath }, Z, Z, Z, Z, 0)[0]); } }
public void Update(GameTime gameTime) { UpdateCamera(); if (Map.CursorPositionVisible.X < 0) { Camera.CameraHeight = 600; Camera.CameraDistance = 500; Camera.SetTarget(new Vector3(Map.TileSize.X * Map.MapSize.X / 2, Map.CursorPosition.Z * 32, Map.TileSize.Y * Map.MapSize.Y / 2)); Camera.Update(gameTime); return; } Camera.CameraHeight = 400; Camera.CameraDistance = 300; int X = (int)Map.CursorPositionVisible.X; int Y = (int)Map.CursorPositionVisible.Y; float Z = Map.LayerManager.ListLayer[(int)Map.CursorPosition.Z].ArrayTerrain[X, Y].Position.Z * 32 + (Map.CursorPosition.Z * 32) + 0.3f; Map2D GroundLayer = Map.LayerManager.ListLayer[(int)Map.CursorPosition.Z].LayerGrid; DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y); Terrain3D ActiveTerrain3D = ActiveTerrain.Terrain3DInfo; Cursor = ActiveTerrain3D.CreateTile3D(0, Point.Zero, X * Map.TileSize.X, Y * Map.TileSize.Y, Z, Map.CursorPosition.Z * 32 + 0.3f, Map.TileSize, new List <Texture2D>() { sprCursor }, Z, Z, Z, Z, 0)[0]; Camera.SetTarget(new Vector3(Map.TileSize.X * Map.CursorPositionVisible.X, Map.CursorPosition.Z * 32, Map.TileSize.Y * Map.CursorPositionVisible.Y)); Camera.Update(gameTime); DicDrawablePointPerColor.Clear(); ListDrawableArrowPerColor.Clear(); }
protected virtual void CreateMap(SorcererStreetMap Map) { DicTile3D.Clear(); if (Map.ListTileSet.Count == 0) { return; } for (int X = Map.MapSize.X - 1; X >= 0; --X) { for (int Y = Map.MapSize.Y - 1; Y >= 0; --Y) { float Z = Grid.ArrayTerrain[X, Y].Position.Z; Vector3[] ArrayVertexPosition = new Vector3[4]; ArrayVertexPosition[0] = new Vector3(X * Map.TileSize.X, Z, Y * Map.TileSize.Y); ArrayVertexPosition[1] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y); ArrayVertexPosition[2] = new Vector3(X * Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); ArrayVertexPosition[3] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y); Texture2D ActiveTileset = Map.ListTileSet[ActiveTerrain.TilesetIndex]; if (!DicTile3D.ContainsKey(ActiveTileset)) { DicTile3D.Add(ActiveTileset, new List <Tile3D>()); } DicTile3D[ActiveTileset].Add(CreateTile3D(Map, ArrayVertexPosition, ActiveTerrain.Origin.X, ActiveTerrain.Origin.Y, X, Y, ActiveTileset.Width, ActiveTileset.Height, Radius)); //Create slope right if (X + 1 < Map.MapSize.X) { float ZRight = Grid.ArrayTerrain[X + 1, Y].Position.Z; if (Z != ZRight) { Vector3[] ArrayVertexPositionRight = new Vector3[4]; ArrayVertexPositionRight[0] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y); ArrayVertexPositionRight[2] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); ArrayVertexPositionRight[1] = new Vector3((X + 1) * Map.TileSize.X, ZRight, Y * Map.TileSize.Y); ArrayVertexPositionRight[3] = new Vector3((X + 1) * Map.TileSize.X, ZRight, Y * Map.TileSize.Y + Map.TileSize.Y); DicTile3D[ActiveTileset].Add(CreateTile3D(Map, ArrayVertexPositionRight, ActiveTerrain.Origin.X, ActiveTerrain.Origin.Y, X, Y, ActiveTileset.Width, ActiveTileset.Height, Radius)); } } //Create slope down if (Y + 1 < Map.MapSize.Y) { float ZDown = Grid.ArrayTerrain[X, Y + 1].Position.Z; if (Z != ZDown) { Vector3[] ArrayVertexPositionDown = new Vector3[4]; ArrayVertexPositionDown[0] = new Vector3(X * Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); ArrayVertexPositionDown[1] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); ArrayVertexPositionDown[2] = new Vector3(X * Map.TileSize.X, ZDown, (Y + 1) * Map.TileSize.Y); ArrayVertexPositionDown[3] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, ZDown, (Y + 1) * Map.TileSize.Y); DicTile3D[ActiveTileset].Add(CreateTile3D(Map, ArrayVertexPositionDown, ActiveTerrain.Origin.X, ActiveTerrain.Origin.Y, X, Y, ActiveTileset.Width, ActiveTileset.Height, Radius)); } } } } }
protected virtual void CreateMap(DeathmatchMap Map) { DicTile3D.Clear(); for (int X = Map.MapSize.X - 1; X >= 0; --X) { for (int Y = Map.MapSize.Y - 1; Y >= 0; --Y) { Map.GetTerrain(X, Y, Map.ActiveLayerIndex).Position.Z = Random.Next(2) * 32; float Z = Map.GetTerrain(X, Y, Map.ActiveLayerIndex).Position.Z; Vector3[] ArrayVertexPosition = new Vector3[4]; ArrayVertexPosition[0] = new Vector3(X * Map.TileSize.X, Z, Y * Map.TileSize.Y); ArrayVertexPosition[1] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y); ArrayVertexPosition[2] = new Vector3(X * Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); ArrayVertexPosition[3] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); Map2D GroundLayer = Map.ListLayer[0].OriginalLayerGrid; DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y); Texture2D ActiveTileset = Map.ListTileSet[ActiveTerrain.Tileset]; if (!DicTile3D.ContainsKey(ActiveTileset)) { DicTile3D.Add(ActiveTileset, new List <Tile3D>()); } DicTile3D[ActiveTileset].Add(CreateTile3D(Map, ArrayVertexPosition, ActiveTerrain.Origin.X, ActiveTerrain.Origin.Y, X, Y, ActiveTileset.Width, ActiveTileset.Height, Radius)); //Create slope right if (X + 1 < Map.MapSize.X) { float ZRight = Map.GetTerrain(X + 1, Y, Map.ActiveLayerIndex).Position.Z; if (Z != ZRight) { Vector3[] ArrayVertexPositionRight = new Vector3[4]; ArrayVertexPositionRight[0] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y); ArrayVertexPositionRight[2] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); ArrayVertexPositionRight[1] = new Vector3((X + 1) * Map.TileSize.X, ZRight, Y * Map.TileSize.Y); ArrayVertexPositionRight[3] = new Vector3((X + 1) * Map.TileSize.X, ZRight, Y * Map.TileSize.Y + Map.TileSize.Y); DicTile3D[ActiveTileset].Add(CreateTile3D(Map, ArrayVertexPositionRight, ActiveTerrain.Origin.X, ActiveTerrain.Origin.Y, X, Y, ActiveTileset.Width, ActiveTileset.Height, Radius)); } } //Create slope down if (Y + 1 < Map.MapSize.Y) { float ZDown = Map.GetTerrain(X, Y + 1, Map.ActiveLayerIndex).Position.Z; if (Z != ZDown) { Vector3[] ArrayVertexPositionDown = new Vector3[4]; ArrayVertexPositionDown[0] = new Vector3(X * Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); ArrayVertexPositionDown[1] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, Z, Y * Map.TileSize.Y + Map.TileSize.Y); ArrayVertexPositionDown[2] = new Vector3(X * Map.TileSize.X, ZDown, (Y + 1) * Map.TileSize.Y); ArrayVertexPositionDown[3] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, ZDown, (Y + 1) * Map.TileSize.Y); DicTile3D[ActiveTileset].Add(CreateTile3D(Map, ArrayVertexPositionDown, ActiveTerrain.Origin.X, ActiveTerrain.Origin.Y, X, Y, ActiveTileset.Width, ActiveTileset.Height, Radius)); } } } } }
protected void CreateMap(DeathmatchMap Map, MapLayer Owner, int LayerIndex) { Map2D GroundLayer = Owner.LayerGrid; for (int X = Map.MapSize.X - 1; X >= 0; --X) { for (int Y = Map.MapSize.Y - 1; Y >= 0; --Y) { DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y); Terrain3D ActiveTerrain3D = ActiveTerrain.Terrain3DInfo; if (ActiveTerrain3D.TerrainStyle == Terrain3D.TerrainStyles.Invisible) { continue; } float Z = Owner.ArrayTerrain[X, Y].Position.Z * 32 + (LayerIndex * 32); float ZFront = Z; float ZBack = Z; float ZRight = Z; float ZLeft = Z; if (Y + 1 < Map.MapSize.Y) { ZFront = Owner.ArrayTerrain[X, Y + 1].Position.Z * 32 + (LayerIndex * 32); } if (Y - 1 >= 0) { ZBack = Owner.ArrayTerrain[X, Y - 1].Position.Z * 32 + (LayerIndex * 32); } if (X - 1 >= 0) { ZLeft = Owner.ArrayTerrain[X - 1, Y].Position.Z * 32 + (LayerIndex * 32); } if (X + 1 < Map.MapSize.X) { ZRight = Owner.ArrayTerrain[X + 1, Y].Position.Z * 32 + (LayerIndex * 32); } List <Tile3D> ListNew3DTile = ActiveTerrain3D.CreateTile3D(ActiveTerrain.TilesetIndex, ActiveTerrain.Origin.Location, X * Map.TileSize.X, Y * Map.TileSize.Y, Z, LayerIndex * 32, Map.TileSize, Map.ListTileSet, ZFront, ZBack, ZLeft, ZRight, 0); foreach (Tile3D ActiveTile in ListNew3DTile) { if (!DicTile3DByTileset.ContainsKey(ActiveTile.TilesetIndex)) { DicTile3DByTileset.Add(ActiveTile.TilesetIndex, new Tile3DHolder(effect, Map.ListTileSet[ActiveTile.TilesetIndex])); } DicTile3DByTileset[ActiveTile.TilesetIndex].AddTile(ActiveTile); } } } for (int L = 0; L < Owner.ListSubLayer.Count; L++) { CreateMap(Map, Owner.ListSubLayer[L], LayerIndex); } }
private Tile3D CreateTile(DeathmatchMap Map, Texture2D ActiveTileset, Vector3[] ArrayVertexPosition, int X, int Y) { //Add and remove a half pixel offset to avoid texture bleeding. VertexPositionColorTexture[] ArrayVertex = new VertexPositionColorTexture[4]; Map2D GroundLayer = Map.ListLayer[0].OriginalLayerGrid; DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y); float UVXValue = ActiveTerrain.Origin.X + 0.5f; float UVYValue = ActiveTerrain.Origin.Y + 0.5f; Vector2 TextureSize = new Vector2(ActiveTileset.Width, ActiveTileset.Height); ArrayVertex[0] = new VertexPositionColorTexture(); ArrayVertex[0].Position = ArrayVertexPosition[0]; ArrayVertex[0].TextureCoordinate = new Vector2(UVXValue / TextureSize.X, UVYValue / TextureSize.Y); ArrayVertex[0].Color = Color.White; UVXValue = ActiveTerrain.Origin.X + Map.TileSize.X - 0.5f; UVYValue = ActiveTerrain.Origin.Y + 0.5f; ArrayVertex[1] = new VertexPositionColorTexture(); ArrayVertex[1].Position = ArrayVertexPosition[1]; ArrayVertex[1].TextureCoordinate = new Vector2(UVXValue / TextureSize.X, UVYValue / TextureSize.Y); ArrayVertex[1].Color = Color.White; UVXValue = ActiveTerrain.Origin.X + 0.5f; UVYValue = ActiveTerrain.Origin.Y + Map.TileSize.Y - 0.5f; ArrayVertex[2] = new VertexPositionColorTexture(); ArrayVertex[2].Position = ArrayVertexPosition[2]; ArrayVertex[2].TextureCoordinate = new Vector2(UVXValue / TextureSize.X, UVYValue / TextureSize.Y); ArrayVertex[2].Color = Color.White; UVXValue = ActiveTerrain.Origin.X + Map.TileSize.X - 0.5f; UVYValue = ActiveTerrain.Origin.Y + Map.TileSize.Y - 0.5f; ArrayVertex[3] = new VertexPositionColorTexture(); ArrayVertex[3].Position = ArrayVertexPosition[3]; ArrayVertex[3].TextureCoordinate = new Vector2(UVXValue / TextureSize.X, UVYValue / TextureSize.Y); ArrayVertex[3].Color = Color.White; short[] ArrayIndex = new short[6]; ArrayIndex[0] = 0; ArrayIndex[1] = 1; ArrayIndex[2] = 3; ArrayIndex[3] = 0; ArrayIndex[4] = 3; ArrayIndex[5] = 2; Tile3D NewTile = new Tile3D(ArrayVertex, ArrayIndex); return(NewTile); }
protected override void CreateMap(DeathmatchMap Map) { DicTile3D.Clear(); for (int X = Map.MapSize.X - 1; X >= 0; --X) { for (int Y = Map.MapSize.Y - 1; Y >= 0; --Y) { Vector3[] ArrayVertexPosition = new Vector3[4]; ArrayVertexPosition[0] = new Vector3(X * Map.TileSize.X, 0, Y * Map.TileSize.Y); ArrayVertexPosition[1] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, 0, Y * Map.TileSize.Y); ArrayVertexPosition[2] = new Vector3(X * Map.TileSize.X, 0, Y * Map.TileSize.Y + Map.TileSize.Y); ArrayVertexPosition[3] = new Vector3(X * Map.TileSize.X + Map.TileSize.X, 0, Y * Map.TileSize.Y + Map.TileSize.Y); Vector3[] ArrayTransformedVertexPosition = new Vector3[ArrayVertexPosition.Length]; Matrix TranslationToOriginMatrix = Matrix.CreateTranslation(-Radius, Radius, -Radius); Vector3.Transform(ArrayVertexPosition, ref TranslationToOriginMatrix, ArrayTransformedVertexPosition); for (int V = ArrayVertexPosition.Length - 1; V >= 0; --V) { ArrayVertexPosition[V] = ArrayTransformedVertexPosition[V]; } Map2D GroundLayer = Map.ListLayer[0].OriginalLayerGrid; DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y); Texture2D ActiveTileset = Map.ListTileSet[ActiveTerrain.Tileset]; if (!DicTile3D.ContainsKey(ActiveTileset)) { DicTile3D.Add(ActiveTileset, new List <Tile3D>()); } Tile3D NewTile = CreateTile(Map, ActiveTileset, ArrayVertexPosition, X, Y); if (Spherical) { MoveToSphericalCoordinates(NewTile, Radius); CreateSphericalElevation(Map, ActiveTileset, NewTile, X, Y); } else { CreateFlatElevation(Map, ActiveTileset, NewTile, X, Y); } CreateCubicTile(Map, ActiveTileset, NewTile); } } }
public void AddDrawablePoints(List <MovementAlgorithmTile> ListPoint, Color PointColor) { List <Tile3D> ListDrawablePoint3D = new List <Tile3D>(ListPoint.Count); foreach (MovementAlgorithmTile ActivePoint in ListPoint) { int X = (int)ActivePoint.Position.X; int Y = (int)ActivePoint.Position.Y; float Z = Map.LayerManager.ListLayer[ActivePoint.LayerIndex].ArrayTerrain[X, Y].Position.Z * 32 + (ActivePoint.LayerIndex * 32) + 0.1f; Map2D GroundLayer = Map.LayerManager.ListLayer[ActivePoint.LayerIndex].LayerGrid; DrawableTile ActiveTerrain = GroundLayer.GetTile(X, Y); Terrain3D ActiveTerrain3D = ActiveTerrain.Terrain3DInfo; ListDrawablePoint3D.Add(ActiveTerrain3D.CreateTile3D(0, Point.Zero, X * Map.TileSize.X, Y * Map.TileSize.Y, Z, Z + 0.1f, Map.TileSize, new List <Texture2D>() { sprCursor }, Z, Z, Z, Z, 0)[0]); } DicDrawablePointPerColor.Add(PointColor, ListDrawablePoint3D); }
public Map3DDrawable(DeathmatchMap Map, GraphicsDevice g) { this.Map = Map; sprCursor = Map.sprCursor; Camera = new DefaultCamera(g); effect = Map.Content.Load <Effect>("Shaders/Default Shader 3D"); PolygonEffect = new BasicEffect(g); PolygonEffect.TextureEnabled = true; PolygonEffect.EnableDefaultLighting(); float aspectRatio = g.Viewport.Width / (float)g.Viewport.Height; Matrix Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, 1, 10000); PolygonEffect.Projection = Projection; PolygonEffect.World = Matrix.Identity; PolygonEffect.View = Matrix.Identity; // Key light. effect.Parameters["DirLight0Direction"].SetValue(new Vector3(-0.5265408f, -0.5735765f, -0.6275069f)); effect.Parameters["DirLight0DiffuseColor"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f)); effect.Parameters["DirLight0SpecularColor"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f)); // Fill light. effect.Parameters["DirLight1Direction"].SetValue(new Vector3(0.7198464f, 0.3420201f, 0.6040227f)); effect.Parameters["DirLight1DiffuseColor"].SetValue(new Vector3(0.9647059f, 0.7607844f, 0.4078432f)); effect.Parameters["DirLight1SpecularColor"].SetValue(Vector3.Zero); // Back light. effect.Parameters["DirLight2Direction"].SetValue(new Vector3(0.4545195f, -0.7660444f, 0.4545195f)); effect.Parameters["DirLight2DiffuseColor"].SetValue(new Vector3(0.3231373f, 0.3607844f, 0.3937255f)); effect.Parameters["DirLight2SpecularColor"].SetValue(new Vector3(0.3231373f, 0.3607844f, 0.3937255f)); Vector3 diffuseColor = Vector3.One; Vector3 emissiveColor = Vector3.Zero; Vector3 ambientLightColor = new Vector3(0.05333332f, 0.09882354f, 0.1819608f); Vector4 diffuse = new Vector4(); Vector3 emissive = new Vector3(); float alpha = 1; diffuse.X = diffuseColor.X * alpha; diffuse.Y = diffuseColor.Y * alpha; diffuse.Z = diffuseColor.Z * alpha; diffuse.W = alpha; emissive.X = (emissiveColor.X + ambientLightColor.X * diffuseColor.X) * alpha; emissive.Y = (emissiveColor.Y + ambientLightColor.Y * diffuseColor.Y) * alpha; emissive.Z = (emissiveColor.Z + ambientLightColor.Z * diffuseColor.Z) * alpha; effect.Parameters["DiffuseColor"].SetValue(diffuse); effect.Parameters["EmissiveColor"].SetValue(emissive); effect.Parameters["SpecularColor"].SetValue(Vector3.One); effect.Parameters["SpecularPower"].SetValue(64); DicDrawablePointPerColor = new Dictionary <Color, List <Tile3D> >(); DicTile3DByTileset = new Dictionary <int, Tile3DHolder>(); ListDrawableArrowPerColor = new List <Tile3D>(); for (int L = 0; L < Map.LayerManager.ListLayer.Count; L++) { CreateMap(Map, Map.LayerManager.ListLayer[L], L); } foreach (KeyValuePair <int, Tile3DHolder> ActiveTileSet in DicTile3DByTileset) { ActiveTileSet.Value.Finish(GameScreen.GraphicsDevice); } float Z = Map.LayerManager.ListLayer[0].ArrayTerrain[0, 0].Position.Z * 32; Map2D GroundLayer = Map.LayerManager.ListLayer[0].LayerGrid; DrawableTile ActiveTerrain = GroundLayer.GetTile(0, 0); Terrain3D ActiveTerrain3D = ActiveTerrain.Terrain3DInfo; Cursor = ActiveTerrain3D.CreateTile3D(0, Point.Zero, 0, 0, Z, 0, Map.TileSize, new List <Texture2D>() { sprCursor }, Z, Z, Z, Z, 0)[0]; }