private void SetupTile(int i, int j, TileType type) { Tile tile = new Tile { Y = i * BlockHeight, X = j * BlockWidth, Size = new SKSize(BlockWidth, BlockHeight), Type = type }; switch (type) { case TileType.End: EndPoint = tile; break; case TileType.Player: PlayerTile = new Player() { X = i * BlockHeight + 10, Y = j * BlockWidth + 10, }; break; case TileType.None: break; default: TileElements.Add(tile); break; } }
private void RecalculateTitlePaths() { for (int i = 0; i < TileElements.Length; i += 6) { VertexPosTexNormal[] quadElements = TileElements.Skip(i).Take(6).ToArray(); int[] pattern = { quadElements[0].Taken, (quadElements[1].Taken == 0? quadElements[4].Taken: quadElements[1].Taken), (quadElements[2].Taken == 0 ? quadElements[3].Taken : quadElements[2].Taken), quadElements[5].Taken }; TileElement stg1 = TileSheetData.TileElements.Where(x => x.Groups.Any(y => y.Pattern.SequenceEqual(pattern))).FirstOrDefault(); if (stg1 != null) { ElementsGroup texture2Put = stg1.Groups.Where(x => x.Pattern.SequenceEqual(pattern)).FirstOrDefault(); if (texture2Put != null) { int value; using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) { byte[] randomNumber = new byte[4];//4 for int32 rng.GetBytes(randomNumber); value = BitConverter.ToInt32(randomNumber, 0); } int indexRand = new Random(value).Next((texture2Put.Positions.Count <= 1 ? 1 : texture2Put.Positions.Count)); float uvX = (float)texture2Put.Positions[indexRand].X / (ContentContainer.GetObjectFromContainer <Texture2D>(TileSheetData.Name).Width); float uvY = (float)texture2Put.Positions[indexRand].Y / (ContentContainer.GetObjectFromContainer <Texture2D>(TileSheetData.Name).Height); float uvX2 = ((float)texture2Put.Positions[indexRand].X / (float)ContentContainer.GetObjectFromContainer <Texture2D>(TileSheetData.Name).Width) + ((float)TileSheetData.TileElementWeight / ContentContainer.GetObjectFromContainer <Texture2D>(TileSheetData.Name).Width); float uvY2 = ((float)texture2Put.Positions[indexRand].Y / (float)ContentContainer.GetObjectFromContainer <Texture2D>(TileSheetData.Name).Height) - ((float)TileSheetData.TileElementHeight / ContentContainer.GetObjectFromContainer <Texture2D>(TileSheetData.Name).Height); VertexPosTexNormal temp = TileElements[i]; temp.texCoord = new Vector2(uvX, uvY); TileElements[i] = temp; temp = TileElements[i + 1]; temp.texCoord = new Vector2(uvX, uvY2); TileElements[i + 1] = temp; temp = TileElements[i + 2]; temp.texCoord = new Vector2(uvX2, uvY); TileElements[i + 2] = temp; temp = TileElements[i + 3]; temp.texCoord = new Vector2(uvX2, uvY); TileElements[i + 3] = temp; temp = TileElements[i + 4]; temp.texCoord = new Vector2(uvX, uvY2); TileElements[i + 4] = temp; temp = TileElements[i + 5]; temp.texCoord = new Vector2(uvX2, uvY2); TileElements[i + 5] = temp; } } } }
public void Draw(GraphicsDevice graphicsDevice, Effect ef) { foreach (EffectPass pass in ef.CurrentTechnique.Passes) { ef.Parameters["xTexture"].SetValue(ContentContainer.GetObjectFromContainer <Texture2D>(TileSheetData.Name)); ef.Parameters["xWorld"].SetValue(Matrix.Identity); pass.Apply(); graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, TileElements.ToArray(), 0, TileElements.Count() / 3, VertexPosTexNormal.VertexDeclaration); } }
public void CheckPlayerTileCollision(ActionType action) { if (StateLevel == StateLevel.Ongoing) { var tile = TileElements.FirstOrDefault(t => PlayerTile.Rect.IntersectsWith(t.Rect)); if (tile != null) { StateLevel = StateLevel.Looser; } } CheckEndCondition(); }