public void ReparentNode(Tile tile) { Gem = tile.Gem; Node = tile.Node; HasNode = true; Destroyed = false; //reset original node tile.Node = new TileScene(); tile.Reset(); }
public TileSceneRenderData(ITagContainer diContainer, TileScene scene, DeviceBuffer counterBuffer) { this.diContainer = diContainer; this.scene = scene; locationBuffer = diContainer.GetTag <LocationBuffer>(); var textureLoader = diContainer.GetTag <IAssetLoader <Texture> >(); var camera = diContainer.GetTag <OrthoCamera>(); var worldLocationRange = locationBuffer.Add(new Location()); var locationRanges = new List <DeviceBufferRange>(scene.Objects.Count + 1) { worldLocationRange }; this.locationRanges = locationRanges; worldMaterials = scene.WorldBuffers.Materials.Select(rwMaterial => { IMapMaterial material; if (rwMaterial.isTextured) { var texMaterial = new MapStandardMaterial(diContainer); (texMaterial.MainTexture.Texture, texMaterial.Sampler.Sampler) = textureLoader.LoadTexture(TextureBasePaths, rwMaterial); material = texMaterial; } else { material = new MapUntexturedMaterial(diContainer); } material.Projection.BufferRange = camera.ProjectionRange; material.View.BufferRange = camera.ViewRange; material.World.Value = Matrix4x4.Identity; material.Uniforms.Ref = ModelStandardMaterialUniforms.Default; material.PixelCounter.Buffer = counterBuffer; AddDisposable(material); return(material as IMaterial); }).ToList() !; objectMaterials = scene.Objects.Select(obj => obj.ClumpBuffers.SubMeshes.Select(subMesh => { var objectLocation = new Location(); objectLocation.LocalPosition = obj.Position; objectLocation.LocalRotation = obj.Rotation; var objectLocationRange = locationBuffer.Add(objectLocation); locationRanges.Add(objectLocationRange); var rwMaterial = subMesh.Material; IMapMaterial material; if (rwMaterial.isTextured) { var texMaterial = new MapStandardMaterial(diContainer); (texMaterial.MainTexture.Texture, texMaterial.Sampler.Sampler) = textureLoader.LoadTexture(TextureBasePaths, rwMaterial); material = texMaterial; } else { material = new MapUntexturedMaterial(diContainer); } material.Projection.BufferRange = camera.ProjectionRange; material.View.BufferRange = camera.ViewRange; material.World.BufferRange = objectLocationRange; material.Uniforms.Ref = ModelStandardMaterialUniforms.Default; material.Uniforms.Ref.vertexColorFactor = 0.0f; material.Uniforms.Ref.tint = rwMaterial.color.ToFColor() * obj.Tint; material.PixelCounter.Buffer = counterBuffer; AddDisposable(material); return(material as IMaterial); }).ToList() as IReadOnlyList <IMaterial>).ToList(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); camera = new Camera2D(new Vector2(0f, 0f), new Vector2(1f), new Vector2(3f)); this.Services.AddService(typeof(SpriteBatch), spriteBatch); this.Services.AddService(typeof(Camera2D), camera); texture1 = this.Content.Load<Texture2D>("tex"); TileCatalog cat1 = new TileCatalog(texture1, 15, 15); Random rand = new Random(DateTime.Now.Millisecond); TileMap map1 = new TileMap(100, 100); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { map1.SetTile(i, j, new Tile(rand.Next(1, cat1.TilePositions.Count))); } } TileLayer layer1 = new TileLayer(cat1, map1, 0.5f, false, new Vector2(0, 0), new Vector2(1f, 1f), new Vector2(3f), false, LayerMovementDirection.None); texture2 = this.Content.Load<Texture2D>("tiles2"); TileCatalog cat2 = new TileCatalog(texture2, 48, 48); TileMap map2 = new TileMap(10, 500); for (int i = 0; i < 10; i++) { for (int j = 0; j < 500; j++) { map2.SetTile(i, j, new Tile(rand.Next(1, cat2.TilePositions.Count))); } } TileLayer layer2 = new TileLayer(cat2, map2, 1.0f, false, new Vector2(0, 0), new Vector2(1f, 1f), new Vector2(3f), true, LayerMovementDirection.Up); scene = new TileScene(); scene.AddLayer(layer2); scene.AddLayer(layer1); TileComponent component = new TileComponent(this, scene, baseScreenSize, resultionIndependent); this.Components.Add(component); TextureLayer tLayer1 = new TextureLayer(this.texture1, 1f, false, new Vector2(20f), Vector2.One, new Vector2(1.5f,1.5f), true, Anchor.LowerRight); TextureLayer tLayer2 = new TextureLayer(this.texture2, 0.5f, false, new Vector2(10f), Vector2.One, new Vector2(5f), true, Anchor.LowerLeft); TextureScene tScene = new TextureScene(); tScene.AddLayer(tLayer1); tScene.AddLayer(tLayer2); TextureComponent tComponent = new TextureComponent(this, tScene, baseScreenSize, resultionIndependent); this.Components.Add(tComponent); texture1 = this.Content.Load<Texture2D>("megax"); SpriteCatalog scatalog = new SpriteCatalog(texture1, 36, 42); SpriteSequence[] spriteSecuences = new SpriteSequence[2]; SpriteSequence spriteSecuence1 = new SpriteSequence(7, 0); spriteSecuence1.StepTime = 400; spriteSecuence1.SetFrame(0,new SpriteFrame(1)); spriteSecuence1.SetFrame(1, new SpriteFrame(1)); spriteSecuence1.SetFrame(2, new SpriteFrame(1)); spriteSecuence1.SetFrame(3, new SpriteFrame(1)); spriteSecuence1.SetFrame(4, new SpriteFrame(2)); spriteSecuence1.SetFrame(5, new SpriteFrame(3)); spriteSecuence1.SetFrame(6, new SpriteFrame(1)); spriteSecuences[0] = spriteSecuence1; SpriteSequence spriteSecuence2 = new SpriteSequence(10, 0); spriteSecuence2.StepTime = 90; spriteSecuence2.SetFrame(0, new SpriteFrame(5)); spriteSecuence2.SetFrame(1, new SpriteFrame(6)); spriteSecuence2.SetFrame(2, new SpriteFrame(7)); spriteSecuence2.SetFrame(3, new SpriteFrame(8)); spriteSecuence2.SetFrame(4, new SpriteFrame(9)); spriteSecuence2.SetFrame(5, new SpriteFrame(10)); spriteSecuence2.SetFrame(6, new SpriteFrame(11)); spriteSecuence2.SetFrame(7, new SpriteFrame(12)); spriteSecuence2.SetFrame(8, new SpriteFrame(13)); spriteSecuence2.SetFrame(9, new SpriteFrame(14)); spriteSecuences[1] = spriteSecuence2; SpriteLayer spLayer = new SpriteLayer(scatalog, spriteSecuences, 1.0f, true, new Vector2(10f), Vector2.One, Vector2.Zero, SpriteEffects.None, true, Anchor.None); spLayer.CurrentSequence = 2; SpriteScene spScene = new SpriteScene(); spScene.AddLayer(spLayer); SpriteComponent spComponent = new SpriteComponent(this, spScene, baseScreenSize, resultionIndependent); this.Components.Add(spComponent); }