public void SetGrid(Tile[,] newGrid) { for (int i = 0; i < tiles.GetLength(0); i++) for (int j = 0; j < tiles.GetLength(1); j++) { tiles[i, j].Image = newGrid[i, j].Image; } gridPanel.Invalidate(true); gridPanel.Update(); }
public AssetsWindow() { InitializeComponent(); mSelectedTile = new Tile(); GameFiles.CurrentTile = mSelectedTile; mEditorAssetLoader.Load(); List<string> tempList = mEditorAssetLoader.StortedIconFiles; ImageList tempImageList = new ImageList(); for (int loop = 0; loop < tempList.Count; loop++) { tempImageList.Images.Add(Image.FromFile(tempList[loop])); tempImageList.ImageSize = new Size(128, 128); iAssetList.Items.Add(tempList[loop]); iAssetList.Items[loop].BackColor = System.Drawing.Color.White; iAssetList.Items[loop].Name = tempList[loop]; iAssetList.LargeImageList = tempImageList; iAssetList.Items[loop].ImageIndex = loop; } }
public override void Load(string aFilePath) { using (XmlReader xmlReader = XmlReader.Create(aFilePath)) { xmlReader.MoveToContent(); string rawData; string[] organizedData; string[] xData; string[] yData; string[] zData; xmlReader.ReadToFollowing("TileDescription"); int count; xmlReader.ReadToFollowing("Count"); count = xmlReader.ReadElementContentAsInt("Count", ""); xmlReader.ReadToFollowing("Tile"); for (int loop = 0; loop < count; loop++) { xmlReader.ReadStartElement("Tile"); Tile temporaryTile = new Tile(); temporaryTile.FilePathToModel = xmlReader.ReadElementContentAsString("Model", ""); temporaryTile.FilePathToGraphic = xmlReader.ReadElementContentAsString("Graphic", ""); rawData = xmlReader.ReadElementContentAsString("Position", ""); organizedData = rawData.Split(' '); xData = organizedData[0].Split(':'); yData = organizedData[1].Split(':'); zData = organizedData[2].Split(':'); zData[1] = zData[1].TrimEnd(); zData[1] = zData[1].Replace('}', ' '); temporaryTile.WorldPosition = new Vector3((float)Convert.ToDouble(xData[1]), (float)Convert.ToDouble(yData[1]), (float)Convert.ToDouble(zData[1])); rawData = xmlReader.ReadElementContentAsString("IsCollidable", ""); if (rawData == "True") { temporaryTile.IsCollidable = true; } else { temporaryTile.IsCollidable = false; } rawData = xmlReader.ReadElementContentAsString("Color", ""); organizedData = rawData.Split(' '); xData = organizedData[0].Split(':'); yData = organizedData[1].Split(':'); zData = organizedData[2].Split(':'); zData[1] = zData[1].TrimEnd(); zData[1] = zData[1].Replace('}', ' '); temporaryTile.Color = new Color((float)Convert.ToDouble(xData[1]), (float)Convert.ToDouble(yData[1]), (float)Convert.ToDouble(zData[1])); rawData = xmlReader.ReadElementContentAsString("Rotation", ""); organizedData = rawData.Split(' '); xData = organizedData[0].Split(':'); yData = organizedData[1].Split(':'); zData = organizedData[2].Split(':'); zData[1] = zData[1].TrimEnd(); zData[1] = zData[1].Replace('}', ' '); temporaryTile.Rotation = new Vector3((float)Convert.ToDouble(xData[1]), (float)Convert.ToDouble(yData[1]), (float)Convert.ToDouble(zData[1])); rawData = xmlReader.ReadElementContentAsString("Scale", ""); organizedData = rawData.Split(' '); xData = organizedData[0].Split(':'); yData = organizedData[1].Split(':'); zData = organizedData[2].Split(':'); zData[1] = zData[1].TrimEnd(); zData[1] = zData[1].Replace('}', ' '); temporaryTile.Scale = new Vector3((float)Convert.ToDouble(xData[1]), (float)Convert.ToDouble(yData[1]), (float)Convert.ToDouble(zData[1])); switch (xmlReader.ReadElementContentAsString("SpriteEffects", "")) { case "FlipVertically": temporaryTile.SpriteEffects = SpriteEffects.FlipVertically; break; case "FlipHorizontally": temporaryTile.SpriteEffects = SpriteEffects.FlipHorizontally; break; case "None": temporaryTile.SpriteEffects = SpriteEffects.None; break; default: break; } temporaryTile.LayerDepth = xmlReader.ReadElementContentAsFloat("LayerDepth", ""); xmlReader.ReadEndElement(); Add(temporaryTile); } xmlReader.Close(); } }
public override void Generate(Vector3 aCoordinate) { Tile newTile = new Tile(aCoordinate); }
public void Draw(Tile aTile) { GameFiles.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; GameFiles.GraphicsDevice.BlendState = BlendState.Opaque; GameFiles.GraphicsDevice.DepthStencilState = DepthStencilState.Default; foreach (EffectPass pass in mEffect.CurrentTechnique.Passes) { mEffect.CurrentTechnique = mEffect.Techniques["Standard"]; mEffect.Parameters["xWorldViewProjectionMatrix"].SetValue(aTile.ScaleMatrix * aTile.RotationMatrix * aTile.WorldMatrix * GameFiles.ViewMatrix * GameFiles.ProjectionMatrix); mEffect.Parameters["xColorMap"].SetValue(aTile.Graphic); pass.Apply(); GameFiles.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, mObjModel, 0, mObjModel.Length / 3); } }
public MainEditorWindow() { commandQueue = new Stack<ICommand>(); redoCommandQueue = new Stack<ICommand>(); hazards = new BindingList<Hazard>(); // Gets the current directory string dir = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())); // Set the tile array to the proper grid size tiles = new Tile[gridWidth, gridHeight]; // Add all textures available at the moment imageMap.Add("empty", Image.FromFile(dir + "/empty.png")); imageMap.Add("grass", Image.FromFile(dir + "/grass.png")); imageMap.Add("ground", Image.FromFile(dir + "/ground.png")); imageMap.Add("background", Image.FromFile(dir + "/background_sky.png")); // Initial tile to be drawn is "Empty" currentImage = imageMap["empty"]; // Initialize tile array for (int i = 0; i < tiles.GetLength(0); i++) for (int j = 0; j < tiles.GetLength(1); j++) { tiles[i, j] = new Tile(Color.White); tiles[i, j].Image = imageMap["empty"]; } InitializeComponent(); this.javaTestItem.Click += new EventHandler(this.testJava_Click); this.KeyPreview = true; this.KeyDown += this.form_KeyDown; this.KeyUp += this.form_KeyUp; /* All not auto-generated code for UI here */ this.comboBox1.SelectedIndex = 0; this.comboBox2.SelectedIndex = 0; this.Text = "LevelEditor"; this.exitItem.Click += new System.EventHandler(exitItem_Click); this.listBox1.DataSource = hazards; typeof(System.Windows.Forms.Panel).InvokeMember("DoubleBuffered", System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, gridPanel, new object[] { true }); // Set initial values (Sort of magic numbers-ish right now) maxZoom = 40; minZoom = 5; initDrawOffsetX = 600; initDrawOffsetY = 80; initScrollOffsetX = 50; initScrollOffsetY = 50; origXMargin = 10 + initDrawOffsetX; origYMargin = 10 + initDrawOffsetY; }
private void ResizeGrid() { Tile[,] tempTileArr = new Tile[gridWidth, gridHeight]; Rectangle[,] tempRectArr = new Rectangle[gridWidth, gridHeight]; for (int i = 0; i < gridWidth; i++) { for (int j = 0; j < gridHeight; j++) { tempTileArr[i, j] = new Tile(Color.White); tempTileArr[i, j].Image = imageMap["empty"]; } } for (int i = 0; i < Math.Min(tiles.GetLength(0), tempTileArr.GetLength(0)); i++) for (int j = 0; j < Math.Min(tiles.GetLength(1), tempTileArr.GetLength(1)); j++) { tempTileArr[i, j].Image = tiles[i, j].Image; } tiles = tempTileArr; //gridPanel.Size = new Size(gridWidth * (rectSize + 5), gridHeight * (rectSize + 5)); this.gridPanel.AutoScrollMargin = new System.Drawing.Size(origXMargin, origYMargin); this.gridPanel.AutoScrollMinSize = new System.Drawing.Size(rectSize * (tiles.GetLength(0) + initScrollOffsetX), (rectSize / 2) * (tiles.GetLength(1) + initScrollOffsetY)); paintOffsetX = 0F; paintOffsetY = 0F; // 18000 is based of 30x30 iniDrawOffsetX was 600 and 90x30 was 200 so that gave 18000 / 30 and 90 initDrawOffsetX = 18000 / gridWidth; }
private void RefreshGrid() { for (int i = 0; i < tiles.GetLength(0); i++) for (int j = 0; j < tiles.GetLength(1); j++) { tiles[i, j] = new Tile(Color.White); tiles[i, j].Image = imageMap["empty"]; } }
private void fillGrid_Click(object sender, EventArgs e) { // Need temporary but identical array to send Tile[,] tempTiles = new Tile[gridWidth, gridHeight]; for (int i = 0; i < tiles.GetLength(0); i++) for (int j = 0; j < tiles.GetLength(1); j++) { tempTiles[i, j] = new Tile(Color.White); tempTiles[i, j].Image = tiles[i, j].Image; } FillGridCommand fgc = new FillGridCommand(this, tempTiles, currentImage); ExecuteAndQueueCommand(fgc); InvalidateAndUpdate(gridPanel); }
public void Clone() { try { Tile clonedTile = new Tile(); clonedTile.WorldPosition = this.WorldPosition; clonedTile.FilePathToGraphic = this.FilePathToGraphic; clonedTile.FilePathToModel = this.FilePathToModel; clonedTile.mObjModel = new ObjModel(this.FilePathToModel); theTileManager.Add(clonedTile); } catch { Console.WriteLine("{0} has an incorrect filepath of {1}. {2}.", "clonedTile", this.FilePathToModel, this.ToString()); } }
public void Draw(Tile aTile) { GameFiles.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; GameFiles.GraphicsDevice.BlendState = BlendState.Opaque; GameFiles.GraphicsDevice.DepthStencilState = DepthStencilState.Default; Matrix defaultMatrix = Matrix.Identity * Matrix.CreateScale(m_Scale) * Matrix.CreateRotationX(m_Rotation.X) * Matrix.CreateRotationY(m_Rotation.Y) * Matrix.CreateRotationZ(m_Rotation.Z) * Matrix.CreateTranslation(m_Translation); foreach (EffectPass pass in m_Effect.CurrentTechnique.Passes) { m_Effect.CurrentTechnique = m_Effect.Techniques["Standard"]; m_Effect.Parameters["xWorldViewProjectionMatrix"].SetValue(defaultMatrix * aTile.ScaleMatrix * aTile.RotationMatrix * aTile.WorldMatrix * GameFiles.ViewMatrix * GameFiles.ProjectionMatrix); m_Effect.Parameters["xColorMap"].SetValue(aTile.Graphic); //TODO: Update generic shader to take in Normals pass.Apply(); GameFiles.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, m_FbxModel, 0, m_FbxModel.Length / 3); } }